From e7710d94bf7ff1603b554d80d0f66c2ea953a0e5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 4 Apr 2014 22:32:34 -0400 Subject: [PATCH] Extra language. --- libethereum/Instruction.cpp | 43 ++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/libethereum/Instruction.cpp b/libethereum/Instruction.cpp index 109ed7ccf..f2971f3a3 100644 --- a/libethereum/Instruction.cpp +++ b/libethereum/Instruction.cpp @@ -348,11 +348,12 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes bool exec = false; int outs = 1; + bool seq = false; while (d != e) { // skip to next token - for (; d != e && !isalnum(*d) && *d != '(' && *d != ')' && *d != '_' && *d != '"' && *d != '@' && *d != '[' && !c_allowed.count(*d) && *d != ';'; ++d) {} + for (; d != e && !isalnum(*d) && *d != '(' && *d != ')' && *d != '{' && *d != '}' && *d != '_' && *d != '"' && *d != '@' && *d != '[' && !c_allowed.count(*d) && *d != ';'; ++d) {} if (d == e) break; @@ -365,6 +366,33 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes exec = true; ++d; break; + case '{': + ++d; + while (d != e) + { + bytes codes; + vector locs; + outs = 0; + int o; + if ((o = compileLispFragment(d, e, _quiet, codes, locs, _vars)) > -1) + { + for (int i = 0; i < outs; ++i) + o_code.push_back((byte)Instruction::POP); // pop additional items off stack for the previous item (final item's returns get left on). + outs = o; + appendCode(o_code, o_locs, codes, locs); + } + else + break; + } + seq = true; + break; + case '}': + if (seq) + { + ++d; + return outs; + } + return -1; case ')': if (exec) { @@ -374,6 +402,7 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes else // unexpected - return false as we don't know what to do with it. return -1; + case '@': { if (exec) @@ -639,20 +668,14 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes codes.push_back(pair>()); totalArgs += o; } - if (totalArgs < 2) + if (totalArgs < 7) { - cwarn << "Expected at least 2 arguments to CALL; got" << totalArgs << "."; + cwarn << "Expected at least 7 arguments to CALL; got" << totalArgs << "."; break; } - unsigned datan = (unsigned)codes.size() - 3; - unsigned i = 0; - for (auto it = codes.rbegin(); it != codes.rend(); ++it, ++i) - { + for (auto it = codes.rbegin(); it != codes.rend(); ++it) appendCode(o_code, o_locs, it->first, it->second); - if (i == datan) - pushLocation(o_code, datan); - } o_code.push_back((byte)Instruction::CALL); outs = 0; }