tealrb 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -69,6 +69,24 @@ module TEALrb
69
69
  insert_after(node.loc.name, '.call') unless ['@teal_methods', '@subroutines', '@scratch'].include? node.source
70
70
  super
71
71
  end
72
+
73
+ def on_gvasgn(node)
74
+ unless RuboCop::Cop::Style::GlobalVars::BUILT_IN_VARS.include? node.loc.name.source.to_sym
75
+ var_name = node.loc.name.source[1..]
76
+ replace(node.loc.name, "@scratch[:#{var_name}]")
77
+ end
78
+
79
+ super
80
+ end
81
+
82
+ def on_gvar(node)
83
+ unless RuboCop::Cop::Style::GlobalVars::BUILT_IN_VARS.include? node.loc.name.source.to_sym
84
+ var_name = node.loc.name.source[1..]
85
+ replace(node.loc.name, "@scratch[:#{var_name}]")
86
+ end
87
+
88
+ super
89
+ end
72
90
  end
73
91
 
74
92
  class ComparisonRewriter < Rewriter
@@ -107,7 +125,7 @@ module TEALrb
107
125
  super
108
126
  end
109
127
 
110
- OPCODE_METHODS = TEALrb::Opcodes.instance_methods.freeze
128
+ OPCODE_METHODS = TEALrb::Opcodes::AllOpcodes.instance_methods.freeze
111
129
 
112
130
  def on_send(node)
113
131
  meth_name = node.children[1]
@@ -116,7 +134,7 @@ module TEALrb
116
134
  if meth_name[/(byte|int)cblock/]
117
135
  @skips += node.children[2..]
118
136
  else
119
- params = TEALrb::Opcodes.instance_method(meth_name).parameters
137
+ params = TEALrb::Opcodes::AllOpcodes.instance_method(meth_name).parameters
120
138
  req_params = params.count { |param| param[0] == :req }
121
139
  @skips += node.children[2..(1 + req_params.size)] unless req_params.zero?
122
140
  end
@@ -131,7 +149,7 @@ module TEALrb
131
149
  @skips << node.children[2]
132
150
  elsif node.children.first&.children&.last == :@scratch && meth_name[/=$/]
133
151
  nil
134
- elsif %i[@scratch Gtxn].include? node.children.first&.children&.last
152
+ elsif %i[@scratch Gtxn Accounts ApplicationArgs Assets Apps Logs].include? node.children.first&.children&.last
135
153
  @skips << node.children.last
136
154
  end
137
155
 
@@ -169,6 +187,19 @@ module TEALrb
169
187
  end
170
188
  end
171
189
 
190
+ class InlineIfRewriter < Rewriter
191
+ def on_if(node)
192
+ unless node.loc.respond_to? :else
193
+ conditional = node.children[0].source
194
+ if_blk = node.children[1].source
195
+
196
+ replace(node.loc.expression, "if(#{conditional})\n#{if_blk}\nend")
197
+ end
198
+
199
+ super
200
+ end
201
+ end
202
+
172
203
  class IfRewriter < Rewriter
173
204
  def on_if(node)
174
205
  case node.loc.keyword.source
@@ -5,21 +5,25 @@ module TEALrb
5
5
  def initialize
6
6
  @open_slots = (0..256).to_a
7
7
  @named_slots = {}
8
+ @values = {}
8
9
  end
9
10
 
10
11
  def [](key)
11
12
  TEAL.instance << "load #{@named_slots[key]} // #{key}"
13
+ @values[key]
12
14
  end
13
15
 
14
- def []=(key, _value)
15
- store(key)
16
+ def []=(key, value)
17
+ store(key, value)
16
18
  end
17
19
 
18
- def store(key)
20
+ def store(key, value = TEAL.instance)
21
+ @values[key] = value
19
22
  TEAL.instance << "store #{@named_slots[key] ||= @open_slots.shift} // #{key}"
20
23
  end
21
24
 
22
25
  def delete(key)
26
+ @values.delete(key)
23
27
  @open_slots << @named_slots.delete(key)
24
28
  end
25
29
 
@@ -33,21 +37,5 @@ module TEALrb
33
37
  def unreserve(slot)
34
38
  @open_slots << slot
35
39
  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
52
40
  end
53
41
  end
data/lib/tealrb.rb CHANGED
@@ -44,13 +44,13 @@ module TEALrb
44
44
 
45
45
  TEALrb::Opcodes::BINARY_OPCODE_METHOD_MAPPING.each do |meth, opcode|
46
46
  define_method(meth) do |other|
47
- ExtendedOpcodes.send(opcode, self, other)
47
+ TEALrb::Opcodes::ExtendedOpcodes.send(opcode, self, other)
48
48
  end
49
49
  end
50
50
 
51
51
  TEALrb::Opcodes::UNARY_OPCODE_METHOD_MAPPING.each do |meth, opcode|
52
52
  define_method(meth) do
53
- ExtendedOpcodes.send(opcode, self)
53
+ TEALrb::Opcodes::ExtendedOpcodes.send(opcode, self)
54
54
  end
55
55
  end
56
56
  end
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.8.0
4
+ version: 0.10.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-07-30 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.27'
33
+ version: '1.36'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.27'
40
+ version: '1.36'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.6.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.21.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.21.2
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: yard
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -177,5 +191,5 @@ requirements: []
177
191
  rubygems_version: 3.1.6
178
192
  signing_key:
179
193
  specification_version: 4
180
- summary: A DSL for building Algorand applications
194
+ summary: A DSL for building Algorand smart contracts
181
195
  test_files: []