Skip to content

Commit

Permalink
rename useFFI=>nimHasLibFFI; improve formatting rawExecute traceCode
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 12, 2019
1 parent 54e836e commit aacaac9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bootSwitch(usedTinyC, hasTinyCBackend, "-d:tinyc")
bootSwitch(usedNativeStacktrace,
defined(nativeStackTrace) and nativeStackTraceSupported,
"-d:nativeStackTrace")
bootSwitch(usedFFI, hasFFI, "-d:useFFI")
bootSwitch(usedFFI, hasFFI, "-d:nimHasLibFFI")

type
TCmdLinePass* = enum
Expand Down
2 changes: 1 addition & 1 deletion compiler/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ when not defined(leanCompiler):
proc interactivePasses(graph: ModuleGraph) =
initDefines(graph.config.symbols)
defineSymbol(graph.config.symbols, "nimscript")
# note: seems redundant with -d:useFFI
# note: seems redundant with -d:nimHasLibFFI
when hasFFI: defineSymbol(graph.config.symbols, "nimffi")
registerPass(graph, verbosePass)
registerPass(graph, semPass)
Expand Down
4 changes: 2 additions & 2 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const
hasTinyCBackend* = defined(tinyc)
useEffectSystem* = true
useWriteTracking* = false
hasFFI* = defined(useFFI)
hasFFI* = defined(nimHasLibFFI)
copyrightYear* = "2018"

type # please make sure we have under 32 options
Expand Down Expand Up @@ -129,7 +129,7 @@ type
caseStmtMacros,
codeReordering,
compiletimeFFI,
## This requires building nim with `-d:useFFI`
## This requires building nim with `-d:nimHasLibFFI`
## which itself requires `nimble install libffi`, see #10150
## Note: this feature can't be localized with {.push.}

Expand Down
34 changes: 12 additions & 22 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,6 @@ const
"compiler/vmdef.MaxLoopIterations and rebuild the compiler"
errFieldXNotFound = "node lacks field: "

import strformat

proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
var pc = start
var tos = tos
Expand All @@ -500,14 +498,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let ra = instr.regA

when traceCode:
# echo "PC ", pc, " ", c.code[pc].opcode, " ra ", ra, " rb ", instr.regB, " rc ", instr.regC
let rb = instr.regB
let rbk = if rb<regs.len: $regs[rb].kind else: ""
let rc = instr.regC
let rck = if rc<regs.len: $regs[rc].kind else: ""
echo fmt"""PC:{pc} opcode:{c.code[pc].opcode} ra:{ra},{regs[ra].kind} rb:{rb},{rbk} rc:{rc},{rck}"""
# echo "PC ", pc, " ", c.code[pc].opcode, " ra ", ra, " "," rb ", instr.regB, " rc ", instr.regC
# message(c.config, c.debug[pc], warnUser, "Trace")
template regDescr(name, r): string =
let kind = if r < regs.len: $regs[r].kind else: ""
let ret = name & ": " & $r & " " & $kind
alignLeft(ret, 15)
echo "PC:$pc $opcode $ra $rb $rc" % [
"pc", $pc, "opcode", alignLeft($c.code[pc].opcode, 15),
"ra", regDescr("ra", ra), "rb", regDescr("rb", instr.regB),
"rc", regDescr("rc", instr.regC)]

case instr.opcode
of opcEof: return regs[ra]
Expand Down Expand Up @@ -1650,20 +1648,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let srctyp = c.types[c.code[pc].regBx - wordExcess]

when hasFFI:
# let dest = fficast(c.config, regs[rb].node, desttyp)
# echo (k:regs[rb].kind)
echo (msg:"D20190211T154842", k: regs[rb].kind)
let dest = fficast(
c.config,
regs[rb].node,
desttyp)
let dest = fficast(c.config, regs[rb].node, desttyp)
# todo: check whether this is correct
# asgnRef(regs[ra], dest)
putIntoReg(regs[ra], dest)
else:
# globalError(c.config, c.debug[pc], "cannot evaluate cast")
globalError(
c.config,
c.debug[pc],
"cannot evaluate cast")
globalError(c.config, c.debug[pc], "cannot evaluate cast")
of opcNSetIntVal:
decodeB(rkNode)
var dest = regs[ra].node
Expand Down
6 changes: 3 additions & 3 deletions koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,16 @@ proc runCI(cmd: string) =
# note(@araq): Do not replace these commands with direct calls (eg boot())
# as that would weaken our testing efforts.

# boot without -d:useFFI to make sure this still works
# boot without -d:nimHasLibFFI to make sure this still works
kochExecFold("Boot in release mode", "boot -d:release")

# steps to boot with -d:useFFI
# steps to boot with -d:nimHasLibFFI
kochExecFold("Build Nimble", "nimble")
execFold("nimble install libffi", "nimble install -y libffi")

when defined(posix): # appveyor (on windows) didn't run this
kochExecFold("Boot", "boot")
kochExecFold("boot -d:release -d:useFFI", "boot -d:release -d:useFFI")
kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI")

if getEnv("NIM_TEST_PACKAGES", "false") == "true":
execFold("Test selected Nimble packages", "nim c -r testament/tester cat nimble-extra")
Expand Down

0 comments on commit aacaac9

Please sign in to comment.