mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 03:14:08 +00:00
@@ -1322,6 +1322,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
ensureKind(rkNode)
|
||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||
regs[ra].node = opMapTypeToAst(c.cache, regs[rb].node.typ, c.debug[pc])
|
||||
elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil:
|
||||
regs[ra].node = opMapTypeToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc])
|
||||
else:
|
||||
stackTrace(c, tos, pc, "node has no type")
|
||||
of 1:
|
||||
@@ -1329,6 +1331,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
ensureKind(rkInt)
|
||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||
regs[ra].intVal = ord(regs[rb].node.typ.kind)
|
||||
elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil:
|
||||
regs[ra].intVal = ord(regs[rb].node.sym.typ.kind)
|
||||
#else:
|
||||
# stackTrace(c, tos, pc, "node has no type")
|
||||
of 2:
|
||||
@@ -1336,6 +1340,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
ensureKind(rkNode)
|
||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||
regs[ra].node = opMapTypeInstToAst(c.cache, regs[rb].node.typ, c.debug[pc])
|
||||
elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil:
|
||||
regs[ra].node = opMapTypeInstToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc])
|
||||
else:
|
||||
stackTrace(c, tos, pc, "node has no type")
|
||||
else:
|
||||
@@ -1343,6 +1349,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
ensureKind(rkNode)
|
||||
if regs[rb].kind == rkNode and regs[rb].node.typ != nil:
|
||||
regs[ra].node = opMapTypeImplToAst(c.cache, regs[rb].node.typ, c.debug[pc])
|
||||
elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil:
|
||||
regs[ra].node = opMapTypeImplToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc])
|
||||
else:
|
||||
stackTrace(c, tos, pc, "node has no type")
|
||||
of opcNStrVal:
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
discard """
|
||||
nimout: '''void
|
||||
int'''
|
||||
nimout: '''intProc; ntyProc; proc[int, int, float]; proc (a: int; b: float): int
|
||||
void; ntyVoid; void; void
|
||||
int; ntyInt; int; int
|
||||
proc (); ntyProc; proc[void]; proc ()
|
||||
voidProc; ntyProc; proc[void]; proc ()'''
|
||||
"""
|
||||
|
||||
import macros
|
||||
|
||||
macro checkType(ex: typed; expected: string): untyped =
|
||||
var t = ex.getType()
|
||||
echo t
|
||||
echo ex.getTypeInst.repr, "; ", ex.typeKind, "; ", ex.getType.repr, "; ", ex.getTypeImpl.repr
|
||||
|
||||
macro checkProcType(fn: typed): untyped =
|
||||
let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn
|
||||
echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr
|
||||
|
||||
|
||||
proc voidProc = echo "hello"
|
||||
proc intProc(a: int, b: float): int = 10
|
||||
proc intProc(a: int, b: float): int {.checkProcType.} = 10
|
||||
|
||||
checkType(voidProc(), "void")
|
||||
checkType(intProc(10, 20.0), "int")
|
||||
checkType(voidProc, "procTy")
|
||||
checkProcType(voidProc)
|
||||
|
||||
Reference in New Issue
Block a user