Top Level Namespace
Defined Under Namespace
Modules: BigMap, Map, Michelson
Classes: Current, Integer
Constant Summary
collapse
- Nat =
Integer
- Money =
Integer
- KeyHash =
String
- Address =
String
Instance Method Summary
collapse
Instance Method Details
#define_function(method, signature) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/michelson/michelson.rb', line 22
def define_function( method, signature )
Object.__send__( :alias_method, "#{method}_unsafe", method )
puts "define function #{method}:"
pp signature
define_method method do |*args|
if args.size == 0
call_inspect = "#{method}()"
else
args_inspect = args.map { |arg| arg.inspect }.join( ", " )
call_inspect = "#{method}( #{args_inspect} )"
end
puts "calling #{call_inspect}..."
__send__( "#{method}_unsafe", *args ).tap do |result|
puts "returning:"
pp result
end
end
end
|
#entry(*args) ⇒ Object
57
58
59
|
# File 'lib/michelson/michelson.rb', line 57
def entry( *args )
sig( *args )
end
|
#failwith(msg, *args) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/michelson/michelson.rb', line 76
def failwith( msg, *args )
if args.size == 0
msg_inspect = msg
else
args_inspect = args.map { |arg| arg.inspect }.join( ", " )
msg_inspect = "#{msg}: #{args_inspect}"
end
fail msg_inspect
end
|
#init(*args) ⇒ Object
53
54
55
|
# File 'lib/michelson/michelson.rb', line 53
def init( *args )
sig( *args )
end
|
#is_nat(num) ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/michelson/michelson.rb', line 109
def is_nat( num )
if num >=0
num else
nil end
end
|
#match(obj, matchers) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/michelson/michelson.rb', line 154
def match( obj, matchers )
if obj
matchers[:Some].call( obj )
else
matchers[:None].call
end
end
|
#Option(arg) ⇒ Object
71
|
# File 'lib/michelson/michelson.rb', line 71
def Option( arg ) arg; end
|
#sig(*args) ⇒ Object
47
48
49
50
51
|
# File 'lib/michelson/michelson.rb', line 47
def sig( *args )
method = args.pop signature = args
define_function( method, signature )
end
|
#type(class_name, *args) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/michelson/michelson.rb', line 5
def type( class_name, *args )
puts "define type #{class_name}:"
pp args
if args.size == 1 && (args[0].is_a?( Class ) || args[0].is_a?( Module ))
klass = args[0]
Kernel.const_set( class_name, klass )
elsif args.size == 1 && args[0].is_a?( Hash )
keys = args[0].keys
klass = Struct.new( *keys )
Kernel.const_set( class_name, klass )
else
raise ArgumentError.new( "Class|Module or Hash expected")
end
end
|