michelson 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed3b5fbe9328e38ec213aa5d36c106711cdd5e1e
4
- data.tar.gz: 0e5d7cd932220b76b7951a1db682c266cd3242c3
3
+ metadata.gz: c38fcb8b1914f1dd67e97fcbefa894c09988d19b
4
+ data.tar.gz: aaefda11aab976e8683faee197f783c53c7da8f5
5
5
  SHA512:
6
- metadata.gz: 22d4c310be5fd21d7caa94fa87ab9f3b50c7a4c1a208c2f35682173d2894be1fca582e9c6eddab10ea81b5f6ffbf46c5e52c96696976b8b8cc7d86e7ef148601
7
- data.tar.gz: a0e72f64c2dbd6a8e47cf9c9a009204c8e967411834c9119462113f88e3d335685b444f6371e9a72b9cb5faa080a7c05c98aabd1757c243158e71b2e1c1356d6
6
+ metadata.gz: c1f77fc464cf095c83896265a4071566a50e3fd3ec0b60535d965ed0d62c4fb3e16aa84426e1db505cd275f44ee8fc209f0252383960da503edf184403b5a074
7
+ data.tar.gz: a979354201a30ad6e5c2bcf46675883d39e9c3e0457a1929a5a875aa3513fd1e79111734adec5a108342b09c68f13dc9ea0606d0007bc478c31bedbd25349831
@@ -4,4 +4,7 @@ Manifest.txt
4
4
  README.md
5
5
  Rakefile
6
6
  lib/michelson.rb
7
+ lib/michelson/michelson.rb
7
8
  lib/michelson/version.rb
9
+ test/helper.rb
10
+ test/test_counter.rb
data/README.md CHANGED
@@ -14,8 +14,9 @@ michelson gem / library - test simulator / runtime for type-safe 'n' functional
14
14
 
15
15
  **What's Michelson? What's Liquidity?**
16
16
 
17
- The Liquidity language lets you program contracts with (higher-level type-safe functional) OCaml or ReasonML syntax (see <http://www.liquidity-lang.org>)
18
- compiling to (lower-level) Michelson stack machine bytecode (see <https://www.michelson-lang.com>).
17
+ The [Liquidity language](http://www.liquidity-lang.org) lets you programm (crypto) contracts with (higher-level type-safe functional) OCaml or ReasonML syntax
18
+ compiling to (lower-level) [Michelson stack machine bytecode](https://www.michelson-lang.com).
19
+
19
20
 
20
21
  Using the michelson test simulator / runtime for type-safe 'n' functional (crypto) contracts you can now use a "Yes, It's Just Ruby" syntax.
21
22
 
@@ -0,0 +1,164 @@
1
+ # encoding: utf-8
2
+
3
+
4
+
5
+ def type( class_name, *args )
6
+ puts "define type #{class_name}:"
7
+ pp args
8
+
9
+ if args.size == 1 && args[0].is_a?( Class )
10
+ klass = args[0]
11
+ Kernel.const_set( class_name, klass )
12
+ elsif args.size == 1 && args[0].is_a?( Hash )
13
+ keys = args[0].keys
14
+ klass = Struct.new( *keys )
15
+ Kernel.const_set( class_name, klass )
16
+ else
17
+ raise ArgumentError.new( "Class or Hash expected")
18
+ end
19
+ end
20
+
21
+
22
+ def define_function( method, signature )
23
+ ## todo/fix: check if we are in a module ?
24
+ ## only use Object.__send__ as a (last) fallback (for convenience) - why? why not?
25
+ Object.__send__( :alias_method, "#{method}_unsafe", method )
26
+
27
+ puts "define function #{method}:"
28
+ pp signature
29
+
30
+ define_method method do |*args|
31
+ if args.size == 0
32
+ call_inspect = "#{method}()"
33
+ else
34
+ args_inspect = args.map { |arg| arg.inspect }.join( ", " )
35
+ call_inspect = "#{method}( #{args_inspect} )"
36
+ end
37
+ puts "calling #{call_inspect}..."
38
+
39
+ __send__( "#{method}_unsafe", *args ).tap do |result|
40
+ puts "returning:"
41
+ pp result
42
+ end
43
+ end
44
+ end
45
+
46
+
47
+ def sig( *args )
48
+ method = args.pop # remove last element (assume it's a method)
49
+ signature = args
50
+ define_function( method, signature )
51
+ end
52
+
53
+ def init( *args )
54
+ sig( *args )
55
+ end
56
+
57
+ def entry( *args )
58
+ sig( *args )
59
+ end
60
+
61
+
62
+
63
+ Nat = Integer
64
+ Money = Integer
65
+ KeyHash = String
66
+ Address = String
67
+
68
+
69
+
70
+
71
+ def Option( arg ) arg; end
72
+
73
+ _ = nil ## predefine "global" underscore variable
74
+
75
+
76
+ def failwith( msg, *args )
77
+ if args.size == 0
78
+ msg_inspect = msg
79
+ else
80
+ args_inspect = args.map { |arg| arg.inspect }.join( ", " )
81
+ msg_inspect = "#{msg}: #{args_inspect}"
82
+ end
83
+ fail msg_inspect
84
+ end
85
+
86
+ class Current
87
+ def self.amount=(value) @amount = value; end
88
+ def self.amount() @amount ||= 0; end
89
+
90
+ def self.sender=(value) @sender = value; end
91
+ def self.sender() @sender ||= "0x0000"; end
92
+
93
+
94
+ ## todo/check: Current.failwith exits? - always use "global" failwith - why? why not?
95
+ def self.failwith( *args)
96
+ ## hack: todo - is there a better way to call "global" outer failwith function/method ???
97
+ Object.send( :failwith, *args );
98
+ end
99
+ end
100
+
101
+
102
+
103
+ class Integer
104
+ def tz() self; end ## tezzies (cryptocurrency)
105
+ def p() self; end ## p(ositive) integer number (0... only)
106
+ end
107
+
108
+
109
+ def is_nat( num )
110
+ if num >=0
111
+ num ## a.k.a Some
112
+ else
113
+ nil ## a.k.a None
114
+ end
115
+ end
116
+
117
+
118
+ module Map
119
+ def self.find( key, map )
120
+ value = map[key]
121
+ value
122
+ end
123
+
124
+ def self.add( key, value, map )
125
+ map.merge( Hash[key,value] )
126
+ end
127
+
128
+ def self.remove( key, map )
129
+ ## todo: check if there's better way??
130
+ new_map = map.merge( {} )
131
+ new_map.delete( key )
132
+ new_map
133
+ end
134
+ end
135
+
136
+ module BigMap
137
+ end
138
+
139
+
140
+
141
+ def Object.const_missing( name )
142
+ puts "const_missing:"
143
+ pp name
144
+ if name.to_s.start_with?( "Map‹" )
145
+ Map
146
+ elsif name.to_s.start_with?( "BigMap‹" )
147
+ BigMap
148
+ else
149
+ super
150
+ end
151
+ end
152
+
153
+
154
+ def match( obj, matchers )
155
+ ## pp obj
156
+ ## pp matchers
157
+ ## note: assume None/Some for now
158
+ if obj
159
+ matchers[:Some].call( obj )
160
+ else
161
+ ## none
162
+ matchers[:None].call
163
+ end
164
+ end
@@ -5,7 +5,7 @@ module Michelson
5
5
 
6
6
  MAJOR = 0
7
7
  MINOR = 1
8
- PATCH = 0
8
+ PATCH = 1
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
@@ -0,0 +1,8 @@
1
+ ## minitest setup
2
+
3
+ require 'minitest/autorun'
4
+
5
+
6
+ ## our own code
7
+
8
+ require 'michelson'
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_counter.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ type :Storage, Integer
12
+
13
+ init [],
14
+ def storage()
15
+ 0
16
+ end
17
+
18
+ entry [Integer],
19
+ def inc( by, storage )
20
+ [[], storage + by]
21
+ end
22
+
23
+
24
+ class TestCounter < MiniTest::Test
25
+
26
+ def test_storage
27
+ pp Storage
28
+ assert_equal Storage, Integer
29
+ end
30
+
31
+ def test_call
32
+ storage = storage()
33
+ assert_equal 0, storage
34
+
35
+ _, storage = inc( 2, storage )
36
+ assert_equal 2, storage
37
+
38
+ _, storage = inc( 1, storage )
39
+ assert_equal 3, storage
40
+ end
41
+
42
+ end # class TestCounter
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: michelson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -55,7 +55,10 @@ files:
55
55
  - README.md
56
56
  - Rakefile
57
57
  - lib/michelson.rb
58
+ - lib/michelson/michelson.rb
58
59
  - lib/michelson/version.rb
60
+ - test/helper.rb
61
+ - test/test_counter.rb
59
62
  homepage: https://github.com/s6ruby/ruby-to-michelson
60
63
  licenses:
61
64
  - Public Domain