fixes regression: constant fac4 didn't work
This commit is contained in:
parent
cc0a32ae87
commit
3be07d842a
4 changed files with 26 additions and 11 deletions
|
|
@ -35,6 +35,7 @@ type
|
||||||
lex*: TLexer # the lexer that is used for parsing
|
lex*: TLexer # the lexer that is used for parsing
|
||||||
tok*: TToken # the current token
|
tok*: TToken # the current token
|
||||||
inPragma: int
|
inPragma: int
|
||||||
|
inSemiStmtList: int
|
||||||
|
|
||||||
proc parseAll*(p: var TParser): PNode
|
proc parseAll*(p: var TParser): PNode
|
||||||
proc openParser*(p: var TParser, filename: string, inputstream: PLLStream)
|
proc openParser*(p: var TParser, filename: string, inputstream: PLLStream)
|
||||||
|
|
@ -455,11 +456,13 @@ proc complexOrSimpleStmt(p: var TParser): PNode
|
||||||
proc simpleExpr(p: var TParser, mode = pmNormal): PNode
|
proc simpleExpr(p: var TParser, mode = pmNormal): PNode
|
||||||
|
|
||||||
proc semiStmtList(p: var TParser, result: PNode) =
|
proc semiStmtList(p: var TParser, result: PNode) =
|
||||||
|
inc p.inSemiStmtList
|
||||||
result.add(complexOrSimpleStmt(p))
|
result.add(complexOrSimpleStmt(p))
|
||||||
while p.tok.tokType == tkSemiColon:
|
while p.tok.tokType == tkSemiColon:
|
||||||
getTok(p)
|
getTok(p)
|
||||||
optInd(p, result)
|
optInd(p, result)
|
||||||
result.add(complexOrSimpleStmt(p))
|
result.add(complexOrSimpleStmt(p))
|
||||||
|
dec p.inSemiStmtList
|
||||||
result.kind = nkStmtListExpr
|
result.kind = nkStmtListExpr
|
||||||
|
|
||||||
proc parsePar(p: var TParser): PNode =
|
proc parsePar(p: var TParser): PNode =
|
||||||
|
|
@ -1880,6 +1883,10 @@ proc parseStmt(p: var TParser): PNode =
|
||||||
tkMacro, tkType, tkConst, tkWhen, tkVar:
|
tkMacro, tkType, tkConst, tkWhen, tkVar:
|
||||||
parMessage(p, errComplexStmtRequiresInd)
|
parMessage(p, errComplexStmtRequiresInd)
|
||||||
result = ast.emptyNode
|
result = ast.emptyNode
|
||||||
|
else:
|
||||||
|
if p.inSemiStmtList > 0:
|
||||||
|
result = simpleStmt(p)
|
||||||
|
if result.kind == nkEmpty: parMessage(p, errExprExpected, p.tok)
|
||||||
else:
|
else:
|
||||||
result = newNodeP(nkStmtList, p)
|
result = newNodeP(nkStmtList, p)
|
||||||
while true:
|
while true:
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import ast except getstr
|
||||||
|
|
||||||
import
|
import
|
||||||
strutils, astalgo, msgs, vmdef, vmgen, nimsets, types, passes, unsigned,
|
strutils, astalgo, msgs, vmdef, vmgen, nimsets, types, passes, unsigned,
|
||||||
parser, vmdeps, idents, trees, renderer, options
|
parser, vmdeps, idents, trees, renderer, options, transf
|
||||||
|
|
||||||
from semfold import leValueConv, ordinalValToString
|
from semfold import leValueConv, ordinalValToString
|
||||||
from evaltempl import evalTemplate
|
from evaltempl import evalTemplate
|
||||||
|
|
@ -1078,6 +1078,7 @@ proc execute(c: PCtx, start: int): PNode =
|
||||||
result = rawExecute(c, start, tos)
|
result = rawExecute(c, start, tos)
|
||||||
|
|
||||||
proc evalStmt*(c: PCtx, n: PNode) =
|
proc evalStmt*(c: PCtx, n: PNode) =
|
||||||
|
let n = transformExpr(c.module, n)
|
||||||
let start = genStmt(c, n)
|
let start = genStmt(c, n)
|
||||||
# execute new instructions; this redundant opcEof check saves us lots
|
# execute new instructions; this redundant opcEof check saves us lots
|
||||||
# of allocations in 'execute':
|
# of allocations in 'execute':
|
||||||
|
|
@ -1085,6 +1086,7 @@ proc evalStmt*(c: PCtx, n: PNode) =
|
||||||
discard execute(c, start)
|
discard execute(c, start)
|
||||||
|
|
||||||
proc evalExpr*(c: PCtx, n: PNode): PNode =
|
proc evalExpr*(c: PCtx, n: PNode): PNode =
|
||||||
|
let n = transformExpr(c.module, n)
|
||||||
let start = genExpr(c, n)
|
let start = genExpr(c, n)
|
||||||
assert c.code[start].opcode != opcEof
|
assert c.code[start].opcode != opcEof
|
||||||
result = execute(c, start)
|
result = execute(c, start)
|
||||||
|
|
@ -1127,6 +1129,7 @@ proc myProcess(c: PPassContext, n: PNode): PNode =
|
||||||
const evalPass* = makePass(myOpen, nil, myProcess, myProcess)
|
const evalPass* = makePass(myOpen, nil, myProcess, myProcess)
|
||||||
|
|
||||||
proc evalConstExprAux(module, prc: PSym, n: PNode, mode: TEvalMode): PNode =
|
proc evalConstExprAux(module, prc: PSym, n: PNode, mode: TEvalMode): PNode =
|
||||||
|
let n = transformExpr(module, n)
|
||||||
setupGlobalCtx(module)
|
setupGlobalCtx(module)
|
||||||
var c = globalCtx
|
var c = globalCtx
|
||||||
c.mode = mode
|
c.mode = mode
|
||||||
|
|
|
||||||
|
|
@ -1033,7 +1033,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
if s.isGlobal:
|
if s.isGlobal:
|
||||||
if sfCompileTime in s.flags or c.mode == emRepl:
|
if sfCompileTime in s.flags or c.mode == emRepl:
|
||||||
discard
|
discard
|
||||||
else:
|
elif s.position == 0:
|
||||||
cannotEval(n)
|
cannotEval(n)
|
||||||
if s.position == 0:
|
if s.position == 0:
|
||||||
if sfImportc in s.flags: c.importcSym(n.info, s)
|
if sfImportc in s.flags: c.importcSym(n.info, s)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''(bar: bar)
|
output: '''24
|
||||||
|
(bar: bar)
|
||||||
1244
|
1244
|
||||||
6
|
6
|
||||||
abcdefghijklmnopqrstuvwxyz
|
abcdefghijklmnopqrstuvwxyz
|
||||||
|
|
@ -8,6 +9,10 @@ abcdefghijklmnopqrstuvwxyz
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
|
const fac4 = (var x = 1; for i in 1..4: x *= i; x)
|
||||||
|
|
||||||
|
echo fac4
|
||||||
|
|
||||||
when true:
|
when true:
|
||||||
proc test(foo: proc (x, y: int): bool) =
|
proc test(foo: proc (x, y: int): bool) =
|
||||||
echo foo(5, 5)
|
echo foo(5, 5)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue