From 6d97a56af17d65425d72c5df973b2fa4fac74a7a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 31 Oct 2016 23:15:57 +0000 Subject: [PATCH 1/3] LLL: support multiple strings in LIT --- liblll/CodeFragment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 0f8f26061..f143ca43c 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -287,10 +287,10 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) if (pos.m_asm.deposit() != 1) error(); } - else if (ii == 2 && !i.tag() && i.which() == sp::utree_type::string_type) + else if (ii >= 2 && !i.tag() && i.which() == sp::utree_type::string_type) { auto sr = i.get, sp::utree_type::string_type>>(); - data = bytes((byte const*)sr.begin(), (byte const*)sr.end()); + data.insert(data.end(), (byte const *)sr.begin(), (byte const*)sr.end()); } else if (ii >= 2 && !i.tag() && i.which() == sp::utree_type::any_type) { From 75b1ae89102d1f917b59b3fa67046181cd74aa7e Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 31 Oct 2016 23:17:09 +0000 Subject: [PATCH 2/3] LLL: only support variable length bigendian numbers in LIT --- liblll/CodeFragment.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index f143ca43c..1bf587cec 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -297,21 +297,10 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) bigint bi = *i.get(); if (bi < 0) error(); - else if (bi > bigint(u256(0) - 1)) - { - if (ii == 2 && _t.size() == 3) - { - // One big int - allow it as hex. - data.resize(bytesRequired(bi)); - toBigEndian(bi, data); - } - else - error(); - } else { - data.resize(data.size() + 32); - *(h256*)(&data.back() - 31) = (u256)bi; + bytes tmp = toCompactBigEndian(bi); + data.insert(data.end(), tmp.begin(), tmp.end()); } } else if (ii) From eee10f1af27cb3c9e94b9e4bcb5d78f02cf4192d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 8 Nov 2016 17:16:45 +0000 Subject: [PATCH 3/3] LLL: simplify the LIT parsing code --- liblll/CodeFragment.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 1bf587cec..9257e7390 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -281,18 +281,27 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) bytes data; for (auto const& i: _t) { - if (ii == 1) + if (ii == 0) + { + ii++; + continue; + } + else if (ii == 1) { pos = CodeFragment(i, _s); if (pos.m_asm.deposit() != 1) error(); } - else if (ii >= 2 && !i.tag() && i.which() == sp::utree_type::string_type) + else if (i.tag() != 0) + { + error(); + } + else if (i.which() == sp::utree_type::string_type) { auto sr = i.get, sp::utree_type::string_type>>(); data.insert(data.end(), (byte const *)sr.begin(), (byte const*)sr.end()); } - else if (ii >= 2 && !i.tag() && i.which() == sp::utree_type::any_type) + else if (i.which() == sp::utree_type::any_type) { bigint bi = *i.get(); if (bi < 0) @@ -303,9 +312,12 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) data.insert(data.end(), tmp.begin(), tmp.end()); } } - else if (ii) + else + { error(); - ++ii; + } + + ii++; } m_asm.append((u256)data.size()); m_asm.append(Instruction::DUP1);