serpent 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 811c4565b51dd15e5eeb48a256059514f0c0b533
4
- data.tar.gz: c1beae6806e7f1b2b814e25faa7ea844d63db767
3
+ metadata.gz: a7e97b6b271ee3c9ca4451ace9e8bb1115c9d716
4
+ data.tar.gz: 8de2a46ee639fd1476d86b8d4beaaf96bc25edc9
5
5
  SHA512:
6
- metadata.gz: b03d4526f59ee065ea878e6e6e7abfb2d68c90a9e3bdf34e887683247e4d272104375da2b2173749f73aedbcee063e6a650358fd7740237d8dca8d459607d6cd
7
- data.tar.gz: c1a76b77781c5ec3fdfc5d978dcc71b47895387250310c80f885ba8d9162fc737899ca5d9eafef82b04c37bf8a2ee44c96e0b3d7c83634fe079ebcfdc929a9d4
6
+ metadata.gz: 5724e2ba8c64c10c43dda924f0927108855633083e09a26097ee89c0c134eaa413670f5efbd5eb6d614d354ca322884e8d7f3716acc85390150534c70cd343c9
7
+ data.tar.gz: 93f6688b63c71d22a8717a0c6bd10a24dddad0a61dc24c22a1180c1eeac730590872a8165548c17e86775b74df54d13f64d37995508c22170227dc21bc412408
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- serpent (0.2.0)
4
+ serpent (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://ruby.taobao.org/
@@ -2,6 +2,7 @@
2
2
  #include "rice/Array.hpp"
3
3
  using namespace Rice;
4
4
 
5
+ #include "libserpent/util.h"
5
6
  #include "libserpent/parser.h"
6
7
  #include "libserpent/funcs.h"
7
8
 
@@ -23,6 +24,28 @@ Array serialize_node(Node n) {
23
24
  return a;
24
25
  }
25
26
 
27
+ Metadata deserialize_metadata(Array o) {
28
+ return Metadata(from_ruby<std::string>(o[0]),
29
+ from_ruby<int>(o[1]),
30
+ from_ruby<int>(o[2]));
31
+ }
32
+
33
+ Node deserialize_node(Array o) {
34
+ Node n;
35
+
36
+ n.type = from_ruby<int>(o[0]) ? ASTNODE : TOKEN;
37
+ n.val = from_ruby<std::string>(o[1]);
38
+ n.metadata = deserialize_metadata(from_ruby<Array>(o[2]));
39
+
40
+ std::vector<Node> args;
41
+ for(unsigned i = 3; i < o.size(); i++) {
42
+ args.push_back(deserialize_node(from_ruby<Array>(o[i])));
43
+ }
44
+ n.args = args;
45
+
46
+ return n;
47
+ }
48
+
26
49
  /*
27
50
  * Serpent functions
28
51
  */
@@ -43,6 +66,11 @@ Array serpent_parse_lll(Object self, std::string code) {
43
66
  return serialize_node(parseLLL(code));
44
67
  }
45
68
 
69
+ std::string serpent_compile_lll(Object self, Array o) {
70
+ Node n = deserialize_node(o);
71
+ return compileLLL(n);
72
+ }
73
+
46
74
  std::string serpent_mk_signature(Object self, std::string input) {
47
75
  return mkSignature(input);
48
76
  }
@@ -67,6 +95,7 @@ void Init_serpent_ffi() {
67
95
  .define_module_function("compile", &serpent_compile)
68
96
  .define_module_function("compile_to_lll", &serpent_compile_to_lll)
69
97
  .define_module_function("parse_lll", &serpent_parse_lll)
98
+ .define_module_function("compile_lll", &serpent_compile_lll)
70
99
  .define_module_function("mk_signature", &serpent_mk_signature)
71
100
  .define_module_function("mk_full_signature", &serpent_mk_full_signature)
72
101
  .define_module_function("mk_contract_info", &serpent_mk_contract_info)
@@ -9,30 +9,15 @@ require 'serpent/caller'
9
9
 
10
10
  module Serpent
11
11
 
12
- extend self
13
-
14
- def compile(code, **kwargs)
15
- Caller.new.compile code, **kwargs
16
- end
17
-
18
- def compile_to_lll(code, **kwargs)
19
- Caller.new.compile_to_lll code, **kwargs
20
- end
21
-
22
- def get_prefix(signature)
23
- FFI.get_prefix signature
24
- end
25
-
26
- def mk_signature(s)
27
- JSON.parse FFI.mk_signature(s)
28
- end
29
-
30
- def mk_full_signature(s)
31
- JSON.parse FFI.mk_full_signature(s)
32
- end
33
-
34
- def mk_contract_info(s)
35
- JSON.parse FFI.mk_contract_info(s)
12
+ class <<self
13
+ def method_missing(name, *args)
14
+ caller = Caller.new
15
+ if caller.respond_to?(name)
16
+ caller.send name, *args
17
+ else
18
+ super
19
+ end
20
+ end
36
21
  end
37
22
 
38
23
  end
@@ -3,6 +3,8 @@
3
3
  module Serpent
4
4
  class Caller
5
5
 
6
+ N = 2**32
7
+
6
8
  def compile(code, **kwargs)
7
9
  FFI.compile pre_transform(code, kwargs)
8
10
  end
@@ -11,13 +13,29 @@ module Serpent
11
13
  Node.build FFI.compile_to_lll(pre_transform(code, kwargs))
12
14
  end
13
15
 
14
- def parse_to_lll(code)
15
- FFI.parse_lll(code)
16
+ def compile_lll(code)
17
+ FFI.compile_lll ast(code)
18
+ end
19
+
20
+ def get_prefix(signature)
21
+ FFI.get_prefix(signature) % N
22
+ end
23
+
24
+ def mk_signature(code, **kwargs)
25
+ JSON.parse FFI.mk_signature(pre_transform(code, kwargs))
26
+ end
27
+
28
+ def mk_full_signature(code, **kwargs)
29
+ JSON.parse FFI.mk_full_signature(pre_transform(code, kwargs))
30
+ end
31
+
32
+ def mk_contract_info(code, **kwargs)
33
+ JSON.parse FFI.mk_contract_info(pre_transform(code, kwargs))
16
34
  end
17
35
 
18
36
  private
19
37
 
20
- def take(x)
38
+ def ast(x)
21
39
  x.instance_of?(String) ? FFI.parse_lll(x) : x.out
22
40
  end
23
41
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : ascii-8bit -*-
2
2
  module Serpent
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
@@ -11,6 +11,19 @@ def main(a,b):
11
11
  return(a ^ b)
12
12
  EOF
13
13
 
14
+ LLL_CODE = <<EOF
15
+ (with 'x 10
16
+ (with 'y 20
17
+ (with 'z 30
18
+ (seq
19
+ (set 'a (add (mul (get 'y) (get 'z)) (get 'x)))
20
+ (return (ref 'a) 32)
21
+ )
22
+ )
23
+ )
24
+ )
25
+ EOF
26
+
14
27
  def test_compile
15
28
  assert_equal decode_hex('604a80600b6000396055567c0100000000000000000000000000000000000000000000000000000000600035046397d857aa8114156048576004356040526024356060526060516040510a60805260206080f35b505b6000f3'), Serpent.compile(CODE, foo: 1)
16
29
  end
@@ -19,6 +32,10 @@ EOF
19
32
  assert_match /^\(return 0 \n/, Serpent.compile_to_lll(CODE).to_s
20
33
  end
21
34
 
35
+ def test_compile_lll
36
+ assert_equal "`\n`\x14`\x1e\x82\x81\x83\x02\x01` R` ` \xf3PPP", Serpent.compile_lll(LLL_CODE)
37
+ end
38
+
22
39
  def test_parse_lll
23
40
  assert_equal [0, 'def', ['main', 0, 0]], Serpent::FFI.parse_lll(CODE)
24
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serpent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Xie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.5.1
126
+ rubygems_version: 2.4.5.1
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Ruby binding to Ethereum Serpent compiler.