ion out last changes from grammar update
surprisingly painless, considering it was more or less a rewrite
This commit is contained in:
parent
4c17ed2e6e
commit
024e6cb389
@ -183,8 +183,8 @@ module Interpreter
|
|||||||
left = get_register(@instruction.left)
|
left = get_register(@instruction.left)
|
||||||
rr = @instruction.right
|
rr = @instruction.right
|
||||||
right = get_register(rr)
|
right = get_register(rr)
|
||||||
case @instruction.operator
|
case @instruction.operator.to_s
|
||||||
when :add
|
when "add"
|
||||||
result = left + right
|
result = left + right
|
||||||
when "/"
|
when "/"
|
||||||
result = left / right
|
result = left / right
|
||||||
@ -195,7 +195,7 @@ module Interpreter
|
|||||||
when "=="
|
when "=="
|
||||||
result = left == right
|
result = left == right
|
||||||
else
|
else
|
||||||
raise "unimplemented #{@instruction.operator} #{@instruction}"
|
raise "unimplemented '#{@instruction.operator}' #{@instruction}"
|
||||||
end
|
end
|
||||||
puts "#{@instruction} == #{result}"
|
puts "#{@instruction} == #{result}"
|
||||||
right = set_register(rr , result)
|
right = set_register(rr , result)
|
||||||
|
@ -2,7 +2,7 @@ module Phisol
|
|||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
# if - attr_reader :cond, :if_true, :if_false
|
# if - attr_reader :cond, :if_true, :if_false
|
||||||
|
|
||||||
def on_if statement
|
def on_if_statement statement
|
||||||
condition , if_true , if_false = *statement
|
condition , if_true , if_false = *statement
|
||||||
condition = condition.first
|
condition = condition.first
|
||||||
# to execute the logic as the if states it, the blocks are the other way around
|
# to execute the logic as the if states it, the blocks are the other way around
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Phisol
|
module Phisol
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_operator statement
|
def on_operator_value statement
|
||||||
puts "operator #{statement.inspect}"
|
puts "operator #{statement.inspect}"
|
||||||
operator , left_e , right_e = *statement
|
operator , left_e , right_e = *statement
|
||||||
left_slot = process(left_e)
|
left_slot = process(left_e)
|
||||||
@ -22,7 +22,7 @@ module Phisol
|
|||||||
Virtual::Return.new(:int )
|
Virtual::Return.new(:int )
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_assign statement
|
def on_assignment statement
|
||||||
puts statement.inspect
|
puts statement.inspect
|
||||||
name , value = *statement
|
name , value = *statement
|
||||||
name = name.to_a.first
|
name = name.to_a.first
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Phisol
|
module Phisol
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_while statement
|
def on_while_statement statement
|
||||||
#puts statement.inspect
|
#puts statement.inspect
|
||||||
condition , statements = *statement
|
condition , statements = *statement
|
||||||
condition = condition.first
|
condition = condition.first
|
||||||
|
@ -50,7 +50,7 @@ HERE
|
|||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Integer < Object
|
class Integer < Object
|
||||||
int times(int x)
|
int times(int x)
|
||||||
self * x
|
return x
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
|
@ -5,13 +5,11 @@ class TestBasicClass < MiniTest::Test
|
|||||||
|
|
||||||
def test_class_basic
|
def test_class_basic
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
module Foo
|
|
||||||
class Bar
|
class Bar
|
||||||
int buh()
|
int buh()
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
HERE
|
HERE
|
||||||
@expect = [ Virtual::Return ]
|
@expect = [ Virtual::Return ]
|
||||||
check
|
check
|
||||||
|
@ -9,9 +9,9 @@ class Object
|
|||||||
int main()
|
int main()
|
||||||
int n = 10
|
int n = 10
|
||||||
if( n < 12)
|
if( n < 12)
|
||||||
3
|
return 3
|
||||||
else
|
else
|
||||||
4
|
return 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,8 @@ class Integer < Object
|
|||||||
int rest
|
int rest
|
||||||
rest = self - div
|
rest = self - div
|
||||||
if( rest < 0)
|
if( rest < 0)
|
||||||
str = str + digit( rest )
|
rest = self.digit( rest )
|
||||||
|
str = str + rest
|
||||||
else
|
else
|
||||||
str = div.add_string(str)
|
str = div.add_string(str)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user