From bcefce7d8c7c4979787d89dc198e7bfc1a4949c8 Mon Sep 17 00:00:00 2001 From: Vitalik Buterin Date: Mon, 30 Jun 2014 18:58:04 -0400 Subject: [PATCH] Changed array_lit mechanics --- libserpent/rewriter.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libserpent/rewriter.cpp b/libserpent/rewriter.cpp index cf40c6604..0e7e28c2b 100644 --- a/libserpent/rewriter.cpp +++ b/libserpent/rewriter.cpp @@ -339,6 +339,35 @@ Node subst(Node pattern, } } +// array_lit transform + +Node array_lit_transform(Node node) { + std::vector o1; + o1.push_back(token(intToDecimal(node.args.size() * 32), node.metadata)); + std::vector o2; + std::string symb = "_temp"+mkUniqueToken()+"_0"; + o2.push_back(token(symb, node.metadata)); + o2.push_back(astnode("alloc", o1, node.metadata)); + std::vector o3; + o3.push_back(astnode("set", o2, node.metadata)); + for (int i = 0; i < node.args.size(); i++) { + // (mstore (add (get symb) i*32) v) + std::vector o5; + o5.push_back(token(symb, node.metadata)); + std::vector o6; + o6.push_back(astnode("get", o5, node.metadata)); + o6.push_back(token(intToDecimal(i * 32), node.metadata)); + std::vector o7; + o7.push_back(astnode("add", o6)); + o7.push_back(node.args[i]); + o3.push_back(astnode("mstore", o7, node.metadata)); + } + std::vector o8; + o8.push_back(token(symb, node.metadata)); + o3.push_back(astnode("get", o8)); + return astnode("seq", o3, node.metadata); +} + // Recursively applies rewrite rules Node apply_rules(Node node) { // If the rewrite rules have not yet been parsed, parse them @@ -371,6 +400,9 @@ Node apply_rules(Node node) { node = subst(pattern2, mr.map, prefix, node.metadata); } } + // Array_lit special instruction + if (node.val == "array_lit") + node = array_lit_transform(node); if (node.type == ASTNODE && node.val != "ref" && node.val != "get") { unsigned i = 0; if (node.val == "set") i = 1;