Skip to content

Commit

Permalink
adapt some codegen symbols for now, still need proper mangling for ev…
Browse files Browse the repository at this point in the history
…ery other symbol
  • Loading branch information
metagn committed Nov 28, 2024
1 parent 911d843 commit 58407e5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion compiler/cbuilderdecls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ when buildNifc:
if key in m.arrayTypes:
result = m.arrayTypes[key]
else:
result = cEscape(elementType) & "_Arr_" & $len
let tmp = getTempName(m)
result = tmp & "_Arr_" & $len
m.s[cfsTypes].add("(type :")
m.s[cfsTypes].add(result)
m.s[cfsTypes].add(" . (array ")
Expand Down
2 changes: 1 addition & 1 deletion compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ proc genOfHelper(p: BProc; dest: PType; a: Rope; info: TLineInfo; result: var Bu
p.module.s[cfsVars].addArrayVar(p.module,
kind = Global,
name = cache,
elementType = ptrType("TNimType"),
elementType = ptrType(cgsymValue(p.module, "TNimType")),
len = 2)
result.addCall(cgsymValue(p.module, "isObjWithCache"),
dotField(a, "m_type"),
Expand Down
2 changes: 1 addition & 1 deletion compiler/ccgliterals.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ proc genStringLiteralV2(m: BModule; n: PNode; isConst: bool; result: var Builder
res.addVarWithInitializer(
if isConst: AlwaysConst else: Global,
name = tmp,
typ = "NimStringV2"):
typ = cgsymValue(m, "NimStringV2")):
var strInit: StructInitializer
res.addStructInitializer(strInit, kind = siOrderedStruct):
res.addField(strInit, name = "len"):
Expand Down
26 changes: 13 additions & 13 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ proc getSimpleTypeDesc(m: BModule; typ: PType): Rope =
of 2:
cgsym(m, "NimStrPayload")
cgsym(m, "NimStringV2")
result = typeNameOrLiteral(m, typ, "NimStringV2")
result = typeNameOrLiteral(m, typ, cgsymValue(m, "NimStringV2"))
else:
cgsym(m, "NimStringDesc")
result = typeNameOrLiteral(m, typ, "NimStringDesc*")
result = typeNameOrLiteral(m, typ, ptrType(cgsymValue(m, "NimStringDesc")))
of tyCstring: result = typeNameOrLiteral(m, typ, NimCstring)
of tyBool: result = typeNameOrLiteral(m, typ, NimBool)
of tyChar: result = typeNameOrLiteral(m, typ, NimChar)
Expand Down Expand Up @@ -1313,7 +1313,7 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType;
m.s[cfsTypeInit3].addAssignment("nimTypeRoot", cAddr(nameHcr))

if m.hcrOn:
m.s[cfsStrData].addVar(kind = Global, name = name, typ = ptrType("TNimType"))
m.s[cfsStrData].addVar(kind = Global, name = name, typ = ptrType(cgsymValue(m, "TNimType")))
m.hcrCreateTypeInfosProc.add('\t')
var registerHcr: CallBuilder
m.hcrCreateTypeInfosProc.addStmt():
Expand All @@ -1323,15 +1323,15 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType;
m.hcrCreateTypeInfosProc.addArgument(registerHcr):
m.hcrCreateTypeInfosProc.add(makeCString(name))
m.hcrCreateTypeInfosProc.addArgument(registerHcr):
m.hcrCreateTypeInfosProc.addSizeof("TNimType")
m.hcrCreateTypeInfosProc.addSizeof(cgsymValue(m, "TNimType"))
m.hcrCreateTypeInfosProc.addArgument(registerHcr):
m.hcrCreateTypeInfosProc.add(CNil)
m.hcrCreateTypeInfosProc.addArgument(registerHcr):
m.hcrCreateTypeInfosProc.addCast(typ = ptrType(CPointer)):
m.hcrCreateTypeInfosProc.add(cAddr(name))
else:
m.s[cfsStrData].addDeclWithVisibility(Private):
m.s[cfsStrData].addVar(kind = Local, name = name, typ = "TNimType")
m.s[cfsStrData].addVar(kind = Local, name = name, typ = cgsymValue(m, "TNimType"))

proc genTypeInfoAux(m: BModule; typ, origType: PType, name: Rope;
info: TLineInfo) =
Expand Down Expand Up @@ -1751,7 +1751,7 @@ proc genVTable(result: var Builder, seqs: seq[PSym]) =
proc genTypeInfoV2OldImpl(m: BModule; t, origType: PType, name: Rope; info: TLineInfo) =
cgsym(m, "TNimTypeV2")
m.s[cfsStrData].addDeclWithVisibility(Private):
m.s[cfsStrData].addVar(kind = Local, name = name, typ = "TNimTypeV2")
m.s[cfsStrData].addVar(kind = Local, name = name, typ = cgsymValue(m, "TNimTypeV2"))

var flags = 0
if not canFormAcycle(m.g.graph, t): flags = flags or 1
Expand Down Expand Up @@ -1817,14 +1817,14 @@ proc genTypeInfoV2OldImpl(m: BModule; t, origType: PType, name: Rope; info: TLin
proc genTypeInfoV2Impl(m: BModule; t, origType: PType, name: Rope; info: TLineInfo) =
cgsym(m, "TNimTypeV2")
m.s[cfsStrData].addDeclWithVisibility(Private):
m.s[cfsStrData].addVar(kind = Local, name = name, typ = "TNimTypeV2")
m.s[cfsStrData].addVar(kind = Local, name = name, typ = cgsymValue(m, "TNimTypeV2"))

var flags = 0
if not canFormAcycle(m.g.graph, t): flags = flags or 1

var typeEntry = newBuilder("")
typeEntry.addDeclWithVisibility(Private):
typeEntry.addVarWithInitializer(kind = Local, name = name, typ = "TNimTypeV2"):
typeEntry.addVarWithInitializer(kind = Local, name = name, typ = cgsymValue(m, "TNimTypeV2")):
var typeInit: StructInitializer
typeEntry.addStructInitializer(typeInit, kind = siNamedStruct):
typeEntry.addField(typeInit, name = "destructor"):
Expand Down Expand Up @@ -1903,7 +1903,7 @@ proc genTypeInfoV2(m: BModule; t: PType; info: TLineInfo): Rope =
let marker = m.g.typeInfoMarkerV2.getOrDefault(sig)
if marker.str != "":
cgsym(m, "TNimTypeV2")
declareNimType(m, "TNimTypeV2", marker.str, marker.owner)
declareNimType(m, cgsymValue(m, "TNimTypeV2"), marker.str, marker.owner)
# also store in local type section:
m.typeInfoMarkerV2[sig] = marker.str
return prefixTI(marker.str)
Expand All @@ -1917,7 +1917,7 @@ proc genTypeInfoV2(m: BModule; t: PType; info: TLineInfo): Rope =
discard genTypeInfoV2(m.g.modules[owner], origType, info)
# reference the type info as extern here
cgsym(m, "TNimTypeV2")
declareNimType(m, "TNimTypeV2", result, owner)
declareNimType(m, cgsymValue(m, "TNimTypeV2"), result, owner)
return prefixTI(result)

m.g.typeInfoMarkerV2[sig] = (str: result, owner: owner)
Expand Down Expand Up @@ -1981,7 +1981,7 @@ proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope =
if marker.str != "":
cgsym(m, "TNimType")
cgsym(m, "TNimNode")
declareNimType(m, "TNimType", marker.str, marker.owner)
declareNimType(m, cgsymValue(m, "TNimType"), marker.str, marker.owner)
# also store in local type section:
m.typeInfoMarker[sig] = marker.str
return prefixTI(marker.str)
Expand All @@ -1993,7 +1993,7 @@ proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope =
if old != FileIndex(0):
cgsym(m, "TNimType")
cgsym(m, "TNimNode")
declareNimType(m, "TNimType", result, old.int)
declareNimType(m, cgsymValue(m, "TNimType"), result, old.int)
return prefixTI(result)

var owner = t.skipTypes(typedescPtrs).itemId.module
Expand All @@ -2003,7 +2003,7 @@ proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope =
# reference the type info as extern here
cgsym(m, "TNimType")
cgsym(m, "TNimNode")
declareNimType(m, "TNimType", result, owner)
declareNimType(m, cgsymValue(m, "TNimType"), result, owner)
return prefixTI(result)
else:
owner = m.module.position.int32
Expand Down

0 comments on commit 58407e5

Please sign in to comment.