From 88a441ea8ea25f7a298a1279e0fb89274e2c544d Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 2 Jan 2013 01:17:53 +0100 Subject: next steps for FFI at compile time --- compiler/evals.nim | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'compiler/evals.nim') diff --git a/compiler/evals.nim b/compiler/evals.nim index f0a09fff3..5623f7955 100755 --- a/compiler/evals.nim +++ b/compiler/evals.nim @@ -77,6 +77,7 @@ proc newEvalContext*(module: PSym, filename: string, new(result) result.module = module result.mode = mode + result.features = {allowFFI} initIdNodeTable(result.globals) proc pushStackFrame*(c: PEvalContext, t: PStackFrame) {.inline.} = @@ -90,7 +91,7 @@ proc popStackFrame*(c: PEvalContext) {.inline.} = proc evalMacroCall*(c: PEvalContext, n, nOrig: PNode, sym: PSym): PNode proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode -proc raiseCannotEval(c: PEvalContext, info: TLineInfo): PNode = +proc raiseCannotEval(c: PEvalContext, info: TLineInfo): PNode = result = newNodeI(nkExceptBranch, info) # creating a nkExceptBranch without sons # means that it could not be evaluated @@ -351,7 +352,7 @@ proc evalGlobalVar(c: PEvalContext, s: PSym, flags: TEvalFlags): PNode = result = copyTree(result) else: when hasFFI: - if sfImportc in s.flags: + if sfImportc in s.flags and allowFFI in c.features: result = importcSymbol(s) IdNodeTablePut(c.globals, s, result) return result @@ -398,7 +399,7 @@ proc evalCall(c: PEvalContext, n: PNode): PNode = if n.typ != nil: d.params[0] = getNullValue(n.typ, n.info) when hasFFI: - if sfImportc in prc.sym.flags: + if sfImportc in prc.sym.flags and allowFFI in c.features: var newCall = newNodeI(nkCall, n.info, n.len) newCall.sons[0] = evalGlobalVar(c, prc.sym, {}) for i in 1 .. = 1: stackTrace(c, n, errUnhandledExceptionX, typeToString(result.typ)) else: - stackTrace(c, n, errCannotInterpretNodeX, renderTree(n)) + stackTrace(c, result, errCannotInterpretNodeX, renderTree(n)) proc evalConstExprAux(module: PSym, e: PNode, mode: TEvalMode): PNode = var p = newEvalContext(module, "", mode) @@ -1474,6 +1480,7 @@ proc evalMacroCall(c: PEvalContext, n, nOrig: PNode, sym: PSym): PNode = proc myOpen(module: PSym, filename: string): PPassContext = var c = newEvalContext(module, filename, emRepl) + c.features = {allowCast, allowFFI, allowInfiniteLoops} pushStackFrame(c, newStackFrame()) result = c -- cgit 1.4.1-2-gfad0