From 79c4014fd2852d12b2489184f53da40247452b8a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 9 Sep 2015 08:22:40 +0200 Subject: More bitwise operators! --- functions.cpp | 35 +++++++++++++++++++++++++---------- runtime.cpp | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/functions.cpp b/functions.cpp index 8bd4053..7a6ce36 100644 --- a/functions.cpp +++ b/functions.cpp @@ -69,16 +69,29 @@ unordered_map&,unordered_map &S,unordered_map &variables){ + BUILTIN_GUARD_STACKSIZE("&",2) + Stackitem b=move(S.back()); S.pop_back(); + Stackitem a=move(S.back()); S.pop_back(); + if(a.isstr||b.isstr)throw string("Builtin '&' cannot accept a string argument"); + S.emplace_back(a.intval&b.intval); + }}, + {"|",[](vector &S,unordered_map &variables){ + BUILTIN_GUARD_STACKSIZE("|",2) + Stackitem b=move(S.back()); S.pop_back(); + Stackitem a=move(S.back()); S.pop_back(); + if(a.isstr||b.isstr)throw string("Builtin '|' cannot accept a string argument"); + S.emplace_back(a.intval|b.intval); + }}, + {"~",[](vector &S,unordered_map &variables){ + BUILTIN_GUARD_STACKSIZE("~",1) + Stackitem &back=S.back(); + if(back.isstr)throw string("Builtin '~' cannot accept a string argument"); + else back.intval=~back.intval; + }}, {"^",[](vector &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("^",2) Stackitem b=move(S.back()); S.pop_back(); @@ -88,9 +101,11 @@ unordered_map&,unordered_map &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("!",1) - Stackitem v=move(S.back()); S.pop_back(); - if(v.isstr)S.emplace_back(!v.strval.size()); - else S.emplace_back(!v.intval); + Stackitem &back=S.back(); + if(back.isstr){ + back.isstr=false; + back.intval=!back.strval.size(); + } else back.intval=!back.intval; }}, {"=",[](vector &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("=",2) diff --git a/runtime.cpp b/runtime.cpp index 03c87b4..98ae245 100644 --- a/runtime.cpp +++ b/runtime.cpp @@ -12,7 +12,7 @@ using namespace std; inline bool isword(char c){return isalpha(c)||c=='_'||c=='@'||c=='$';} inline bool isextword(char c){return isword(c)||isdigit(c);} -inline bool isoperator(char c){return (bool)strchr("+-*/=><{}",c);} Stackitem::Stackitem(void):isstr(false),intval(0){} -- cgit v1.2.3-70-g09d2