Skip to content

Commit

Permalink
added support for interpolation in goto and jump
Browse files Browse the repository at this point in the history
  • Loading branch information
ajusa committed May 12, 2021
1 parent a8cc449 commit ef7bdba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions spec/vnds_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ describe "VNDS Interpreter Tests", ->
text run
')
assert.are.equals(ins[1].text, "run")
it "Label Interpolation", ->
i, ins = run_scr('
setvar RETLABEL = "hello"
goto $RETLABEL
text not run
label hello
text run
')
assert.are.equals(ins[1].text, "run")


--todo
--nested if statements
Expand Down
5 changes: 4 additions & 1 deletion src/script.moon
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ next_instruction = (s) ->
while count > 0
s.n += 1
count += ops[s.ins[s.n].type] or 0
when "goto" then s.n = s.labels[ins.label]
when "goto"
ins.label = interpolate(s, ins.label)
s.n = s.labels[ins.label]
when "jump" --see if I can reuse load here
if ins.label != nil then ins.label = interpolate(s, ins.label)
-- add string interpolation
ins.filename = interpolate(s, ins.filename)\gsub('{', '')\gsub('}', '')
s = _.extend(s, read_file(s, ins.filename))
Expand Down

0 comments on commit ef7bdba

Please sign in to comment.