From 0711be4f145b3d74bc90658dd71d186716e6a72c Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 9 Sep 2015 22:06:32 +0200 Subject: Add arrays to Postrun --- runtime.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'runtime.cpp') diff --git a/runtime.cpp b/runtime.cpp index 98ae245..19108cd 100644 --- a/runtime.cpp +++ b/runtime.cpp @@ -1,10 +1,12 @@ #include +#include #include #include #include #include #include #include +#include #include "runtime.h" @@ -15,23 +17,67 @@ 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){} -Stackitem::Stackitem(int _i):isstr(false),intval(_i){} -Stackitem::Stackitem(const string &_s):isstr(true),strval(_s),intval(0){} -Stackitem::Stackitem(const Stackitem&)=default; -Stackitem::Stackitem(Stackitem &&other):isstr(other.isstr),strval(move(other.strval)),intval(other.intval){ - other.isstr=false; +Stackitem::Stackitem(void){} + +Stackitem::Stackitem(int _i):type(SIT_INT),intval(_i){} +Stackitem::Stackitem(const string &_s):type(SIT_STR),strval(_s){} +Stackitem::Stackitem(const vector &_a):type(SIT_ARR),arrval(_a){} + +Stackitem::Stackitem(const Stackitem &other)=default; +Stackitem::Stackitem(Stackitem &&other):type(other.type),strval(move(other.strval)),intval(other.intval),arrval(move(other.arrval)){ + other.type=SIT_INT; +} + +Stackitem& Stackitem::operator=(const Stackitem &other){ + type=other.type; + strval=other.strval; + intval=other.intval; + arrval=other.arrval; + return *this; } -Stackitem& Stackitem::operator=(const Stackitem&)=default; Stackitem& Stackitem::operator=(Stackitem &&other){ - isstr=other.isstr; + type=other.type; strval=move(other.strval); intval=other.intval; - other.isstr=false; + arrval=move(other.arrval); + other.type=SIT_INT; return *this; } -Stackitem::operator bool(void) const{return (isstr&&strval.size())||(!isstr&&intval);} -bool Stackitem::operator==(const Stackitem &other) const{return isstr==other.isstr&&(isstr?strval==other.strval:intval==other.intval);} + +Stackitem::operator bool(void) const{ + return (type==SIT_INT&&intval)|| + (type==SIT_STR&&strval.size())|| + (type==SIT_ARR&&arrval.size()); +} + +bool Stackitem::operator==(const Stackitem &other) const{ + if(type!=other.type)return false; + if(type==SIT_INT)return intval==other.intval; + if(type==SIT_STR)return strval==other.strval; + assert(type==SIT_ARR); + auto sz=arrval.size(); + if(sz!=other.arrval.size())return false; + for(int i=0;i&,unordered_map&)>> builtins; -- cgit v1.2.3-70-g09d2