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 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'functions.cpp') 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) -- cgit v1.2.3-70-g09d2