update to new syntax and patch tests

basic semantics remain, but have to improve test for new functionality
that has to be written for new branch types
This commit is contained in:
Torsten Ruger 2015-10-19 15:31:48 +03:00
parent bdcd0f297d
commit 50379a1fea
8 changed files with 37 additions and 38 deletions

View File

@ -12,7 +12,7 @@ GIT
GIT GIT
remote: git://github.com/salama/salama-reader.git remote: git://github.com/salama/salama-reader.git
revision: ab0a94bd51c996637453331adeb28bf1731f9b65 revision: 6710567af979b0b367245c16a0c6af260675bc71
specs: specs:
salama-reader (0.4.0) salama-reader (0.4.0)
ast (~> 2.1.0) ast (~> 2.1.0)
@ -20,7 +20,7 @@ GIT
GIT GIT
remote: git://github.com/whitequark/ast.git remote: git://github.com/whitequark/ast.git
revision: 82e280fe0f9d528a581721d02d22d1fbf3755142 revision: 3814fb102af82a30bf334005ebe17332744f9dad
specs: specs:
ast (2.1.0) ast (2.1.0)

View File

@ -3,7 +3,7 @@ module Phisol
# if - attr_reader :cond, :if_true, :if_false # if - attr_reader :cond, :if_true, :if_false
def on_if_statement statement def on_if_statement statement
condition , if_true , if_false = *statement branch_type , 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
# so we can the jump over the else if true , # so we can the jump over the else if true ,

View File

@ -3,7 +3,7 @@ module Phisol
def on_while_statement statement def on_while_statement statement
#puts statement.inspect #puts statement.inspect
condition , statements = *statement branch_type , condition , statements = *statement
condition = condition.first condition = condition.first
# this is where the while ends and both branches meet # this is where the while ends and both branches meet

View File

@ -98,7 +98,7 @@ module Register
next if objekt.is_a? Parfait::BinaryCode next if objekt.is_a? Parfait::BinaryCode
write_any( objekt ) write_any( objekt )
end end
puts "Assembled #{stream_position} bytes" #puts "Assembled #{stream_position} bytes"
return @stream.string return @stream.string
end end

View File

@ -8,7 +8,7 @@ class TestIf < MiniTest::Test
class Object class Object
int main() int main()
int n = 10 int n = 10
if( n - 12) if_plus( n - 12)
return 3 return 3
else else
return 4 return 4
@ -25,7 +25,7 @@ HERE
class Object class Object
int main() int main()
int n = 10 int n = 10
if(8 - n ) if_minus(8 - n )
"10".putstring() "10".putstring()
end end
end end
@ -41,7 +41,7 @@ HERE
@string_input = <<HERE @string_input = <<HERE
class Object class Object
int itest(int n) int itest(int n)
if( n - 12) if_zero( n - 12)
"then".putstring() "then".putstring()
else else
"else".putstring() "else".putstring()

View File

@ -8,7 +8,7 @@ class TestIfStatement < MiniTest::Test
@string_input = <<HERE @string_input = <<HERE
class Object class Object
int main() int main()
if( 10 < 12) if_plus( 10 < 12)
return 3 return 3
else else
return 4 return 4
@ -28,7 +28,7 @@ HERE
@string_input = <<HERE @string_input = <<HERE
class Object class Object
int main() int main()
if( 10 < 12) if_minus( 10 < 12)
return 3 return 3
end end
end end

View File

@ -9,7 +9,7 @@ module Register
@string_input = <<HERE @string_input = <<HERE
class Object class Object
int main() int main()
while(1) while_plus(1)
return 3 return 3
end end
end end
@ -25,7 +25,7 @@ HERE
class Object class Object
int main() int main()
int n = 5 int n = 5
while(n > 0) while_minus(n > 0)
n = n - 1 n = n - 1
end end
end end
@ -43,7 +43,7 @@ HERE
class Object class Object
int main() int main()
int n = 10 int n = 10
while( n > 5) while_notzero( n > 5)
n = n + 1 n = n + 1
return n return n
end end

View File

@ -8,19 +8,19 @@ class AddTest < MiniTest::Test
@string_input = <<HERE @string_input = <<HERE
class Integer < Object class Integer < Object
Word digit( int rest ) Word digit( int rest )
if( rest == 5 ) if_zero( rest == 5 )
return "5" return "5"
end end
if( rest == 1 ) if_zero( rest == 1 )
return "1" return "1"
end end
if( rest == 2 ) if_zero( rest == 2 )
return "2" return "2"
end end
if( rest == 3 ) if_zero( rest == 3 )
return "3" return "3"
end end
if( rest == 4 ) if_zero( rest == 4 )
return "4" return "4"
end end
end end
@ -29,7 +29,7 @@ class Integer < Object
div = self / 10 div = self / 10
int rest int rest
rest = self - div rest = self - div
if( rest - 0) if_nonzero( rest )
rest = self.digit( rest ) rest = self.digit( rest )
str = str + rest str = str + rest
else else
@ -67,24 +67,23 @@ HERE
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot", "SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot", "LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot", "GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
"GetSlot","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch", "GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
"GetSlot","GetSlot","GetSlot","SetSlot","LoadConstant", "GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
"SetSlot","GetSlot","SetSlot","RegisterTransfer","FunctionCall", "SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"SaveReturn","GetSlot","LoadConstant","OperatorInstruction","GetSlot", "LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"SetSlot","GetSlot","GetSlot","GetSlot","OperatorInstruction", "GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
"GetSlot","SetSlot","GetSlot","GetSlot","LoadConstant", "GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
"OperatorInstruction","IsZeroBranch","GetSlot","GetSlot","GetSlot", "GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
"SetSlot","LoadConstant","SetSlot","GetSlot","SetSlot", "SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"RegisterTransfer","FunctionCall","SaveReturn","GetSlot","LoadConstant", "LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"OperatorInstruction","GetSlot","SetSlot","GetSlot","GetSlot", "GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
"GetSlot","OperatorInstruction","GetSlot","SetSlot","GetSlot", "GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
"GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch","GetSlot", "GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
"GetSlot","GetSlot","SetSlot","LoadConstant","SetSlot", "SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"GetSlot","SetSlot","RegisterTransfer","FunctionCall","SaveReturn", "LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"GetSlot","LoadConstant","OperatorInstruction","GetSlot","SetSlot", "GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
"GetSlot","GetSlot","GetSlot","OperatorInstruction","GetSlot", "GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
"SetSlot","GetSlot","GetSlot","LoadConstant","OperatorInstruction", "GetSlot"].each_with_index do |name , index|
"IsZeroBranch","GetSlot","GetSlot","GetSlot"].each_with_index do |name , index|
got = ticks(1) got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}" assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end end