diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-09-09 08:22:40 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-09-09 08:22:40 +0200 |
commit | 79c4014fd2852d12b2489184f53da40247452b8a (patch) | |
tree | bb64aa3e6263723ef0ca912584ee6e46acfd291d | |
parent | ed0409a2a7450905bdc70015ffe537171684dddf (diff) |
More bitwise operators!
-rw-r--r-- | functions.cpp | 35 | ||||
-rw-r--r-- | 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<string,function<void(vector<Stackitem>&,unordered_map<string,Stack 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){ - cerr<<"modding "; - if(a.isstr)cerr<<'"'<<a.strval<<'"'; else cerr<<a.intval; - cerr<<" and "; - if(b.isstr)cerr<<'"'<<b.strval<<'"'; else cerr<<b.intval; - cerr<<endl; - } if(a.isstr||b.isstr)throw string("Builtin '%' cannot accept a string argument"); S.emplace_back(a.intval%b.intval); }}, + {"&",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &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<Stackitem> &S,unordered_map<string,Stackitem> &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<Stackitem> &S,unordered_map<string,Stackitem> &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<Stackitem> &S,unordered_map<string,Stackitem> &variables){ BUILTIN_GUARD_STACKSIZE("^",2) Stackitem b=move(S.back()); S.pop_back(); @@ -88,9 +101,11 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack }}, {"!",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &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<Stackitem> &S,unordered_map<string,Stackitem> &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);} +inline bool isoperator(char c){return (bool)strchr("+-*/%&|~^!=><{}",c);} Stackitem::Stackitem(void):isstr(false),intval(0){} |