bugfix
This commit is contained in:
parent
f665efaeed
commit
2651cf3cbd
11
compiler.nim
11
compiler.nim
|
@ -240,6 +240,7 @@ proc beginScope(comp: Compiler, function: bool = false) =
|
|||
|
||||
if function:
|
||||
scope.labels.add("result")
|
||||
scope.labels.add("function")
|
||||
else:
|
||||
while comp.match(tkLabel):
|
||||
let label = comp.previous.text[1..^1]
|
||||
|
@ -270,7 +271,6 @@ proc restore(comp: Compiler, scope: Scope) =
|
|||
debugEcho &"Restored scope: delta {delta}"
|
||||
|
||||
proc restoreInFunct(comp: Compiler, scope: Scope) =
|
||||
|
||||
let pops = comp.stackIndex
|
||||
comp.writePops(pops)
|
||||
|
||||
|
@ -279,9 +279,14 @@ proc restoreInFunct(comp: Compiler, scope: Scope) =
|
|||
debugEcho &"Restored function scope: delta {pops}; new stackindex: {comp.stackIndex}"
|
||||
|
||||
proc jumpToEnd(comp: Compiler, scope: Scope) =
|
||||
let delta = comp.stackIndex - scope.goalStackIndex
|
||||
## Jumps to the end of scope, does not affect stackIndex
|
||||
var delta: int
|
||||
if scope.function:
|
||||
delta = comp.stackIndex
|
||||
else:
|
||||
delta = comp.stackIndex - scope.goalStackIndex
|
||||
comp.writePops(delta)
|
||||
let jmp = comp.emitJump(0, opJump)
|
||||
let jmp = comp.emitJump(delta, opJump)
|
||||
scope.jumps.add(jmp)
|
||||
|
||||
proc endScope(comp: Compiler) =
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
print "expect: inner douter";
|
||||
{ @outer
|
||||
{ @middle
|
||||
{ @inner
|
||||
print "inner";
|
||||
break @middle;
|
||||
};
|
||||
print "middle";
|
||||
};
|
||||
print "outer";
|
||||
};
|
||||
|
||||
print "expect: inner middle outer";
|
||||
{ @outer
|
||||
{ @middle
|
||||
{ @inner
|
||||
print "inner";
|
||||
break @inner;
|
||||
};
|
||||
print "middle";
|
||||
};
|
||||
print "outer";
|
||||
};
|
||||
|
||||
print "expect: nothing";
|
||||
{ @outer
|
||||
{ @middle
|
||||
{ @inner
|
||||
{
|
||||
break @outer;
|
||||
};
|
||||
print "inner";
|
||||
};
|
||||
print "middle";
|
||||
};
|
||||
print "outer";
|
||||
};
|
|
@ -19,7 +19,7 @@ proc newString*(str: string): NdString =
|
|||
if interned != nil:
|
||||
return interned
|
||||
|
||||
let len = 4 + strlen
|
||||
let len = 8 + strlen
|
||||
result = cast[NdString](alloc(len))
|
||||
result.len = strlen.uint32
|
||||
result.hash = hash.uint32
|
||||
|
|
Loading…
Reference in New Issue