removed blocks and moved to labels

somewhat easier to understand the code as a linked list
relatively painless change, considering
This commit is contained in:
Torsten Ruger
2015-10-23 21:27:36 +03:00
parent f1f56f0d4e
commit 57f37ec023
22 changed files with 281 additions and 370 deletions

View File

@ -9,16 +9,20 @@ module Statements
machine.parse_and_compile @string_input
produced = Register.machine.space.get_main.source
assert @expect , "No output given"
assert_equal @expect.length , produced.blocks.length , "Block length"
produced.blocks.each_with_index do |b,i|
codes = @expect[i]
assert codes , "No codes for block #{i}"
assert_equal b.codes.length , codes.length , "Code length for block #{i+1}"
b.codes.each_with_index do |c , ii |
assert_equal codes[ii] , c.class , "Block #{i+1} , code #{ii+1}"
end
end
produced.blocks
#assert_equal @expect.length , produced.instructions.length , "instructions length #{produced.instructions.to_ac}"
compare_instructions produced.instructions , @expect
produced.instructions
end
def compare_instructions instruction , expect
index = 0
begin
should = expect[index]
assert should , "No instruction at #{index}"
assert_equal instruction.class , should , "Expected at #{index+1}"
index += 1
instruction = instruction.next
end while( instruction )
end

View File

@ -16,8 +16,8 @@ int main()
end
end
HERE
@expect = [[SaveReturn,LoadConstant,LoadConstant,
OperatorInstruction,GetSlot,SetSlot],[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,LoadConstant,OperatorInstruction,GetSlot,SetSlot,
Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -30,7 +30,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -42,7 +42,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant, GetSlot,SetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -54,8 +54,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
RegisterTransfer,FunctionCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
RegisterTransfer,FunctionCall,GetSlot,GetSlot,SetSlot ,
Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -68,10 +69,10 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,
Label,RegisterTransfer,GetSlot,FunctionReturn]
was = check
get = was[0].codes[5]
get = was.next(6)
assert_equal GetSlot , get.class
assert_equal 3, get.index , "Get to frame index must be offset, not #{get.index}"
end
@ -85,9 +86,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,SetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
was = check
set = was[0].codes[2]
set = was.next(3)
assert_equal SetSlot , set.class
assert_equal 9, set.index , "Set to args index must be offset, not #{set.index}"
end
@ -100,9 +101,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
was = check
set = was[0].codes[3]
set = was.next(4)
assert_equal SetSlot , set.class
assert_equal 3, set.index , "Set to frame index must be offset, not #{set.index}"
end
@ -117,10 +118,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot , Label , RegisterTransfer,GetSlot,FunctionReturn]
was = check
get = was[0].codes[1]
get = was.next(2)
assert_equal GetSlot , get.class
assert_equal 9, get.index , "Get to frame index must be offset, not #{get.index}"
end

View File

@ -17,9 +17,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot ,
Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -37,9 +37,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot ,
Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -57,9 +57,9 @@ class Object
end
end
HERE
@expect = [ [SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,
@expect = [ Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -77,9 +77,9 @@ class Object
end
end
HERE
@expect = [ [SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot,
@expect = [ Label, SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot,
LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -94,11 +94,11 @@ int main()
end
end
HERE
@expect = [ [SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
SetSlot,RegisterTransfer,FunctionCall,GetSlot],
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [ Label, SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
SetSlot,RegisterTransfer,FunctionCall,GetSlot,
Label,RegisterTransfer,GetSlot,FunctionReturn]
was = check
set = was[0].codes[7]
set = was.next(8)
assert_equal SetSlot , set.class
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
end

View File

@ -16,10 +16,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,LoadConstant,
OperatorInstruction,IsPlus] ,
[LoadConstant,Branch] ,[LoadConstant] ,[] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,Branch , Label , LoadConstant ,
Label,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -34,10 +33,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,LoadConstant,
OperatorInstruction,IsMinus] ,
[Branch] ,[LoadConstant] ,[] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsMinus ,
Branch ,Label , LoadConstant ,
Label,Label , RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -52,10 +50,9 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,LoadConstant,
OperatorInstruction,IsZero] ,
[Branch] ,[LoadConstant] ,[] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,
Label,Label, RegisterTransfer,GetSlot,FunctionReturn]
check
end
end

View File

@ -13,7 +13,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -26,7 +26,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -39,8 +39,8 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,
Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -53,7 +53,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -65,8 +65,8 @@ class Object
end
end
HERE
@expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,
SetSlot,RegisterTransfer,FunctionCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,
SetSlot,RegisterTransfer,FunctionCall,GetSlot ,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
end

View File

@ -15,8 +15,8 @@ class Object
end
end
HERE
@expect = [[SaveReturn],[LoadConstant,IsPlus,LoadConstant,Branch],
[],[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,Label,LoadConstant,IsPlus,LoadConstant,Branch,
Label,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -28,12 +28,13 @@ class Object
while_plus(n)
n = n - 1
end
return n
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot, IsPlus,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch],
[],[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,GetSlot,GetSlot, IsPlus,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch,
Label,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end
@ -50,11 +51,11 @@ class Object
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsPlus,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
GetSlot,Branch] ,
[],[RegisterTransfer,GetSlot,FunctionReturn]]
@expect = [Label, SaveReturn,LoadConstant,GetSlot,SetSlot,Label,
GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsPlus,
GetSlot, GetSlot,LoadConstant,OperatorInstruction, GetSlot,
SetSlot,GetSlot, GetSlot,Branch , Label ,
Label , RegisterTransfer,GetSlot,FunctionReturn]
check
end
end