tealrb 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tealrb/contract.rb +11 -15
- data/lib/tealrb/if_block.rb +16 -17
- data/lib/tealrb/opcode_modules.rb +49 -7
- data/lib/tealrb/opcodes.rb +155 -155
- data/lib/tealrb/rewriters.rb +39 -22
- data/lib/tealrb/scratch.rb +19 -4
- data/lib/tealrb.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94ca888a944ccee0517d5e543498570af448a9eb3ea1ba74d3d3261ffc4b86f0
|
4
|
+
data.tar.gz: 54ac7826a7af43fb82fa17cf010a2ce869511546067f7a151181b86d3445b0bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f986ae5a4e3c37460142951923c3908ec95b58d0d91f695a49a07f8e8eee062499d496b185e1f2eafec8ed2020ca9d83a4c8c50c97531a8a67e26057e7bb794
|
7
|
+
data.tar.gz: c73f78d20f1c76ccc41e42450f713b14dc42049d8d44ee1498c59e38cda3e7699e4f1e655932f5b86c68d707d1a1abba7d59fc5c92244552236bb2a472a3d4c2
|
data/lib/tealrb/contract.rb
CHANGED
@@ -6,6 +6,7 @@ module TEALrb
|
|
6
6
|
include Opcodes
|
7
7
|
include ABI
|
8
8
|
include Rewriters
|
9
|
+
include MaybeOps
|
9
10
|
|
10
11
|
attr_reader :teal
|
11
12
|
|
@@ -69,7 +70,8 @@ module TEALrb
|
|
69
70
|
# sets the `#pragma version`, defines teal methods, and defines subroutines
|
70
71
|
def initialize
|
71
72
|
@teal = TEAL.new ["#pragma version #{self.class.version}"]
|
72
|
-
|
73
|
+
IfBlock.id = 0
|
74
|
+
@scratch = Scratch.new
|
73
75
|
|
74
76
|
self.class.subroutines.each_key do |name|
|
75
77
|
define_singleton_method(name) do |*_args|
|
@@ -96,8 +98,6 @@ module TEALrb
|
|
96
98
|
# @param definition [Lambda, Proc, UnboundMethod] the method definition
|
97
99
|
# @return [nil]
|
98
100
|
def define_teal_method(name, definition)
|
99
|
-
@teal.set_as_current
|
100
|
-
|
101
101
|
new_source = generate_method_source(name, definition)
|
102
102
|
|
103
103
|
define_singleton_method(name) do |*_args|
|
@@ -112,13 +112,11 @@ module TEALrb
|
|
112
112
|
# @param definition [Lambda, Proc, UnboundMethod] the method definition
|
113
113
|
# @return [nil]
|
114
114
|
def define_subroutine(name, definition)
|
115
|
-
@teal.set_as_current
|
116
|
-
|
117
115
|
define_singleton_method(name) do |*_args|
|
118
116
|
callsub(name)
|
119
117
|
end
|
120
118
|
|
121
|
-
|
119
|
+
TEAL.instance << 'b main' unless TEAL.instance.include? 'b main'
|
122
120
|
|
123
121
|
label(name) # add teal label
|
124
122
|
|
@@ -140,17 +138,17 @@ module TEALrb
|
|
140
138
|
def comment(content, inline: false)
|
141
139
|
content = " #{content}" unless content[0] == ' '
|
142
140
|
if inline
|
143
|
-
last_line =
|
144
|
-
|
141
|
+
last_line = TEAL.instance.pop
|
142
|
+
TEAL.instance << "#{last_line} //#{content}"
|
145
143
|
else
|
146
|
-
|
144
|
+
TEAL.instance << "//#{content}"
|
147
145
|
end
|
148
146
|
end
|
149
147
|
|
150
148
|
# inserts a string into TEAL source
|
151
149
|
# @param string [String] the string to insert
|
152
150
|
def placeholder(string)
|
153
|
-
|
151
|
+
TEAL.instance << string
|
154
152
|
end
|
155
153
|
|
156
154
|
# the hash of the abi description
|
@@ -162,15 +160,13 @@ module TEALrb
|
|
162
160
|
# @param string [String] string to transpile
|
163
161
|
# @return [nil]
|
164
162
|
def compile_string(string)
|
165
|
-
@teal.set_as_current
|
166
163
|
eval_tealrb(rewrite(string), debug_context: 'compile_string')
|
167
164
|
nil
|
168
165
|
end
|
169
166
|
|
170
167
|
# transpiles #main
|
171
168
|
def compile
|
172
|
-
|
173
|
-
@teal << 'main:' if @teal.include? 'b main'
|
169
|
+
TEAL.instance << 'main:' if TEAL.instance.include? 'b main'
|
174
170
|
eval_tealrb(rewrite(method(:main).source, method_rewriter: true), debug_context: 'main')
|
175
171
|
end
|
176
172
|
|
@@ -227,7 +223,7 @@ module TEALrb
|
|
227
223
|
end
|
228
224
|
|
229
225
|
def eval_tealrb(s, debug_context:)
|
230
|
-
pre_teal = Array.new
|
226
|
+
pre_teal = Array.new TEAL.instance
|
231
227
|
|
232
228
|
if self.class.debug
|
233
229
|
puts "DEBUG: Evaluating the following code (#{debug_context}):"
|
@@ -239,7 +235,7 @@ module TEALrb
|
|
239
235
|
|
240
236
|
if self.class.debug
|
241
237
|
puts "DEBUG: Resulting TEAL (#{debug_context}):"
|
242
|
-
puts Array.new(
|
238
|
+
puts Array.new(TEAL.instance) - pre_teal
|
243
239
|
puts ''
|
244
240
|
end
|
245
241
|
rescue SyntaxError, StandardError => e
|
data/lib/tealrb/if_block.rb
CHANGED
@@ -6,39 +6,38 @@ module TEALrb
|
|
6
6
|
attr_accessor :id
|
7
7
|
end
|
8
8
|
|
9
|
-
@id =
|
9
|
+
@id = 0
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
self.class.id
|
13
|
-
@teal = teal
|
11
|
+
def initialize(_cond, &blk)
|
12
|
+
self.class.id ||= 0
|
14
13
|
@else_count = 0
|
15
|
-
@id = self.class.id
|
14
|
+
@id = self.class.id
|
16
15
|
@end_label = "if#{@id}_end:"
|
17
16
|
|
18
|
-
self.class.id
|
17
|
+
self.class.id += 1
|
19
18
|
|
20
|
-
|
19
|
+
TEAL.instance << "bz if#{@id}_else0"
|
21
20
|
blk.call
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
TEAL.instance << "b if#{@id}_end"
|
22
|
+
TEAL.instance << "if#{@id}_else0:"
|
23
|
+
TEAL.instance << @end_label
|
25
24
|
end
|
26
25
|
|
27
26
|
def elsif(_cond, &blk)
|
28
27
|
@else_count += 1
|
29
|
-
|
30
|
-
|
28
|
+
TEAL.instance.delete @end_label
|
29
|
+
TEAL.instance << "bz if#{@id}_else#{@else_count}"
|
31
30
|
blk.call
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
TEAL.instance << "b if#{@id}_end"
|
32
|
+
TEAL.instance << "if#{@id}_else#{@else_count}:"
|
33
|
+
TEAL.instance << @end_label
|
35
34
|
self
|
36
35
|
end
|
37
36
|
|
38
37
|
def else(&blk)
|
39
|
-
|
38
|
+
TEAL.instance.delete @end_label
|
40
39
|
blk.call
|
41
|
-
|
40
|
+
TEAL.instance << @end_label
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -33,7 +33,7 @@ module TEALrb
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def txn_type_int(type)
|
36
|
-
|
36
|
+
TEAL.instance << "int #{type}"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -603,7 +603,6 @@ module TEALrb
|
|
603
603
|
extend AppFields
|
604
604
|
|
605
605
|
def self.opcode(field, app_id = nil)
|
606
|
-
@teal = TEALrb::TEAL.current[Thread.current]
|
607
606
|
app_params_get field, app_id
|
608
607
|
end
|
609
608
|
end
|
@@ -613,7 +612,6 @@ module TEALrb
|
|
613
612
|
extend AssetFields
|
614
613
|
|
615
614
|
def self.opcode(field, asset = nil)
|
616
|
-
@teal = TEALrb::TEAL.current[Thread.current]
|
617
615
|
asset_params_get field, asset
|
618
616
|
end
|
619
617
|
end
|
@@ -623,7 +621,6 @@ module TEALrb
|
|
623
621
|
extend AccountFields
|
624
622
|
|
625
623
|
def self.opcode(field, account = nil)
|
626
|
-
@teal = TEALrb::TEAL.current[Thread.current]
|
627
624
|
acct_params_get field, account
|
628
625
|
end
|
629
626
|
end
|
@@ -642,7 +639,6 @@ module TEALrb
|
|
642
639
|
extend Opcodes
|
643
640
|
|
644
641
|
def self.opcode(field, index)
|
645
|
-
@teal = TEALrb::TEAL.current[Thread.current]
|
646
642
|
gtxn index, field
|
647
643
|
end
|
648
644
|
|
@@ -672,7 +668,6 @@ module TEALrb
|
|
672
668
|
end
|
673
669
|
|
674
670
|
def [](index)
|
675
|
-
@teal = TEALrb::TEAL.current[Thread.current]
|
676
671
|
txna @field, index
|
677
672
|
end
|
678
673
|
end
|
@@ -704,7 +699,6 @@ module TEALrb
|
|
704
699
|
extend GlobalFields
|
705
700
|
|
706
701
|
def self.opcode(field)
|
707
|
-
@teal = TEALrb::TEAL.current[Thread.current]
|
708
702
|
global field
|
709
703
|
end
|
710
704
|
|
@@ -722,5 +716,53 @@ module TEALrb
|
|
722
716
|
Txna.application_args[index]
|
723
717
|
end
|
724
718
|
end
|
719
|
+
|
720
|
+
module MaybeOps
|
721
|
+
include Opcodes
|
722
|
+
|
723
|
+
def app_param_exists?(field, _app_id = nil)
|
724
|
+
app_params_get field
|
725
|
+
swap
|
726
|
+
pop
|
727
|
+
end
|
728
|
+
|
729
|
+
def app_param_value(field, _app_id = nil)
|
730
|
+
app_params_get field
|
731
|
+
pop
|
732
|
+
end
|
733
|
+
|
734
|
+
def asset_param_exists?(field, _asset_id = nil)
|
735
|
+
asset_params_get field
|
736
|
+
swap
|
737
|
+
pop
|
738
|
+
end
|
739
|
+
|
740
|
+
def asset_param_value(field, _asset_id = nil)
|
741
|
+
asset_params_get field
|
742
|
+
pop
|
743
|
+
end
|
744
|
+
|
745
|
+
def app_local_ex_exists?(_account = nil, _applicaiton = nil, _key = nil)
|
746
|
+
app_local_get_ex
|
747
|
+
swap
|
748
|
+
pop
|
749
|
+
end
|
750
|
+
|
751
|
+
def app_local_ex_value(_account = nil, _applicaiton = nil, _key = nil)
|
752
|
+
app_local_get_ex
|
753
|
+
pop
|
754
|
+
end
|
755
|
+
|
756
|
+
def app_global_ex_exists?(_account = nil, _applicaiton = nil, _key = nil)
|
757
|
+
app_global_get_ex
|
758
|
+
swap
|
759
|
+
pop
|
760
|
+
end
|
761
|
+
|
762
|
+
def app_global_ex_value(_account = nil, _applicaiton = nil, _key = nil)
|
763
|
+
app_global_get_ex
|
764
|
+
pop
|
765
|
+
end
|
766
|
+
end
|
725
767
|
end
|
726
768
|
end
|
data/lib/tealrb/opcodes.rb
CHANGED
@@ -42,620 +42,620 @@ module TEALrb
|
|
42
42
|
}.freeze
|
43
43
|
|
44
44
|
def acct_params_get(field, _account = nil)
|
45
|
-
|
45
|
+
TEAL.instance << "acct_params_get #{field}"
|
46
46
|
end
|
47
47
|
|
48
48
|
def add(_a = nil, _b = nil)
|
49
|
-
|
49
|
+
TEAL.instance << '+'
|
50
50
|
end
|
51
51
|
|
52
52
|
def addr(address)
|
53
|
-
|
53
|
+
TEAL.instance << "addr #{address}"
|
54
54
|
end
|
55
55
|
|
56
56
|
def addw(_a = nil, _b = nil)
|
57
|
-
|
57
|
+
TEAL.instance << 'addw'
|
58
58
|
end
|
59
59
|
|
60
60
|
def app_global_del(_key = nil)
|
61
|
-
|
61
|
+
TEAL.instance << 'app_global_del'
|
62
62
|
end
|
63
63
|
|
64
64
|
def app_global_get(_key = nil)
|
65
|
-
|
65
|
+
TEAL.instance << 'app_global_get'
|
66
66
|
end
|
67
67
|
|
68
68
|
def app_global_get_ex(_app = nil, _key = nil)
|
69
|
-
|
69
|
+
TEAL.instance << 'app_global_get_ex'
|
70
70
|
end
|
71
71
|
|
72
72
|
def app_global_put(_key = nil, _value = nil)
|
73
|
-
|
73
|
+
TEAL.instance << 'app_global_put'
|
74
74
|
end
|
75
75
|
|
76
76
|
def app_local_del(_account = nil, _key = nil)
|
77
|
-
|
77
|
+
TEAL.instance << 'app_local_del'
|
78
78
|
end
|
79
79
|
|
80
80
|
def app_local_get(_account = nil, _key = nil)
|
81
|
-
|
81
|
+
TEAL.instance << 'app_local_get'
|
82
82
|
end
|
83
83
|
|
84
84
|
def app_local_get_ex(_account = nil, _application = nil, _key = nil)
|
85
|
-
|
85
|
+
TEAL.instance << 'app_local_get_ex'
|
86
86
|
end
|
87
87
|
|
88
88
|
def app_local_put(_account = nil, _key = nil, _value = nil)
|
89
|
-
|
89
|
+
TEAL.instance << 'app_local_put'
|
90
90
|
end
|
91
91
|
|
92
92
|
def app_opted_in(_account = nil, _app = nil)
|
93
|
-
|
93
|
+
TEAL.instance << 'app_opted_in'
|
94
94
|
end
|
95
95
|
|
96
96
|
def app_params_get(field, _app_id = nil)
|
97
|
-
|
97
|
+
TEAL.instance << "app_params_get #{field}"
|
98
98
|
end
|
99
99
|
|
100
100
|
def approve
|
101
|
-
|
102
|
-
|
101
|
+
TEAL.instance << 'int 1'
|
102
|
+
TEAL.instance << 'return'
|
103
103
|
end
|
104
104
|
|
105
105
|
def arg(index)
|
106
|
-
|
106
|
+
TEAL.instance << "arg #{index}"
|
107
107
|
end
|
108
108
|
|
109
109
|
def arg_0 # rubocop:disable Naming/VariableNumber
|
110
|
-
|
110
|
+
TEAL.instance << 'arg_0'
|
111
111
|
end
|
112
112
|
|
113
113
|
def arg_1 # rubocop:disable Naming/VariableNumber
|
114
|
-
|
114
|
+
TEAL.instance << 'arg_1'
|
115
115
|
end
|
116
116
|
|
117
117
|
def arg_2 # rubocop:disable Naming/VariableNumber
|
118
|
-
|
118
|
+
TEAL.instance << 'arg_2'
|
119
119
|
end
|
120
120
|
|
121
121
|
def arg_3 # rubocop:disable Naming/VariableNumber
|
122
|
-
|
122
|
+
TEAL.instance << 'arg_3'
|
123
123
|
end
|
124
124
|
|
125
125
|
def args(_index = nil)
|
126
|
-
|
126
|
+
TEAL.instance << 'args'
|
127
127
|
end
|
128
128
|
|
129
129
|
def assert(_expr = nil)
|
130
|
-
|
130
|
+
TEAL.instance << 'assert'
|
131
131
|
end
|
132
132
|
|
133
133
|
def asset_holding_get(field, _account = nil, _asset = nil)
|
134
|
-
|
134
|
+
TEAL.instance << "asset_holding_get #{field}"
|
135
135
|
end
|
136
136
|
|
137
137
|
def asset_params_get(field, _asset = nil)
|
138
|
-
|
138
|
+
TEAL.instance << "asset_params_get #{field}"
|
139
139
|
end
|
140
140
|
|
141
141
|
def b(target)
|
142
|
-
|
142
|
+
TEAL.instance << "#{__method__} #{target}"
|
143
143
|
end
|
144
144
|
|
145
145
|
def base32(input)
|
146
|
-
|
146
|
+
TEAL.instance << "byte base32(#{input})"
|
147
147
|
end
|
148
148
|
|
149
149
|
def balance(_account = nil)
|
150
|
-
|
150
|
+
TEAL.instance << 'balance'
|
151
151
|
end
|
152
152
|
|
153
153
|
def big_endian_add(_a = nil, _b = nil)
|
154
|
-
|
154
|
+
TEAL.instance << 'b+'
|
155
155
|
end
|
156
156
|
|
157
157
|
def big_endian_divide(_a = nil, _b = nil)
|
158
|
-
|
158
|
+
TEAL.instance << 'b/'
|
159
159
|
end
|
160
160
|
|
161
161
|
def big_endian_equal(_a = nil, _b = nil)
|
162
|
-
|
162
|
+
TEAL.instance << 'b=='
|
163
163
|
end
|
164
164
|
|
165
165
|
def big_endian_less(_a = nil, _b = nil)
|
166
|
-
|
166
|
+
TEAL.instance << 'b<'
|
167
167
|
end
|
168
168
|
|
169
169
|
def big_endian_less_eq(_a = nil, _b = nil)
|
170
|
-
|
170
|
+
TEAL.instance << 'b<='
|
171
171
|
end
|
172
172
|
|
173
173
|
def big_endian_modulo(_a = nil, _b = nil)
|
174
|
-
|
174
|
+
TEAL.instance << 'b%'
|
175
175
|
end
|
176
176
|
|
177
177
|
def big_endian_more(_a = nil, _b = nil)
|
178
|
-
|
178
|
+
TEAL.instance << 'b>'
|
179
179
|
end
|
180
180
|
|
181
181
|
def big_endian_more_eq(_a = nil, _b = nil)
|
182
|
-
|
182
|
+
TEAL.instance << 'b>='
|
183
183
|
end
|
184
184
|
|
185
185
|
def big_endian_multiply(_a = nil, _b = nil)
|
186
|
-
|
186
|
+
TEAL.instance << 'b*'
|
187
187
|
end
|
188
188
|
|
189
189
|
def big_endian_not_equal(_a = nil, _b = nil)
|
190
|
-
|
190
|
+
TEAL.instance << 'b!='
|
191
191
|
end
|
192
192
|
|
193
193
|
def big_endian_subtract(_a = nil, _b = nil)
|
194
|
-
|
194
|
+
TEAL.instance << 'b-'
|
195
195
|
end
|
196
196
|
|
197
197
|
def bitlen(_input = nil)
|
198
|
-
|
198
|
+
TEAL.instance << 'bitlen'
|
199
199
|
end
|
200
200
|
|
201
201
|
def bitwise_and(_a = nil, _b = nil)
|
202
|
-
|
202
|
+
TEAL.instance << '&'
|
203
203
|
end
|
204
204
|
|
205
205
|
def bitwise_byte_invert(_a = nil, _b = nil)
|
206
|
-
|
206
|
+
TEAL.instance << 'b~'
|
207
207
|
end
|
208
208
|
|
209
209
|
def bitwise_invert(_a = nil, _b = nil)
|
210
|
-
|
210
|
+
TEAL.instance << '~'
|
211
211
|
end
|
212
212
|
|
213
213
|
def bitwise_or(_a = nil, _b = nil)
|
214
|
-
|
214
|
+
TEAL.instance << '|'
|
215
215
|
end
|
216
216
|
|
217
217
|
def bitwise_xor(_a = nil, _b = nil)
|
218
|
-
|
218
|
+
TEAL.instance << '^'
|
219
219
|
end
|
220
220
|
|
221
221
|
def bnz(target)
|
222
|
-
|
222
|
+
TEAL.instance << "#{__method__} #{target}"
|
223
223
|
end
|
224
224
|
|
225
225
|
def bsqrt(_big_endian_uint = nil)
|
226
|
-
|
226
|
+
TEAL.instance << 'bsqrt'
|
227
227
|
end
|
228
228
|
|
229
229
|
def btoi(_bytes = nil)
|
230
|
-
|
230
|
+
TEAL.instance << 'btoi'
|
231
231
|
end
|
232
232
|
|
233
233
|
def byte(string)
|
234
|
-
|
234
|
+
TEAL.instance << "byte \"#{string}\""
|
235
235
|
end
|
236
236
|
|
237
237
|
def bytec(index)
|
238
|
-
|
238
|
+
TEAL.instance << "bytec #{index}"
|
239
239
|
end
|
240
240
|
|
241
241
|
def bytec_0 # rubocop:disable Naming/VariableNumber
|
242
|
-
|
242
|
+
TEAL.instance << 'bytec_0'
|
243
243
|
end
|
244
244
|
|
245
245
|
def bytec_1 # rubocop:disable Naming/VariableNumber
|
246
|
-
|
246
|
+
TEAL.instance << 'bytec_1'
|
247
247
|
end
|
248
248
|
|
249
249
|
def bytec_2 # rubocop:disable Naming/VariableNumber
|
250
|
-
|
250
|
+
TEAL.instance << 'bytec_2'
|
251
251
|
end
|
252
252
|
|
253
253
|
def bytec_3 # rubocop:disable Naming/VariableNumber
|
254
|
-
|
254
|
+
TEAL.instance << 'bytec_3'
|
255
255
|
end
|
256
256
|
|
257
257
|
def bytecblock(*bytes)
|
258
|
-
|
258
|
+
TEAL.instance << "bytecblock #{bytes.join(' ')}"
|
259
259
|
end
|
260
260
|
|
261
261
|
def bz(target)
|
262
|
-
|
262
|
+
TEAL.instance << "#{__method__} #{target}"
|
263
263
|
end
|
264
264
|
|
265
265
|
def bzero(_length = nil)
|
266
|
-
|
266
|
+
TEAL.instance << 'bzero'
|
267
267
|
end
|
268
268
|
|
269
269
|
def callsub(name, *_args)
|
270
|
-
|
270
|
+
TEAL.instance << "callsub #{name}"
|
271
271
|
end
|
272
272
|
|
273
273
|
def concat(_a = nil, _b = nil)
|
274
|
-
|
274
|
+
TEAL.instance << 'concat'
|
275
275
|
end
|
276
276
|
|
277
277
|
def cover(count)
|
278
|
-
|
278
|
+
TEAL.instance << "cover #{count}"
|
279
279
|
end
|
280
280
|
|
281
281
|
def dig(index)
|
282
|
-
|
282
|
+
TEAL.instance << "dig #{index}"
|
283
283
|
end
|
284
284
|
|
285
285
|
def divide(_a = nil, _b = nil)
|
286
|
-
|
286
|
+
TEAL.instance << '/'
|
287
287
|
end
|
288
288
|
|
289
289
|
def divmodw(_a = nil, _b = nil)
|
290
|
-
|
290
|
+
TEAL.instance << 'divmodw'
|
291
291
|
end
|
292
292
|
|
293
293
|
def divw(_a = nil, _b = nil)
|
294
|
-
|
294
|
+
TEAL.instance << 'divw'
|
295
295
|
end
|
296
296
|
|
297
297
|
def dup(_expr = nil)
|
298
|
-
|
298
|
+
TEAL.instance << 'dup'
|
299
299
|
end
|
300
300
|
|
301
301
|
def dup2(_expr_a = nil, _expr_b = nil)
|
302
|
-
|
302
|
+
TEAL.instance << 'dup2'
|
303
303
|
end
|
304
304
|
|
305
305
|
def ecdsa_pk_decompress(index, _input = nil)
|
306
|
-
|
306
|
+
TEAL.instance << "ecdsa_pk_decompress #{index}"
|
307
307
|
end
|
308
308
|
|
309
309
|
def ecdsa_pk_recover(index, _input = nil)
|
310
|
-
|
310
|
+
TEAL.instance << "ecdsa_pk_recover #{index}"
|
311
311
|
end
|
312
312
|
|
313
313
|
def ecdsa_verify(index, _input = nil)
|
314
|
-
|
314
|
+
TEAL.instance << "ecdsa_verify #{index}"
|
315
315
|
end
|
316
316
|
|
317
317
|
def ed25519verify(_input = nil)
|
318
|
-
|
318
|
+
TEAL.instance << 'ed25519verify'
|
319
319
|
end
|
320
320
|
|
321
321
|
def equal(_a = nil, _b = nil)
|
322
|
-
|
322
|
+
TEAL.instance << '=='
|
323
323
|
end
|
324
324
|
|
325
325
|
def err
|
326
|
-
|
326
|
+
TEAL.instance << 'err'
|
327
327
|
end
|
328
328
|
|
329
329
|
def exp(_a = nil, _b = nil)
|
330
|
-
|
330
|
+
TEAL.instance << 'exp'
|
331
331
|
end
|
332
332
|
|
333
333
|
def expw(_a = nil, _b = nil)
|
334
|
-
|
334
|
+
TEAL.instance << 'expw'
|
335
335
|
end
|
336
336
|
|
337
337
|
def extract(start, length, _byte_array = nil)
|
338
|
-
|
338
|
+
TEAL.instance << "extract #{start} #{length}"
|
339
339
|
end
|
340
340
|
|
341
341
|
def extract3(_byte_array = nil, _start = nil, _exclusive_end = nil)
|
342
|
-
|
342
|
+
TEAL.instance << 'extract3'
|
343
343
|
end
|
344
344
|
|
345
345
|
def extract_uint16(_byte_array = nil, _start = nil)
|
346
|
-
|
346
|
+
TEAL.instance << 'extract_uint16'
|
347
347
|
end
|
348
348
|
|
349
349
|
def extract_uint32(_byte_array = nil, _start = nil)
|
350
|
-
|
350
|
+
TEAL.instance << 'extract_uint32'
|
351
351
|
end
|
352
352
|
|
353
353
|
def extract_uint64(_byte_array = nil, _start = nil)
|
354
|
-
|
354
|
+
TEAL.instance << 'extract_uint64'
|
355
355
|
end
|
356
356
|
|
357
357
|
def gaid(transaction_index)
|
358
|
-
|
358
|
+
TEAL.instance << "gaid #{transaction_index}"
|
359
359
|
end
|
360
360
|
|
361
361
|
def gaids(_transaction = nil)
|
362
|
-
|
362
|
+
TEAL.instance << 'gaids'
|
363
363
|
end
|
364
364
|
|
365
365
|
def getbit(_input = nil, _bit_index = nil)
|
366
|
-
|
366
|
+
TEAL.instance << 'getbit'
|
367
367
|
end
|
368
368
|
|
369
369
|
def getbyte(_input = nil, _byte_index = nil)
|
370
|
-
|
370
|
+
TEAL.instance << 'getbyte'
|
371
371
|
end
|
372
372
|
|
373
373
|
def gitxn(transaction_index, field)
|
374
|
-
|
374
|
+
TEAL.instance << "gitxn #{transaction_index} #{field}"
|
375
375
|
end
|
376
376
|
|
377
377
|
def gitxna(transaction_index, field, index)
|
378
|
-
|
378
|
+
TEAL.instance << "gitxna #{transaction_index} #{field} #{index}"
|
379
379
|
end
|
380
380
|
|
381
381
|
def gitxnas(transaction_index, field, _index = nil)
|
382
|
-
|
382
|
+
TEAL.instance << "gitxnas #{transaction_index} #{field}"
|
383
383
|
end
|
384
384
|
|
385
385
|
def gload(transaction_index, index)
|
386
|
-
|
386
|
+
TEAL.instance << "gload #{transaction_index} #{index}"
|
387
387
|
end
|
388
388
|
|
389
389
|
def gloads(index, _transaction_index = nil)
|
390
|
-
|
390
|
+
TEAL.instance << "gloads #{index}"
|
391
391
|
end
|
392
392
|
|
393
393
|
def gloadss(_transaction = nil, _index = nil)
|
394
|
-
|
394
|
+
TEAL.instance << 'gloadss'
|
395
395
|
end
|
396
396
|
|
397
397
|
def global(field)
|
398
|
-
|
398
|
+
TEAL.instance << "global #{field}"
|
399
399
|
end
|
400
400
|
|
401
401
|
def greater(_a = nil, _b = nil)
|
402
|
-
|
402
|
+
TEAL.instance << '>'
|
403
403
|
end
|
404
404
|
|
405
405
|
def greater_eq(_a = nil, _b = nil)
|
406
|
-
|
406
|
+
TEAL.instance << '>='
|
407
407
|
end
|
408
408
|
|
409
409
|
def gtxn(index, field)
|
410
|
-
|
410
|
+
TEAL.instance << "gtxn #{index} #{field}"
|
411
411
|
end
|
412
412
|
|
413
413
|
def gtxna(transaction_index, field, index)
|
414
|
-
|
414
|
+
TEAL.instance << "gtxna #{transaction_index} #{field} #{index}"
|
415
415
|
end
|
416
416
|
|
417
417
|
def gtxns(field, _transaction_index = nil)
|
418
|
-
|
418
|
+
TEAL.instance << "gtxns #{field}"
|
419
419
|
end
|
420
420
|
|
421
421
|
def gtxnsa(field, index, _transaction_index = nil)
|
422
|
-
|
422
|
+
TEAL.instance << "gtxnsa #{field} #{index}"
|
423
423
|
end
|
424
424
|
|
425
425
|
def gtxnas(transaction_index, field, _index = nil)
|
426
|
-
|
426
|
+
TEAL.instance << "gtxnas #{transaction_index} #{field}"
|
427
427
|
end
|
428
428
|
|
429
429
|
def gtxnsas(field, _transaction_index = nil, _index = nil)
|
430
|
-
|
430
|
+
TEAL.instance << "gtxnsas #{field}"
|
431
431
|
end
|
432
432
|
|
433
433
|
def int(integer)
|
434
|
-
|
434
|
+
TEAL.instance << "int #{integer}"
|
435
435
|
end
|
436
436
|
|
437
437
|
def intc(index)
|
438
|
-
|
438
|
+
TEAL.instance << "intc #{index}"
|
439
439
|
end
|
440
440
|
|
441
441
|
def intc_0 # rubocop:disable Naming/VariableNumber
|
442
|
-
|
442
|
+
TEAL.instance << 'intc_0'
|
443
443
|
end
|
444
444
|
|
445
445
|
def intc_1 # rubocop:disable Naming/VariableNumber
|
446
|
-
|
446
|
+
TEAL.instance << 'intc_1'
|
447
447
|
end
|
448
448
|
|
449
449
|
def intc_2 # rubocop:disable Naming/VariableNumber
|
450
|
-
|
450
|
+
TEAL.instance << 'intc_2'
|
451
451
|
end
|
452
452
|
|
453
453
|
def intc_3 # rubocop:disable Naming/VariableNumber
|
454
|
-
|
454
|
+
TEAL.instance << 'intc_3'
|
455
455
|
end
|
456
456
|
|
457
457
|
def intcblock(*ints)
|
458
|
-
|
458
|
+
TEAL.instance << "intcblock #{ints.join(' ')}"
|
459
459
|
end
|
460
460
|
|
461
461
|
def itob(_bytes = nil)
|
462
|
-
|
462
|
+
TEAL.instance << 'itob'
|
463
463
|
end
|
464
464
|
|
465
465
|
def itxn_begin
|
466
|
-
|
466
|
+
TEAL.instance << 'itxn_begin'
|
467
467
|
end
|
468
468
|
|
469
469
|
def itxn_field(field, _value = nil)
|
470
|
-
|
470
|
+
TEAL.instance << "itxn_field #{field}"
|
471
471
|
end
|
472
472
|
|
473
473
|
def itxn_next
|
474
|
-
|
474
|
+
TEAL.instance << 'itxn_next'
|
475
475
|
end
|
476
476
|
|
477
477
|
def itxn_submit
|
478
|
-
|
478
|
+
TEAL.instance << 'itxn_submit'
|
479
479
|
end
|
480
480
|
|
481
481
|
def itxna(field, index)
|
482
|
-
|
482
|
+
TEAL.instance << "itxna #{field} #{index}"
|
483
483
|
end
|
484
484
|
|
485
485
|
def itxnas(field, _index = nil)
|
486
|
-
|
486
|
+
TEAL.instance << "itxnas #{field}"
|
487
487
|
end
|
488
488
|
|
489
489
|
def keccak256(_input = nil)
|
490
|
-
|
490
|
+
TEAL.instance << 'keccak256'
|
491
491
|
end
|
492
492
|
|
493
493
|
def label(label_name)
|
494
|
-
|
494
|
+
TEAL.instance << "#{label_name}:"
|
495
495
|
end
|
496
496
|
|
497
497
|
def len(_input = nil)
|
498
|
-
|
498
|
+
TEAL.instance << 'len'
|
499
499
|
end
|
500
500
|
|
501
501
|
def less(_a = nil, _b = nil)
|
502
|
-
|
502
|
+
TEAL.instance << '<'
|
503
503
|
end
|
504
504
|
|
505
505
|
def less_eq(_a = nil, _b = nil)
|
506
|
-
|
506
|
+
TEAL.instance << '<='
|
507
507
|
end
|
508
508
|
|
509
509
|
def load(index)
|
510
|
-
|
510
|
+
TEAL.instance << "load #{index}"
|
511
511
|
end
|
512
512
|
|
513
513
|
def loads(_index = nil)
|
514
|
-
|
514
|
+
TEAL.instance << 'loads'
|
515
515
|
end
|
516
516
|
|
517
517
|
def log(_byte_array = nil)
|
518
|
-
|
518
|
+
TEAL.instance << 'log'
|
519
519
|
end
|
520
520
|
|
521
521
|
def method_signature(signature)
|
522
|
-
|
522
|
+
TEAL.instance << %(method "#{signature}")
|
523
523
|
end
|
524
524
|
|
525
525
|
def min_balance(_account = nil)
|
526
|
-
|
526
|
+
TEAL.instance << 'min_balance'
|
527
527
|
end
|
528
528
|
|
529
529
|
def modulo(_a = nil, _b = nil)
|
530
|
-
|
530
|
+
TEAL.instance << '%'
|
531
531
|
end
|
532
532
|
|
533
533
|
def multiply(_a = nil, _b = nil)
|
534
|
-
|
534
|
+
TEAL.instance << '*'
|
535
535
|
end
|
536
536
|
|
537
537
|
def mulw(_a = nil, _b = nil)
|
538
|
-
|
538
|
+
TEAL.instance << 'mulw'
|
539
539
|
end
|
540
540
|
|
541
541
|
def zero?(_expr = nil)
|
542
|
-
|
542
|
+
TEAL.instance << '!'
|
543
543
|
end
|
544
544
|
|
545
545
|
def not_equal(_a = nil, _b = nil)
|
546
|
-
|
546
|
+
TEAL.instance << '!='
|
547
547
|
end
|
548
548
|
|
549
549
|
def padded_bitwise_and(_a = nil, _b = nil)
|
550
|
-
|
550
|
+
TEAL.instance << 'b&'
|
551
551
|
end
|
552
552
|
|
553
553
|
def padded_bitwise_or(_a = nil, _b = nil)
|
554
|
-
|
554
|
+
TEAL.instance << 'b|'
|
555
555
|
end
|
556
556
|
|
557
557
|
def padded_bitwise_xor(_a = nil, _b = nil)
|
558
|
-
|
558
|
+
TEAL.instance << 'b^'
|
559
559
|
end
|
560
560
|
|
561
561
|
def pop(_expr = nil)
|
562
|
-
|
562
|
+
TEAL.instance << 'pop'
|
563
563
|
end
|
564
564
|
|
565
565
|
def pushbytes(string)
|
566
|
-
|
566
|
+
TEAL.instance << "pushbytes \"#{string}\""
|
567
567
|
end
|
568
568
|
|
569
569
|
def pushint(integer)
|
570
|
-
|
570
|
+
TEAL.instance << "pushint #{integer}"
|
571
571
|
end
|
572
572
|
|
573
573
|
def retsub
|
574
|
-
|
574
|
+
TEAL.instance << 'retsub'
|
575
575
|
end
|
576
576
|
|
577
577
|
def select(_expr_a = nil, _expr_b = nil, _expr_c = nil)
|
578
|
-
|
578
|
+
TEAL.instance << 'select'
|
579
579
|
end
|
580
580
|
|
581
581
|
def setbit(_input = nil, _bit_index = nil, _value = nil)
|
582
|
-
|
582
|
+
TEAL.instance << 'setbit'
|
583
583
|
end
|
584
584
|
|
585
585
|
def setbyte(_byte_array = nil, _byte_index = nil, _value = nil)
|
586
|
-
|
586
|
+
TEAL.instance << 'setbyte'
|
587
587
|
end
|
588
588
|
|
589
589
|
def sha256(_input = nil)
|
590
|
-
|
590
|
+
TEAL.instance << 'sha256'
|
591
591
|
end
|
592
592
|
|
593
593
|
def sha512_256(_input = nil) # rubocop:disable Naming/VariableNumber
|
594
|
-
|
594
|
+
TEAL.instance << 'sha512_256'
|
595
595
|
end
|
596
596
|
|
597
597
|
def shl(_a = nil, _b = nil)
|
598
|
-
|
598
|
+
TEAL.instance << 'shl'
|
599
599
|
end
|
600
600
|
|
601
601
|
def shr(_a = nil, _b = nil)
|
602
|
-
|
602
|
+
TEAL.instance << 'shr'
|
603
603
|
end
|
604
604
|
|
605
605
|
def sqrt(_integer = nil)
|
606
|
-
|
606
|
+
TEAL.instance << 'sqrt'
|
607
607
|
end
|
608
608
|
|
609
609
|
def store(index, _value = nil)
|
610
|
-
|
610
|
+
TEAL.instance << "store #{index}"
|
611
611
|
end
|
612
612
|
|
613
613
|
def stores(_index = nil, _value = nil)
|
614
|
-
|
614
|
+
TEAL.instance << 'stores'
|
615
615
|
end
|
616
616
|
|
617
617
|
def substring(start, exclusive_end, _byte_array = nil)
|
618
|
-
|
618
|
+
TEAL.instance << "substring #{start} #{exclusive_end}"
|
619
619
|
end
|
620
620
|
|
621
621
|
def substring3(_byte_array = nil, _start = nil, _exclusive_end = nil)
|
622
|
-
|
622
|
+
TEAL.instance << 'substring3'
|
623
623
|
end
|
624
624
|
|
625
625
|
def subtract(_a = nil, _b = nil)
|
626
|
-
|
626
|
+
TEAL.instance << '-'
|
627
627
|
end
|
628
628
|
|
629
629
|
def swap(_expr_a = nil, _expr_b = nil)
|
630
|
-
|
630
|
+
TEAL.instance << 'swap'
|
631
631
|
end
|
632
632
|
|
633
633
|
def teal_return(_expr = nil)
|
634
|
-
|
634
|
+
TEAL.instance << 'return'
|
635
635
|
end
|
636
636
|
|
637
637
|
def txn(field)
|
638
|
-
|
638
|
+
TEAL.instance << "txn #{field}"
|
639
639
|
end
|
640
640
|
|
641
641
|
def txna(field, index)
|
642
|
-
|
642
|
+
TEAL.instance << "txna #{field} #{index}"
|
643
643
|
end
|
644
644
|
|
645
645
|
def txnas(field, _index = nil)
|
646
|
-
|
646
|
+
TEAL.instance << "txnas #{field}"
|
647
647
|
end
|
648
648
|
|
649
649
|
def uncover(count)
|
650
|
-
|
650
|
+
TEAL.instance << "uncover #{count}"
|
651
651
|
end
|
652
652
|
|
653
653
|
def boolean_and(_a = nil, _b = nil)
|
654
|
-
|
654
|
+
TEAL.instance << '&&'
|
655
655
|
end
|
656
656
|
|
657
657
|
def boolean_or(_a = nil, _b = nil)
|
658
|
-
|
658
|
+
TEAL.instance << '||'
|
659
659
|
end
|
660
660
|
end
|
661
661
|
end
|
data/lib/tealrb/rewriters.rb
CHANGED
@@ -66,8 +66,7 @@ module TEALrb
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def on_ivar(node)
|
69
|
-
insert_after(node.loc.name, '.call') unless ['@
|
70
|
-
'@scratch'].include? node.source
|
69
|
+
insert_after(node.loc.name, '.call') unless ['@teal_methods', '@subroutines', '@scratch'].include? node.source
|
71
70
|
super
|
72
71
|
end
|
73
72
|
end
|
@@ -83,7 +82,7 @@ module TEALrb
|
|
83
82
|
|
84
83
|
class OpRewriter < Rewriter
|
85
84
|
def initialize
|
86
|
-
@skips =
|
85
|
+
@skips = []
|
87
86
|
super
|
88
87
|
end
|
89
88
|
|
@@ -110,44 +109,62 @@ module TEALrb
|
|
110
109
|
|
111
110
|
OPCODE_METHODS = TEALrb::Opcodes.instance_methods.freeze
|
112
111
|
|
113
|
-
def on_const(node)
|
114
|
-
@skips = 1 if %w[Txna Gtxn AppArgs].include? node.loc.name.source
|
115
|
-
super
|
116
|
-
end
|
117
|
-
|
118
|
-
def on_ivar(node)
|
119
|
-
@skips = 2 if node.source == '@teal_methods'
|
120
|
-
@skips = 1 if node.source == '@scratch'
|
121
|
-
end
|
122
|
-
|
123
112
|
def on_send(node)
|
124
|
-
meth_name = node.
|
113
|
+
meth_name = node.children[1]
|
125
114
|
|
126
115
|
if OPCODE_METHODS.include? meth_name
|
127
116
|
if meth_name[/(byte|int)cblock/]
|
128
|
-
@skips
|
117
|
+
@skips += node.children[2..]
|
129
118
|
else
|
130
119
|
params = TEALrb::Opcodes.instance_method(meth_name).parameters
|
131
|
-
|
120
|
+
req_params = params.count { |param| param[0] == :req }
|
121
|
+
@skips += node.children[2..(1 + req_params.size)] unless req_params.zero?
|
132
122
|
end
|
133
|
-
elsif %i[comment placeholder rb].include?
|
134
|
-
|
123
|
+
elsif %i[comment placeholder rb].include?(meth_name) ||
|
124
|
+
(%i[[] []=].include?(meth_name) &&
|
125
|
+
(
|
126
|
+
%i[@scratch @teal_methods Gtxn
|
127
|
+
AppArgs].include?(node.children[0].children.last) ||
|
128
|
+
node.children[0].children.first&.children&.last == :Txna
|
129
|
+
))
|
130
|
+
|
131
|
+
@skips << node.children[2]
|
132
|
+
elsif node.children.first&.children&.last == :@scratch && meth_name[/=$/]
|
133
|
+
nil
|
134
|
+
elsif %i[@scratch Gtxn].include? node.children.first&.children&.last
|
135
|
+
@skips << node.children.last
|
135
136
|
end
|
137
|
+
|
136
138
|
super
|
137
139
|
end
|
138
140
|
|
139
141
|
def on_int(node)
|
140
|
-
|
142
|
+
if @skips.include? node
|
143
|
+
@skips.delete(node)
|
144
|
+
else
|
145
|
+
wrap(node.source_range, 'int(', ')')
|
146
|
+
end
|
147
|
+
|
141
148
|
super
|
142
149
|
end
|
143
150
|
|
144
151
|
def on_str(node)
|
145
|
-
|
152
|
+
if @skips.include? node
|
153
|
+
@skips.delete(node)
|
154
|
+
else
|
155
|
+
wrap(node.source_range, 'byte(', ')')
|
156
|
+
end
|
157
|
+
|
146
158
|
super
|
147
159
|
end
|
148
160
|
|
149
161
|
def on_sym(node)
|
150
|
-
|
162
|
+
if @skips.include? node
|
163
|
+
@skips.delete(node)
|
164
|
+
elsif node.source_range.source[/^:/]
|
165
|
+
wrap(node.source_range, 'label(', ')')
|
166
|
+
end
|
167
|
+
|
151
168
|
super
|
152
169
|
end
|
153
170
|
end
|
@@ -156,7 +173,7 @@ module TEALrb
|
|
156
173
|
def on_if(node)
|
157
174
|
case node.loc.keyword.source
|
158
175
|
when 'if'
|
159
|
-
replace(node.loc.keyword, 'IfBlock.new(
|
176
|
+
replace(node.loc.keyword, 'IfBlock.new(')
|
160
177
|
when 'elsif'
|
161
178
|
replace(node.loc.keyword, 'end.elsif(')
|
162
179
|
end
|
data/lib/tealrb/scratch.rb
CHANGED
@@ -2,14 +2,13 @@
|
|
2
2
|
|
3
3
|
module TEALrb
|
4
4
|
class Scratch
|
5
|
-
def initialize
|
6
|
-
@teal = teal
|
5
|
+
def initialize
|
7
6
|
@open_slots = (0..256).to_a
|
8
7
|
@named_slots = {}
|
9
8
|
end
|
10
9
|
|
11
10
|
def [](key)
|
12
|
-
|
11
|
+
TEAL.instance << "load #{@named_slots[key]} // #{key}"
|
13
12
|
end
|
14
13
|
|
15
14
|
def []=(key, _value)
|
@@ -17,7 +16,7 @@ module TEALrb
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def store(key)
|
20
|
-
|
19
|
+
TEAL.instance << "store #{@named_slots[key] ||= @open_slots.shift} // #{key}"
|
21
20
|
end
|
22
21
|
|
23
22
|
def delete(key)
|
@@ -34,5 +33,21 @@ module TEALrb
|
|
34
33
|
def unreserve(slot)
|
35
34
|
@open_slots << slot
|
36
35
|
end
|
36
|
+
|
37
|
+
def respond_to_missing?
|
38
|
+
!!(meth[/=$/] || @named_slots.key?(meth.to_s))
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(meth, *args, &block)
|
42
|
+
super unless block.nil?
|
43
|
+
|
44
|
+
if meth[/=$/]
|
45
|
+
store(meth.to_s.chomp('='))
|
46
|
+
elsif @named_slots.key?(meth.to_s)
|
47
|
+
self[meth.to_s]
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
37
52
|
end
|
38
53
|
end
|
data/lib/tealrb.rb
CHANGED
@@ -16,13 +16,18 @@ require_relative 'tealrb/cmd_line/teal2tealrb'
|
|
16
16
|
module TEALrb
|
17
17
|
class TEAL < Array
|
18
18
|
class << self
|
19
|
-
|
20
|
-
|
19
|
+
attr_writer :instance
|
20
|
+
|
21
|
+
def instance
|
22
|
+
raise 'TEALrb does not support multi-threading' if Thread.current != Thread.main
|
21
23
|
|
22
|
-
|
24
|
+
@instance
|
25
|
+
end
|
26
|
+
end
|
23
27
|
|
24
|
-
def
|
25
|
-
self.class.
|
28
|
+
def initialize(teal_array)
|
29
|
+
self.class.instance = self
|
30
|
+
super
|
26
31
|
end
|
27
32
|
|
28
33
|
def teal
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tealrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Polny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: method_source
|