aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-05-30 20:55:07 +0800
committerGav Wood <i@gavwood.com>2014-05-30 20:55:07 +0800
commitb379ce906530797f0f58569653b648ab64f2968d (patch)
tree326b6e471cf081ea28808fc74777bfbcb1ed379e
parent78c0baa026d69a6b03d0f3d9288c4da4e03f4b96 (diff)
downloaddexon-solidity-b379ce906530797f0f58569653b648ab64f2968d.tar.gz
dexon-solidity-b379ce906530797f0f58569653b648ab64f2968d.tar.zst
dexon-solidity-b379ce906530797f0f58569653b648ab64f2968d.zip
Variadic macros work.
-rw-r--r--CodeFragment.cpp17
-rw-r--r--CompilerState.cpp2
-rw-r--r--CompilerState.h2
3 files changed, 12 insertions, 9 deletions
diff --git a/CodeFragment.cpp b/CodeFragment.cpp
index f30fba95..448d3ef2 100644
--- a/CodeFragment.cpp
+++ b/CodeFragment.cpp
@@ -172,6 +172,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
unsigned ii = 0;
if (_t.size() != 3 && _t.size() != 4)
error<IncorrectParameterCount>();
+ vector<string> args;
for (auto const& i: _t)
{
if (ii == 1)
@@ -198,16 +199,18 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
if (j.tag() || j.which() != sp::utree_type::symbol_type)
error<InvalidMacroArgs>();
auto sr = j.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>();
- _s.macros[n].args.push_back(string(sr.begin(), sr.end()));
+ args.push_back(string(sr.begin(), sr.end()));
}
else if (ii == 3)
{
- _s.macros[n].code = i;
- _s.macros[n].env = _s.outers;
+ auto k = make_pair(n, args.size());
+ _s.macros[k].code = i;
+ _s.macros[k].env = _s.outers;
+ _s.macros[k].args = args;
for (auto const& i: _s.args)
- _s.macros[n].env[i.first] = i.second;
+ _s.macros[k].env[i.first] = i.second;
for (auto const& i: _s.defs)
- _s.macros[n].env[i.first] = i.second;
+ _s.macros[k].env[i.first] = i.second;
}
++ii;
}
@@ -292,9 +295,9 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
auto requireMaxSize = [&](unsigned s) { if (code.size() > s) error<IncorrectParameterCount>(); };
auto requireDeposit = [&](unsigned i, int s) { if (code[i].m_asm.deposit() != s) error<InvalidDeposit>(); };
- if (_s.macros.count(s) && _s.macros.at(s).args.size() == code.size())
+ if (_s.macros.count(make_pair(s, code.size())))
{
- Macro const& m = _s.macros.at(s);
+ Macro const& m = _s.macros.at(make_pair(s, code.size()));
CompilerState cs = _s;
for (auto const& i: m.env)
cs.outers[i.first] = i.second;
diff --git a/CompilerState.cpp b/CompilerState.cpp
index 571b9de3..e5d0b2a0 100644
--- a/CompilerState.cpp
+++ b/CompilerState.cpp
@@ -42,8 +42,8 @@ void CompilerState::populateStandard()
static const string s = "{"
"(def 'gav 0x8a40bfaa73256b60764c1bf40675a99083efb075)"
"(def 'send (to value) (call (- (gas) 21) to value 0 0 0 0))"
-#if 0
"(def 'send (gaslimit to value) (call gaslimit to value 0 0 0 0))"
+#if 1
"(def 'alloc (len) (asm msize 0 1 len msize add sub mstore8))"
"(def 'msg (gaslimit to value data datasize outsize) { [32]:outsize [0]:(alloc @32) (call gaslimit to value data datasize @0 @32) @0 })"
"(def 'msg (gaslimit to value data datasize) { (call gaslimit to value data datasize 0 32) @0 })"
diff --git a/CompilerState.h b/CompilerState.h
index 7f3cef82..b7581e0b 100644
--- a/CompilerState.h
+++ b/CompilerState.h
@@ -43,7 +43,7 @@ struct CompilerState
std::map<std::string, CodeFragment> defs;
std::map<std::string, CodeFragment> args;
std::map<std::string, CodeFragment> outers;
- std::map<std::string, Macro> macros;
+ std::map<std::pair<std::string, unsigned>, Macro> macros;
std::vector<boost::spirit::utree> treesToKill;
};