From 3e22583f8596fd8bb2b1e8f651c38f5a898a6155 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 10 Sep 2015 19:56:51 +0200 Subject: arrpushf, arrpopf, error --- functions.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'functions.cpp') diff --git a/functions.cpp b/functions.cpp index bd718f8..792e2cc 100644 --- a/functions.cpp +++ b/functions.cpp @@ -436,12 +436,28 @@ unordered_map&,unordered_map &S,unordered_map &variables){ + BUILTIN_GUARD_STACKSIZE("arrpushf",2) + Stackitem &arrref=S[S.size()-2]; + if(arrref.type!=SIT_ARR) + throw string("Top of stack is not an array in builtin 'arrpushf'"); + arrref.arrval.insert(arrref.arrval.begin(),move(S.back())); + S.pop_back(); + }}, + //leaves the array on the stack, obviously {"arrpop",[](vector &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("arrpop",1) if(S.back().type!=SIT_ARR) throw string("Top of stack is not an array in builtin 'arrpop'"); S.back().arrval.pop_back(); }}, + //leaves the array on the stack, obviously + {"arrpopf",[](vector &S,unordered_map &variables){ + BUILTIN_GUARD_STACKSIZE("arrpopf",1) + if(S.back().type!=SIT_ARR) + throw string("Top of stack is not an array in builtin 'arrpopf'"); + S.back().arrval.erase(S.back().arrval.begin()); + }}, {"rand",[](vector &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("rand",0) assert(RAND_MAX==0x7fffffff); @@ -474,6 +490,10 @@ unordered_map&,unordered_map &S,unordered_map &variables){ + BUILTIN_GUARD_STACKSIZE("error",0) + exit(1); //STUB IMPLEMENTATION + }}, {"exit",[](vector &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("exit",0) exit(0); -- cgit v1.2.3-70-g09d2