Skip to content

Commit d526bb9

Browse files
long-long-floatmame
authored andcommitted
Support flip flop operator
1 parent dc6be92 commit d526bb9

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/typeprof/core/ast.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def self.create_node(raw_node, lenv, use_result = true)
219219
when :for_node then ForNode.new(raw_node, lenv)
220220
when :alias_global_variable_node then AliasGlobalVariableNode.new(raw_node, lenv)
221221
when :post_execution_node then PostExecutionNode.new(raw_node, lenv)
222+
when :flip_flop_node then FlipFlopNode.new(raw_node, lenv)
222223
when :shareable_constant_node
223224
create_node(raw_node.write, lenv)
224225

lib/typeprof/core/ast/misc.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,23 @@ def install0(genv)
205205
Source.new(genv.nil_type)
206206
end
207207
end
208+
209+
class FlipFlopNode < Node
210+
def initialize(raw_node, lenv)
211+
super(raw_node, lenv)
212+
@e1 = AST.create_node(raw_node.left, lenv)
213+
@e2 = AST.create_node(raw_node.right, lenv)
214+
end
215+
216+
attr_reader :e1, :e2
217+
218+
def subnodes = { e1:, e2: }
219+
220+
def install0(genv)
221+
@e1.install(genv)
222+
@e2.install(genv)
223+
Source.new(genv.true_type, genv.false_type)
224+
end
225+
end
208226
end
209227
end

scenario/misc/flip_flop.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## update
2+
def foo
3+
n = 3
4+
if (n==2)..(n==2)
5+
# flip_flop_node can not become a return value because it is only available in condition.
6+
end
7+
end
8+
9+
## assert
10+
class Object
11+
def foo: -> nil
12+
end

0 commit comments

Comments
 (0)