fix the if syntax and branches
This commit is contained in:
@ -25,7 +25,7 @@ HERE
|
||||
class Object
|
||||
int main()
|
||||
int n = 10
|
||||
if_minus(8 - n )
|
||||
if_zero(8 - n )
|
||||
"10".putstring()
|
||||
end
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ class TestIfStatement < MiniTest::Test
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
if_plus( 10 < 12)
|
||||
if_plus( 10 - 12)
|
||||
return 3
|
||||
else
|
||||
return 4
|
||||
@ -17,18 +17,36 @@ class Object
|
||||
end
|
||||
HERE
|
||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||
OperatorInstruction,IsZero] ,
|
||||
OperatorInstruction,IsPlus] ,
|
||||
[LoadConstant,Branch] ,[LoadConstant] ,[] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
|
||||
def test_if_small
|
||||
def test_if_small_minus
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
if_minus( 10 < 12)
|
||||
if_minus( 10 - 12)
|
||||
return 3
|
||||
end
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||
OperatorInstruction,IsMinus] ,
|
||||
[Branch] ,[LoadConstant] ,[] ,
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
|
||||
def test_if_small_zero
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
if_zero( 10 - 12)
|
||||
return 3
|
||||
end
|
||||
end
|
||||
@ -40,24 +58,5 @@ HERE
|
||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
|
||||
def ttest_call_function
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int itest(int n)
|
||||
return 4
|
||||
end
|
||||
|
||||
int main()
|
||||
itest(20)
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@expect = [ [SaveReturn,GetSlot,SetSlot,LoadConstant,
|
||||
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
|
||||
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
||||
check
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -29,7 +29,7 @@ class Integer < Object
|
||||
div = self / 10
|
||||
int rest
|
||||
rest = self - div
|
||||
if_nonzero( rest )
|
||||
if_notzero( rest )
|
||||
rest = self.digit( rest )
|
||||
str = str + rest
|
||||
else
|
||||
@ -58,7 +58,7 @@ HERE
|
||||
# Phisol::Compiler.compile( statements , Virtual.machine.space.get_main )
|
||||
@interpreter = Interpreter::Interpreter.new
|
||||
@interpreter.start Virtual.machine.init
|
||||
#show_ticks # get output of what is
|
||||
# show_ticks # get output of what is
|
||||
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
||||
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
||||
@ -67,23 +67,14 @@ HERE
|
||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
||||
"GetSlot","GetSlot","IsNotzero","GetSlot","GetSlot",
|
||||
"SetSlot","LoadConstant","SetSlot","GetSlot","GetSlot",
|
||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||
"GetSlot"].each_with_index do |name , index|
|
||||
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
|
||||
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","NilClass"].each_with_index do |name , index|
|
||||
got = ticks(1)
|
||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||
end
|
||||
|
Reference in New Issue
Block a user