implemented macros.getImpl
This commit is contained in:
parent
a2bb7d4c71
commit
695e2e970e
8 changed files with 39 additions and 2 deletions
|
|
@ -602,7 +602,7 @@ type
|
||||||
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo,
|
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo,
|
||||||
mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr,
|
mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr,
|
||||||
mNBindSym, mLocals, mNCallSite,
|
mNBindSym, mLocals, mNCallSite,
|
||||||
mEqIdent, mEqNimrodNode, mSameNodeType,
|
mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl,
|
||||||
mNHint, mNWarning, mNError,
|
mNHint, mNWarning, mNError,
|
||||||
mInstantiationInfo, mGetTypeInfo, mNGenSym
|
mInstantiationInfo, mGetTypeInfo, mNGenSym
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -781,6 +781,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
regs[ra].node.add(copyTree(regs[rb].regToNode))
|
regs[ra].node.add(copyTree(regs[rb].regToNode))
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, errNilAccess)
|
stackTrace(c, tos, pc, errNilAccess)
|
||||||
|
of opcGetImpl:
|
||||||
|
decodeB(rkNode)
|
||||||
|
let a = regs[rb].node
|
||||||
|
if a.kind == nkSym:
|
||||||
|
regs[ra].node = if a.sym.ast.isNil: newNode(nkNilLit)
|
||||||
|
else: copyTree(a.sym.ast)
|
||||||
|
else:
|
||||||
|
stackTrace(c, tos, pc, errFieldXNotFound, "symbol")
|
||||||
of opcEcho:
|
of opcEcho:
|
||||||
let rb = instr.regB
|
let rb = instr.regB
|
||||||
if rb == 1:
|
if rb == 1:
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ type
|
||||||
opcEqIdent,
|
opcEqIdent,
|
||||||
opcStrToIdent,
|
opcStrToIdent,
|
||||||
opcIdentToStr,
|
opcIdentToStr,
|
||||||
|
opcGetImpl,
|
||||||
|
|
||||||
opcEcho,
|
opcEcho,
|
||||||
opcIndCall, # dest = call regStart, n; where regStart = fn, arg1, ...
|
opcIndCall, # dest = call regStart, n; where regStart = fn, arg1, ...
|
||||||
|
|
|
||||||
|
|
@ -948,6 +948,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
of mSlurp: genUnaryABC(c, n, dest, opcSlurp)
|
of mSlurp: genUnaryABC(c, n, dest, opcSlurp)
|
||||||
of mStaticExec: genBinaryABCD(c, n, dest, opcGorge)
|
of mStaticExec: genBinaryABCD(c, n, dest, opcGorge)
|
||||||
of mNLen: genUnaryABI(c, n, dest, opcLenSeq)
|
of mNLen: genUnaryABI(c, n, dest, opcLenSeq)
|
||||||
|
of mGetImpl: genUnaryABC(c, n, dest, opcGetImpl)
|
||||||
of mNChild: genBinaryABC(c, n, dest, opcNChild)
|
of mNChild: genBinaryABC(c, n, dest, opcNChild)
|
||||||
of mNSetChild, mNDel:
|
of mNSetChild, mNDel:
|
||||||
unused(n, dest)
|
unused(n, dest)
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,10 @@ proc newNimNode*(kind: NimNodeKind,
|
||||||
proc copyNimNode*(n: NimNode): NimNode {.magic: "NCopyNimNode", noSideEffect.}
|
proc copyNimNode*(n: NimNode): NimNode {.magic: "NCopyNimNode", noSideEffect.}
|
||||||
proc copyNimTree*(n: NimNode): NimNode {.magic: "NCopyNimTree", noSideEffect.}
|
proc copyNimTree*(n: NimNode): NimNode {.magic: "NCopyNimTree", noSideEffect.}
|
||||||
|
|
||||||
|
proc getImpl*(s: NimSym): NimNode {.magic: "GetImpl", noSideEffect.}
|
||||||
|
## retrieve the implementation of a symbol `s`. `s` can be a routine or a
|
||||||
|
## const.
|
||||||
|
|
||||||
proc error*(msg: string) {.magic: "NError", benign.}
|
proc error*(msg: string) {.magic: "NError", benign.}
|
||||||
## writes an error message at compile time
|
## writes an error message at compile time
|
||||||
|
|
||||||
|
|
|
||||||
20
tests/macros/tgetimpl.nim
Normal file
20
tests/macros/tgetimpl.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
msg: '''"muhaha"
|
||||||
|
proc poo(x, y: int) =
|
||||||
|
echo ["poo"]'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
const
|
||||||
|
foo = "muhaha"
|
||||||
|
|
||||||
|
proc poo(x, y: int) =
|
||||||
|
echo "poo"
|
||||||
|
|
||||||
|
macro m(x: typed): untyped =
|
||||||
|
echo repr x.symbol.getImpl
|
||||||
|
result = x
|
||||||
|
|
||||||
|
discard m foo
|
||||||
|
discard m poo
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -2,7 +2,6 @@ version 0.11.4
|
||||||
==============
|
==============
|
||||||
|
|
||||||
- make tuple unpacking work in a non-var/let context
|
- make tuple unpacking work in a non-var/let context
|
||||||
- built-in 'getImpl'
|
|
||||||
|
|
||||||
- document special cased varargs[untyped] and varargs[typed]
|
- document special cased varargs[untyped] and varargs[typed]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ News
|
||||||
- The ``expandSymlink`` proc has been added to the ``os`` module.
|
- The ``expandSymlink`` proc has been added to the ``os`` module.
|
||||||
- The ``tailDir`` proc has been added to the ``os`` module.
|
- The ``tailDir`` proc has been added to the ``os`` module.
|
||||||
|
|
||||||
|
|
||||||
Language Additions
|
Language Additions
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|
@ -68,6 +69,9 @@ News
|
||||||
variable or parameter for C interoperability. Since technically this
|
variable or parameter for C interoperability. Since technically this
|
||||||
makes parameters and ``let`` variables mutable, it is considered even more
|
makes parameters and ``let`` variables mutable, it is considered even more
|
||||||
unsafe than the ordinary ``addr`` builtin.
|
unsafe than the ordinary ``addr`` builtin.
|
||||||
|
- Added ``macros.getImpl`` that can be used to access the implementation of
|
||||||
|
a routine or a constant. This allows for example for user-defined inlining
|
||||||
|
of function calls.
|
||||||
|
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue