more tests are green
This commit is contained in:
parent
430c8d8b52
commit
29357ab556
6 changed files with 54 additions and 80 deletions
|
|
@ -780,6 +780,7 @@ proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
#semLazyOpAux(c, n)
|
#semLazyOpAux(c, n)
|
||||||
result = semOverloadedCallAnalyseEffects(c, n, nOrig, flags)
|
result = semOverloadedCallAnalyseEffects(c, n, nOrig, flags)
|
||||||
if result != nil: result = afterCallActions(c, result, nOrig, flags)
|
if result != nil: result = afterCallActions(c, result, nOrig, flags)
|
||||||
|
else: result = errorNode(c, n)
|
||||||
|
|
||||||
proc buildStringify(c: PContext, arg: PNode): PNode =
|
proc buildStringify(c: PContext, arg: PNode): PNode =
|
||||||
if arg.typ != nil and
|
if arg.typ != nil and
|
||||||
|
|
@ -1839,7 +1840,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
# don't have to check the symbol for semantics here again!
|
# don't have to check the symbol for semantics here again!
|
||||||
result = semSym(c, n, n.sym, flags)
|
result = semSym(c, n, n.sym, flags)
|
||||||
of nkEmpty, nkNone, nkCommentStmt:
|
of nkEmpty, nkNone, nkCommentStmt:
|
||||||
nil
|
discard
|
||||||
of nkNilLit:
|
of nkNilLit:
|
||||||
result.typ = getSysType(tyNil)
|
result.typ = getSysType(tyNil)
|
||||||
of nkIntLit:
|
of nkIntLit:
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,33 @@ discard """
|
||||||
mShrI, mShrI64, mAddF64, mSubF64, mMulF64, mDivF64, mMaxF64, mMinF64
|
mShrI, mShrI64, mAddF64, mSubF64, mMulF64, mDivF64, mMaxF64, mMinF64
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
proc evalIs(n, a: PNode): PNode =
|
||||||
|
internalAssert a.kind == nkSym and a.sym.kind == skType
|
||||||
|
internalAssert n.sonsLen == 3 and
|
||||||
|
n[2].kind in {nkStrLit..nkTripleStrLit, nkType}
|
||||||
|
|
||||||
|
let t1 = a.sym.typ
|
||||||
|
|
||||||
|
if n[2].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
|
case n[2].strVal.normalize
|
||||||
|
of "closure":
|
||||||
|
let t = skipTypes(t1, abstractRange)
|
||||||
|
result = newIntNode(nkIntLit, ord(t.kind == tyProc and
|
||||||
|
t.callConv == ccClosure and
|
||||||
|
tfIterator notin t.flags))
|
||||||
|
of "iterator":
|
||||||
|
let t = skipTypes(t1, abstractRange)
|
||||||
|
result = newIntNode(nkIntLit, ord(t.kind == tyProc and
|
||||||
|
t.callConv == ccClosure and
|
||||||
|
tfIterator in t.flags))
|
||||||
|
else:
|
||||||
|
# XXX semexprs.isOpImpl is slightly different and requires a context. yay.
|
||||||
|
let t2 = n[2].typ
|
||||||
|
var match = if t2.kind == tyTypeClass: matchTypeClass(t2, t1)
|
||||||
|
else: sameType(t1, t2)
|
||||||
|
result = newIntNode(nkIntLit, ord(match))
|
||||||
|
result.typ = n.typ
|
||||||
|
|
||||||
proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||||
# b and c may be nil
|
# b and c may be nil
|
||||||
result = nil
|
result = nil
|
||||||
|
|
@ -372,7 +399,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||||
mAppendStrStr, mAppendSeqElem, mSetLengthStr, mSetLengthSeq,
|
mAppendStrStr, mAppendSeqElem, mSetLengthStr, mSetLengthSeq,
|
||||||
mParseExprToAst, mParseStmtToAst, mExpandToAst, mTypeTrait,
|
mParseExprToAst, mParseStmtToAst, mExpandToAst, mTypeTrait,
|
||||||
mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym:
|
mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym:
|
||||||
nil
|
discard
|
||||||
of mRand:
|
of mRand:
|
||||||
result = newIntNodeT(math.random(a.getInt.int), n)
|
result = newIntNodeT(math.random(a.getInt.int), n)
|
||||||
else: InternalError(a.info, "evalOp(" & $m & ')')
|
else: InternalError(a.info, "evalOp(" & $m & ')')
|
||||||
|
|
@ -446,8 +473,6 @@ proc magicCall(m: PSym, n: PNode): PNode =
|
||||||
if sonsLen(n) > 3:
|
if sonsLen(n) > 3:
|
||||||
c = getConstExpr(m, n.sons[3])
|
c = getConstExpr(m, n.sons[3])
|
||||||
if c == nil: return
|
if c == nil: return
|
||||||
else:
|
|
||||||
b = nil
|
|
||||||
result = evalOp(s.magic, n, a, b, c)
|
result = evalOp(s.magic, n, a, b, c)
|
||||||
|
|
||||||
proc getAppType(n: PNode): PNode =
|
proc getAppType(n: PNode): PNode =
|
||||||
|
|
@ -485,7 +510,7 @@ proc foldConv*(n, a: PNode; check = false): PNode =
|
||||||
result = a
|
result = a
|
||||||
result.typ = n.typ
|
result.typ = n.typ
|
||||||
of tyOpenArray, tyVarargs, tyProc:
|
of tyOpenArray, tyVarargs, tyProc:
|
||||||
nil
|
discard
|
||||||
else:
|
else:
|
||||||
result = a
|
result = a
|
||||||
result.typ = n.typ
|
result.typ = n.typ
|
||||||
|
|
@ -523,7 +548,7 @@ proc foldArrayAccess(m: PSym, n: PNode): PNode =
|
||||||
nil
|
nil
|
||||||
else:
|
else:
|
||||||
LocalError(n.info, errIndexOutOfBounds)
|
LocalError(n.info, errIndexOutOfBounds)
|
||||||
else: nil
|
else: discard
|
||||||
|
|
||||||
proc foldFieldAccess(m: PSym, n: PNode): PNode =
|
proc foldFieldAccess(m: PSym, n: PNode): PNode =
|
||||||
# a real field access; proc calls have already been transformed
|
# a real field access; proc calls have already been transformed
|
||||||
|
|
@ -592,7 +617,7 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
result.typ = s.typ.sons[0]
|
result.typ = s.typ.sons[0]
|
||||||
else:
|
else:
|
||||||
result = newSymNodeTypeDesc(s, n.info)
|
result = newSymNodeTypeDesc(s, n.info)
|
||||||
else: nil
|
else: discard
|
||||||
of nkCharLit..nkNilLit:
|
of nkCharLit..nkNilLit:
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
of nkIfExpr:
|
of nkIfExpr:
|
||||||
|
|
@ -604,7 +629,8 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
try:
|
try:
|
||||||
case s.magic
|
case s.magic
|
||||||
of mNone:
|
of mNone:
|
||||||
return # XXX: if it has no sideEffect, it should be evaluated
|
# If it has no sideEffect, it should be evaluated. But not here.
|
||||||
|
return
|
||||||
of mSizeOf:
|
of mSizeOf:
|
||||||
var a = n.sons[1]
|
var a = n.sons[1]
|
||||||
if computeSize(a.typ) < 0:
|
if computeSize(a.typ) < 0:
|
||||||
|
|
@ -644,6 +670,10 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)
|
result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)
|
||||||
of mConStrStr:
|
of mConStrStr:
|
||||||
result = foldConStrStr(m, n)
|
result = foldConStrStr(m, n)
|
||||||
|
of mIs:
|
||||||
|
let a = getConstExpr(m, n[1])
|
||||||
|
if a != nil and a.kind == nkSym and a.sym.kind == skType:
|
||||||
|
result = evalIs(n, a)
|
||||||
else:
|
else:
|
||||||
result = magicCall(m, n)
|
result = magicCall(m, n)
|
||||||
except EOverflow:
|
except EOverflow:
|
||||||
|
|
@ -727,4 +757,4 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
of nkBracketExpr: result = foldArrayAccess(m, n)
|
of nkBracketExpr: result = foldArrayAccess(m, n)
|
||||||
of nkDotExpr: result = foldFieldAccess(m, n)
|
of nkDotExpr: result = foldFieldAccess(m, n)
|
||||||
else:
|
else:
|
||||||
nil
|
discard
|
||||||
|
|
|
||||||
|
|
@ -34,60 +34,3 @@ proc opSlurp*(file: string, info: TLineInfo, module: PSym): string =
|
||||||
except EIO:
|
except EIO:
|
||||||
LocalError(info, errCannotOpenFile, file)
|
LocalError(info, errCannotOpenFile, file)
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
when false:
|
|
||||||
proc opExpandToAst*(c: PEvalContext, original: PNode): PNode =
|
|
||||||
var
|
|
||||||
n = original.copyTree
|
|
||||||
macroCall = n.sons[1]
|
|
||||||
expandedSym = macroCall.sons[0].sym
|
|
||||||
|
|
||||||
for i in countup(1, macroCall.sonsLen - 1):
|
|
||||||
macroCall.sons[i] = evalAux(c, macroCall.sons[i], {})
|
|
||||||
|
|
||||||
case expandedSym.kind
|
|
||||||
of skTemplate:
|
|
||||||
let genSymOwner = if c.tos != nil and c.tos.prc != nil:
|
|
||||||
c.tos.prc
|
|
||||||
else:
|
|
||||||
c.module
|
|
||||||
result = evalTemplate(macroCall, expandedSym, genSymOwner)
|
|
||||||
of skMacro:
|
|
||||||
# At this point macroCall.sons[0] is nkSym node.
|
|
||||||
# To be completely compatible with normal macro invocation,
|
|
||||||
# we want to replace it with nkIdent node featuring
|
|
||||||
# the original unmangled macro name.
|
|
||||||
macroCall.sons[0] = newIdentNode(expandedSym.name, expandedSym.info)
|
|
||||||
result = evalMacroCall(c, macroCall, original, expandedSym)
|
|
||||||
else:
|
|
||||||
InternalError(macroCall.info,
|
|
||||||
"ExpandToAst: expanded symbol is no macro or template")
|
|
||||||
result = emptyNode
|
|
||||||
|
|
||||||
proc opIs*(n: PNode): PNode =
|
|
||||||
InternalAssert n.sonsLen == 3 and
|
|
||||||
n[1].kind == nkSym and n[1].sym.kind == skType and
|
|
||||||
n[2].kind in {nkStrLit..nkTripleStrLit, nkType}
|
|
||||||
|
|
||||||
let t1 = n[1].sym.typ
|
|
||||||
|
|
||||||
if n[2].kind in {nkStrLit..nkTripleStrLit}:
|
|
||||||
case n[2].strVal.normalize
|
|
||||||
of "closure":
|
|
||||||
let t = skipTypes(t1, abstractRange)
|
|
||||||
result = newIntNode(nkIntLit, ord(t.kind == tyProc and
|
|
||||||
t.callConv == ccClosure and
|
|
||||||
tfIterator notin t.flags))
|
|
||||||
of "iterator":
|
|
||||||
let t = skipTypes(t1, abstractRange)
|
|
||||||
result = newIntNode(nkIntLit, ord(t.kind == tyProc and
|
|
||||||
t.callConv == ccClosure and
|
|
||||||
tfIterator in t.flags))
|
|
||||||
else:
|
|
||||||
let t2 = n[2].typ
|
|
||||||
var match = if t2.kind == tyTypeClass: matchTypeClass(t2, t1)
|
|
||||||
else: sameType(t1, t2)
|
|
||||||
result = newIntNode(nkIntLit, ord(match))
|
|
||||||
|
|
||||||
result.typ = n.typ
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,17 @@ import
|
||||||
when hasFFI:
|
when hasFFI:
|
||||||
import evalffi
|
import evalffi
|
||||||
|
|
||||||
proc codeListing(c: PCtx, result: var string) =
|
proc codeListing(c: PCtx, result: var string, start=0) =
|
||||||
# first iteration: compute all necessary labels:
|
# first iteration: compute all necessary labels:
|
||||||
var jumpTargets = initIntSet()
|
var jumpTargets = initIntSet()
|
||||||
|
|
||||||
for i in 0.. < c.code.len:
|
for i in start.. < c.code.len:
|
||||||
let x = c.code[i]
|
let x = c.code[i]
|
||||||
if x.opcode in relativeJumps:
|
if x.opcode in relativeJumps:
|
||||||
jumpTargets.incl(i+x.regBx-wordExcess)
|
jumpTargets.incl(i+x.regBx-wordExcess)
|
||||||
|
|
||||||
# for debugging purposes
|
# for debugging purposes
|
||||||
var i = 0
|
var i = start
|
||||||
while i < c.code.len:
|
while i < c.code.len:
|
||||||
if i in jumpTargets: result.addf("L$1:\n", i)
|
if i in jumpTargets: result.addf("L$1:\n", i)
|
||||||
let x = c.code[i]
|
let x = c.code[i]
|
||||||
|
|
@ -48,9 +48,9 @@ proc codeListing(c: PCtx, result: var string) =
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
inc i
|
inc i
|
||||||
|
|
||||||
proc echoCode*(c: PCtx) {.deprecated.} =
|
proc echoCode*(c: PCtx, start=0) {.deprecated.} =
|
||||||
var buf = ""
|
var buf = ""
|
||||||
codeListing(c, buf)
|
codeListing(c, buf, start)
|
||||||
echo buf
|
echo buf
|
||||||
|
|
||||||
proc gABC(ctx: PCtx; n: PNode; opc: TOpcode; a, b, c: TRegister = 0) =
|
proc gABC(ctx: PCtx; n: PNode; opc: TOpcode; a, b, c: TRegister = 0) =
|
||||||
|
|
@ -846,7 +846,7 @@ proc whichAsgnOpc(n: PNode): TOpcode =
|
||||||
opcAsgnStr
|
opcAsgnStr
|
||||||
of tyFloat..tyFloat128:
|
of tyFloat..tyFloat128:
|
||||||
opcAsgnFloat
|
opcAsgnFloat
|
||||||
of tyRef, tyNil:
|
of tyRef, tyNil, tyVar:
|
||||||
opcAsgnRef
|
opcAsgnRef
|
||||||
else:
|
else:
|
||||||
opcAsgnComplex
|
opcAsgnComplex
|
||||||
|
|
@ -1371,8 +1371,8 @@ proc genProc(c: PCtx; s: PSym): int =
|
||||||
c.gABC(body, opcEof, eofInstr.regA)
|
c.gABC(body, opcEof, eofInstr.regA)
|
||||||
c.optimizeJumps(result)
|
c.optimizeJumps(result)
|
||||||
s.offset = c.prc.maxSlots
|
s.offset = c.prc.maxSlots
|
||||||
#if s.name.s == "innerProc":
|
#if s.name.s == "treeRepr" or s.name.s == "traverse":
|
||||||
# c.echoCode
|
# c.echoCode(result)
|
||||||
# echo renderTree(body)
|
# echo renderTree(body)
|
||||||
c.prc = oldPrc
|
c.prc = oldPrc
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ import os, parseutils, strutils
|
||||||
|
|
||||||
when not defined(windows):
|
when not defined(windows):
|
||||||
type
|
type
|
||||||
TConverter = object {.pure, final.}
|
TConverter = object
|
||||||
PConverter* = ptr TConverter ## can convert between two character sets
|
PConverter* = ptr TConverter ## can convert between two character sets
|
||||||
|
|
||||||
else:
|
else:
|
||||||
type
|
type
|
||||||
TCodePage = distinct int32
|
TCodePage = distinct int32
|
||||||
PConverter* = object {.pure.}
|
PConverter* = object
|
||||||
dest, src: TCodePage
|
dest, src: TCodePage
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -425,7 +425,7 @@ else:
|
||||||
dst = cast[cstring](cast[int](cstring(result)) + offset)
|
dst = cast[cstring](cast[int](cstring(result)) + offset)
|
||||||
outLen = len(result) - offset
|
outLen = len(result) - offset
|
||||||
else:
|
else:
|
||||||
OSError()
|
OSError(lerr.TOSErrorCode)
|
||||||
# iconv has a buffer that needs flushing, specially if the last char is
|
# iconv has a buffer that needs flushing, specially if the last char is
|
||||||
# not '\0'
|
# not '\0'
|
||||||
discard iconv(c, nil, nil, dst, outlen)
|
discard iconv(c, nil, nil, dst, outlen)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue