sizeof alignof offsetof macros api (#10855)
This commit is contained in:
parent
16fcbee1bc
commit
188870648a
7 changed files with 93 additions and 1 deletions
|
|
@ -662,7 +662,7 @@ type
|
|||
|
||||
mNIntVal, mNFloatVal, mNSymbol, mNIdent, mNGetType, mNStrVal, mNSetIntVal,
|
||||
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo,
|
||||
mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mNSigHash,
|
||||
mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mNSigHash, mNSizeOf,
|
||||
mNBindSym, mLocals, mNCallSite,
|
||||
mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl, mNGenSym,
|
||||
mNHint, mNWarning, mNError,
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ proc initDefines*(symbols: StringTableRef) =
|
|||
defineSymbol("nimHasNilSeqs")
|
||||
defineSymbol("nimHasSignatureHashInMacro")
|
||||
defineSymbol("nimHasDefault")
|
||||
defineSymbol("nimMacrosSizealignof")
|
||||
for f in low(Feature)..high(Feature):
|
||||
defineSymbol("nimHas" & $f)
|
||||
|
||||
|
|
|
|||
|
|
@ -1477,6 +1477,27 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
|||
regs[ra].node = opMapTypeImplToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc])
|
||||
else:
|
||||
stackTrace(c, tos, pc, "node has no type")
|
||||
of opcNGetSize:
|
||||
decodeBImm(rkInt)
|
||||
let n = regs[rb].node
|
||||
case imm
|
||||
of 0: # size
|
||||
if n.typ == nil:
|
||||
stackTrace(c, tos, pc, "node has no type")
|
||||
else:
|
||||
regs[ra].intVal = getSize(c.config, n.typ)
|
||||
of 1: # align
|
||||
if n.typ == nil:
|
||||
stackTrace(c, tos, pc, "node has no type")
|
||||
else:
|
||||
regs[ra].intVal = getAlign(c.config, n.typ)
|
||||
else: # offset
|
||||
if n.kind != nkSym:
|
||||
stackTrace(c, tos, pc, "node is not a symbol")
|
||||
elif n.sym.kind != skField:
|
||||
stackTrace(c, tos, pc, "symbol is not a field (nskField)")
|
||||
else:
|
||||
regs[ra].intVal = n.sym.offset
|
||||
of opcNStrVal:
|
||||
decodeB(rkNode)
|
||||
createStr regs[ra]
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ type
|
|||
opcNGetType,
|
||||
opcNStrVal,
|
||||
opcNSigHash,
|
||||
opcNGetSize,
|
||||
|
||||
opcNSetIntVal,
|
||||
opcNSetFloatVal, opcNSetSymbol, opcNSetIdent, opcNSetType, opcNSetStrVal,
|
||||
|
|
|
|||
|
|
@ -1236,6 +1236,12 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
|||
c.gABC(n, opcNGetType, dest, tmp, rc)
|
||||
c.freeTemp(tmp)
|
||||
#genUnaryABC(c, n, dest, opcNGetType)
|
||||
of mNSizeOf:
|
||||
let imm = case n[0].sym.name.s:
|
||||
of "getSize": 0
|
||||
of "getAlign": 1
|
||||
else: 2 # "getOffset"
|
||||
c.genUnaryABI(n, dest, opcNGetSize, imm)
|
||||
of mNStrVal: genUnaryABC(c, n, dest, opcNStrVal)
|
||||
of mNSigHash: genUnaryABC(c, n , dest, opcNSigHash)
|
||||
of mNSetIntVal:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue