Skip to content

Commit bb429a1

Browse files
committed
Fix for-range loop with non-default increment.
1 parent 42b8a2d commit bb429a1

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Compiler/Lua.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ compileStat = \case
396396
emit $ B.SetLit "$step" reg_step
397397

398398
-- var = var - step
399-
emit $ B.Sub reg_start reg_start reg_start
399+
emit $ B.Sub reg_start reg_start reg_step
400400
emit $ B.SetLit "$var" reg_start
401401

402402
-- while true

Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ processed :: [((String, Set String), Jass.Ast String Jass.Programm)]
161161
processed = map justProcess runtime
162162

163163
justProcess :: String -> ((String, Set String), Jass.Ast String Jass.Programm)
164-
justProcess = fromRight (error "justProcess") . CPre.process "lua_"
164+
justProcess = either (error . errorBundlePretty) id . CPre.process "lua_"
165165

166166
parseFromFile p file = runParser p file . (++"\n") <$> readFile file
167167

runtime/Ins.j

+19
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,22 @@ function _init takes nothing returns nothing
114114
set _Name[_Lambda] = "Lambda"
115115
set _Name[_Local] = "Local"
116116
endfunction
117+
118+
function _show takes integer ip returns string
119+
local integer ins = _ins[ip]
120+
local string s = _Name[ins] + " "
121+
122+
// ii
123+
if ins == _Call or ins == _Set or (ins >= _JumpT and ins <= _Complement) then
124+
set s = s + I2S(_op1[ins]) +" "+I2S(_op2[ins])
125+
elseif (ins >= _GTE and ins <= _BXor) or (ins >= _Append and ins <= _GetTable) then
126+
set s = s + I2S(_op1[ins]) +" "+I2S(_op2[ins]) +" "+I2S(_op3[ins])
127+
elseif ins == _SetLit then // si
128+
set s = s + _string[ins] +" "+I2S(_op1[ins])
129+
elseif ins == _GetLit or ins == _Lambda or ins == _LitString then // is
130+
set s = s + _string[ins] +" "+I2S(_op1[ins])
131+
else
132+
set s = s + "<...>"
133+
endif
134+
return s
135+
endfunction

runtime/Interpreter.j

+1-1
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ function _step takes integer interpreter returns boolean
886886
set Context#_ip[ctx] = Context#_ip[ctx] + 1
887887

888888
if Builtins#_trace then
889-
call Print#_print("Executing instruction ("+I2S(ip)+") "+ Ins#_Name[ins]+" ctx("+I2S(ctx)+")")
889+
call Print#_print("Executing instruction ("+I2S(ip)+") "+Ins#_show(ip) )
890890
endif
891891

892892
set _GlobalIns = ins

0 commit comments

Comments
 (0)