diff options
-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){} |