Browse Source

Extra language.

cl-refactor
Gav Wood 11 years ago
parent
commit
e7710d94bf
  1. 43
      libethereum/Instruction.cpp

43
libethereum/Instruction.cpp

@ -348,11 +348,12 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
bool exec = false; bool exec = false;
int outs = 1; int outs = 1;
bool seq = false;
while (d != e) while (d != e)
{ {
// skip to next token // 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) if (d == e)
break; break;
@ -365,6 +366,33 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
exec = true; exec = true;
++d; ++d;
break; break;
case '{':
++d;
while (d != e)
{
bytes codes;
vector<unsigned> 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 ')': case ')':
if (exec) if (exec)
{ {
@ -374,6 +402,7 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
else else
// unexpected - return false as we don't know what to do with it. // unexpected - return false as we don't know what to do with it.
return -1; return -1;
case '@': case '@':
{ {
if (exec) if (exec)
@ -639,20 +668,14 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
codes.push_back(pair<bytes, vector<unsigned>>()); codes.push_back(pair<bytes, vector<unsigned>>());
totalArgs += o; 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; break;
} }
unsigned datan = (unsigned)codes.size() - 3; for (auto it = codes.rbegin(); it != codes.rend(); ++it)
unsigned i = 0;
for (auto it = codes.rbegin(); it != codes.rend(); ++it, ++i)
{
appendCode(o_code, o_locs, it->first, it->second); appendCode(o_code, o_locs, it->first, it->second);
if (i == datan)
pushLocation(o_code, datan);
}
o_code.push_back((byte)Instruction::CALL); o_code.push_back((byte)Instruction::CALL);
outs = 0; outs = 0;
} }

Loading…
Cancel
Save