Skip to content

Commit

Permalink
IC: yet another embarrassing omission (#17743)
Browse files Browse the repository at this point in the history
* IC: yet another embarrassing omission

* VM: fewer hacks that kept IC from working
  • Loading branch information
Araq authored Apr 16, 2021
1 parent 201ac2b commit 8e474fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ const

defaultSize = -1
defaultAlignment = -1
defaultOffset = -1
defaultOffset* = -1

proc getPIdent*(a: PNode): PIdent {.inline.} =
## Returns underlying `PIdent` for `{nkSym, nkIdent}`, or `nil`.
Expand Down
3 changes: 2 additions & 1 deletion compiler/ic/ic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ proc symHeaderFromPacked(c: var PackedDecoder; g: var PackedModuleGraph;
kind: s.kind, magic: s.magic, flags: s.flags,
info: translateLineInfo(c, g, si, s.info),
options: s.options,
position: s.position,
position: if s.kind in {skForVar, skVar, skLet, skTemp}: 0 else: s.position,
offset: if s.kind in routineKinds: defaultOffset else: s.offset,
name: getIdent(c.cache, g[si].fromDisk.sh.strings[s.name])
)

Expand Down
3 changes: 3 additions & 0 deletions compiler/vmdef.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
## This module contains the type definitions for the new evaluation engine.
## An instruction is 1-3 int32s in memory, it is a register based VM.

import std / tables

import ast, idents, options, modulegraphs, lineinfos

type TInstrType* = uint64
Expand Down Expand Up @@ -266,6 +268,7 @@ type
profiler*: Profiler
templInstCounter*: ref int # gives every template instantiation a unique ID, needed here for getAst
vmstateDiff*: seq[(PSym, PNode)] # we remember the "diff" to global state here (feature for IC)
procToCodePos*: Table[int, int]

PStackFrame* = ref TStackFrame
TStackFrame* = object
Expand Down
14 changes: 6 additions & 8 deletions compiler/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# solves the opcLdConst vs opcAsgnConst issue. Of course whether we need
# this copy depends on the involved types.

import std / tables

import
strutils, ast, types, msgs, renderer, vmdef,
intsets, magicsys, options, lowerings, lineinfos, transf
Expand Down Expand Up @@ -2248,8 +2250,8 @@ proc optimizeJumps(c: PCtx; start: int) =
else: discard

proc genProc(c: PCtx; s: PSym): int =
var x = s.ast[miscPos]
if x.kind == nkEmpty or x[0].kind == nkEmpty:
let pos = c.procToCodePos.getOrDefault(s.id)
if pos == 0:
#if s.name.s == "outterMacro" or s.name.s == "innerProc":
# echo "GENERATING CODE FOR ", s.name.s
let last = c.code.len-1
Expand All @@ -2260,11 +2262,7 @@ proc genProc(c: PCtx; s: PSym): int =
c.debug.setLen(last)
#c.removeLastEof
result = c.code.len+1 # skip the jump instruction
if x.kind == nkEmpty:
x = newTree(nkBracket, newIntNode(nkIntLit, result), x)
else:
x[0] = newIntNode(nkIntLit, result)
s.ast[miscPos] = x
c.procToCodePos[s.id] = result
# thanks to the jmp we can add top level statements easily and also nest
# procs easily:
let body = transformBody(c.graph, c.idgen, s, cache = not isCompileTimeProc(s))
Expand Down Expand Up @@ -2297,4 +2295,4 @@ proc genProc(c: PCtx; s: PSym): int =
c.prc = oldPrc
else:
c.prc.maxSlots = s.offset
result = x[0].intVal.int
result = pos

0 comments on commit 8e474fb

Please sign in to comment.