Skip to content

Commit

Permalink
Updated to use jump positions instead of index
Browse files Browse the repository at this point in the history
  • Loading branch information
Nafees10 committed Jan 19, 2020
1 parent fa2826b commit e30666e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/array
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def 8 # 8 is just made up, I'm just assuming it doesn't need more than 8.
pop

# fill it with 0,1,2,3,4 - use element at stack[1] as counter
jumpBackToHere:
pushFrom 1 # this one is value for writeTo
pushFrom 1 # this one is index for arrayRefElement
pushRefFrom 0 # and this is ref to array for arrayRefElement
Expand All @@ -29,7 +30,7 @@ def 8 # 8 is just made up, I'm just assuming it doesn't need more than 8.
pushFrom 1
push 5
isGreaterInt
JumpIf 12 # remember, lines that are comments don't count, so it needs to jump to instruction index 12, not line 12
JumpIf jumpBackToHere

# now write it's contents, lets just use a function for that
pushFrom 0
Expand All @@ -43,6 +44,7 @@ def 8 # again, it **probably** doesn't need more than 8
pushFrom 0
arrayLength # this puts array length at stack[2]

jumpBackPosition:
pushFrom 1
pushFrom 0
arrayElement
Expand All @@ -58,5 +60,5 @@ def 8 # again, it **probably** doesn't need more than 8
pushFrom 1
pushFrom 2
isGreaterInt
jumpIf 3
jumpIf jumpBackPosition
terminate

0 comments on commit e30666e

Please sign in to comment.