fixes #1548
This commit is contained in:
parent
729e048a32
commit
c5cc20d337
5 changed files with 27 additions and 45 deletions
|
|
@ -916,14 +916,15 @@ proc genAndOr(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
proc genEcho(p: BProc, n: PNode) =
|
proc genEcho(p: BProc, n: PNode) =
|
||||||
# this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)``
|
# this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)``
|
||||||
# is threadsafe.
|
# is threadsafe.
|
||||||
|
internalAssert n.kind == nkBracket
|
||||||
discard lists.includeStr(p.module.headerFiles, "<stdio.h>")
|
discard lists.includeStr(p.module.headerFiles, "<stdio.h>")
|
||||||
var args: PRope = nil
|
var args: PRope = nil
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
for i in countup(1, n.len-1):
|
for i in countup(0, n.len-1):
|
||||||
initLocExpr(p, n.sons[i], a)
|
initLocExpr(p, n.sons[i], a)
|
||||||
appf(args, ", ($1)->data", [rdLoc(a)])
|
appf(args, ", ($1)->data", [rdLoc(a)])
|
||||||
linefmt(p, cpsStmts, "printf($1$2);$n",
|
linefmt(p, cpsStmts, "printf($1$2);$n",
|
||||||
makeCString(repeatStr(n.len-1, "%s") & tnl), args)
|
makeCString(repeatStr(n.len, "%s") & tnl), args)
|
||||||
|
|
||||||
proc gcUsage(n: PNode) =
|
proc gcUsage(n: PNode) =
|
||||||
if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree)
|
if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree)
|
||||||
|
|
@ -1693,7 +1694,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
discard cgsym(p.module, opr.loc.r.ropeToStr)
|
discard cgsym(p.module, opr.loc.r.ropeToStr)
|
||||||
genCall(p, e, d)
|
genCall(p, e, d)
|
||||||
of mReset: genReset(p, e)
|
of mReset: genReset(p, e)
|
||||||
of mEcho: genEcho(p, e)
|
of mEcho: genEcho(p, e[1].skipConv)
|
||||||
of mArrToSeq: genArrToSeq(p, e, d)
|
of mArrToSeq: genArrToSeq(p, e, d)
|
||||||
of mNLen..mNError:
|
of mNLen..mNError:
|
||||||
localError(e.info, errCannotGenerateCodeForX, e.sons[0].sym.name.s)
|
localError(e.info, errCannotGenerateCodeForX, e.sons[0].sym.name.s)
|
||||||
|
|
|
||||||
|
|
@ -1078,8 +1078,16 @@ proc genInfixCall(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
|
|
||||||
proc genEcho(p: PProc, n: PNode, r: var TCompRes) =
|
proc genEcho(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
useMagic(p, "rawEcho")
|
useMagic(p, "rawEcho")
|
||||||
app(r.res, "rawEcho")
|
app(r.res, "rawEcho(")
|
||||||
genArgs(p, n, r)
|
let n = n[1].skipConv
|
||||||
|
internalAssert n.kind == nkBracket
|
||||||
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
let it = n.sons[i]
|
||||||
|
if it.typ.isCompileTimeOnly: continue
|
||||||
|
if i > 0: app(r.res, ", ")
|
||||||
|
genArg(p, it, r)
|
||||||
|
app(r.res, ")")
|
||||||
|
r.kind = resExpr
|
||||||
|
|
||||||
proc putToSeq(s: string, indirect: bool): PRope =
|
proc putToSeq(s: string, indirect: bool): PRope =
|
||||||
result = toRope(s)
|
result = toRope(s)
|
||||||
|
|
|
||||||
|
|
@ -840,45 +840,17 @@ proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if result != nil: result = afterCallActions(c, result, nOrig, flags)
|
if result != nil: result = afterCallActions(c, result, nOrig, flags)
|
||||||
else: result = errorNode(c, n)
|
else: result = errorNode(c, n)
|
||||||
|
|
||||||
proc buildStringify(c: PContext, arg: PNode): PNode =
|
|
||||||
if arg.typ != nil and
|
|
||||||
skipTypes(arg.typ, abstractInst-{tyTypeDesc}).kind == tyString:
|
|
||||||
result = arg
|
|
||||||
else:
|
|
||||||
result = newNodeI(nkCall, arg.info)
|
|
||||||
addSon(result, newIdentNode(getIdent"$", arg.info))
|
|
||||||
addSon(result, arg)
|
|
||||||
|
|
||||||
proc semEcho(c: PContext, n: PNode): PNode =
|
|
||||||
# this really is a macro
|
|
||||||
checkMinSonsLen(n, 1)
|
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
|
||||||
var arg = semExprWithType(c, n.sons[i])
|
|
||||||
arg = semExprWithType(c, buildStringify(c, arg))
|
|
||||||
n.sons[i] = arg
|
|
||||||
let t = arg.typ
|
|
||||||
if (t == nil or t.skipTypes(abstractInst).kind != tyString) and
|
|
||||||
arg.kind != nkEmpty:
|
|
||||||
localError(n.info, errGenerated,
|
|
||||||
"implicitly invoked '$' does not return string")
|
|
||||||
let t = n.sons[0].typ
|
|
||||||
if tfNoSideEffect notin t.flags: incl(c.p.owner.flags, sfSideEffect)
|
|
||||||
result = n
|
|
||||||
|
|
||||||
proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
||||||
# we MUST not check 'n' for semantics again here!
|
# we MUST not check 'n' for semantics again here! But for now we give up:
|
||||||
result = newNodeI(nkCall, n.info)
|
result = newNodeI(nkCall, n.info)
|
||||||
var e = strTableGet(magicsys.systemModule.tab, getIdent"echo")
|
var e = strTableGet(magicsys.systemModule.tab, getIdent"echo")
|
||||||
if e != nil:
|
if e != nil:
|
||||||
addSon(result, newSymNode(e))
|
add(result, newSymNode(e))
|
||||||
else:
|
else:
|
||||||
localError(n.info, errSystemNeeds, "echo")
|
localError(n.info, errSystemNeeds, "echo")
|
||||||
addSon(result, errorNode(c, n))
|
add(result, errorNode(c, n))
|
||||||
var arg = buildStringify(c, n)
|
add(result, n)
|
||||||
# problem is: implicit '$' is not checked for semantics yet. So we give up
|
result = semExpr(c, result)
|
||||||
# and check 'arg' for semantics again:
|
|
||||||
arg = semExpr(c, arg)
|
|
||||||
if arg != nil: addSon(result, arg)
|
|
||||||
|
|
||||||
proc semExprNoType(c: PContext, n: PNode): PNode =
|
proc semExprNoType(c: PContext, n: PNode): PNode =
|
||||||
result = semExpr(c, n, {efWantStmt})
|
result = semExpr(c, n, {efWantStmt})
|
||||||
|
|
@ -1650,7 +1622,6 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
of mSizeOf: result = semSizeof(c, setMs(n, s))
|
of mSizeOf: result = semSizeof(c, setMs(n, s))
|
||||||
of mIs: result = semIs(c, setMs(n, s))
|
of mIs: result = semIs(c, setMs(n, s))
|
||||||
of mOf: result = semOf(c, setMs(n, s))
|
of mOf: result = semOf(c, setMs(n, s))
|
||||||
of mEcho: result = semEcho(c, setMs(n, s))
|
|
||||||
of mShallowCopy: result = semShallowCopy(c, n, flags)
|
of mShallowCopy: result = semShallowCopy(c, n, flags)
|
||||||
of mExpandToAst: result = semExpandToAst(c, n, s, flags)
|
of mExpandToAst: result = semExpandToAst(c, n, s, flags)
|
||||||
of mQuoteAst: result = semQuoteAst(c, n)
|
of mQuoteAst: result = semQuoteAst(c, n)
|
||||||
|
|
|
||||||
|
|
@ -899,12 +899,14 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest) =
|
||||||
c.freeTemp(tmp)
|
c.freeTemp(tmp)
|
||||||
of mEcho:
|
of mEcho:
|
||||||
unused(n, dest)
|
unused(n, dest)
|
||||||
let x = c.getTempRange(n.len-1, slotTempUnknown)
|
let n = n[1].skipConv
|
||||||
for i in 1.. <n.len:
|
let x = c.getTempRange(n.len, slotTempUnknown)
|
||||||
var r: TRegister = x+i-1
|
internalAssert n.kind == nkBracket
|
||||||
|
for i in 0.. <n.len:
|
||||||
|
var r: TRegister = x+i
|
||||||
c.gen(n.sons[i], r)
|
c.gen(n.sons[i], r)
|
||||||
c.gABC(n, opcEcho, x, n.len-1)
|
c.gABC(n, opcEcho, x, n.len)
|
||||||
c.freeTempRange(x, n.len-1)
|
c.freeTempRange(x, n.len)
|
||||||
of mAppendStrCh:
|
of mAppendStrCh:
|
||||||
unused(n, dest)
|
unused(n, dest)
|
||||||
genBinaryStmtVar(c, n, opcAddStrCh)
|
genBinaryStmtVar(c, n, opcAddStrCh)
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ The following builtin procs cannot be overloaded for reasons of implementation
|
||||||
simplicity (they require specialized semantic checking)::
|
simplicity (they require specialized semantic checking)::
|
||||||
|
|
||||||
declared, defined, definedInScope, compiles, low, high, sizeOf,
|
declared, defined, definedInScope, compiles, low, high, sizeOf,
|
||||||
is, of, echo, shallowCopy, getAst, astToStr, spawn
|
is, of, shallowCopy, getAst, astToStr, spawn
|
||||||
|
|
||||||
Thus they act more like keywords than like ordinary identifiers; unlike a
|
Thus they act more like keywords than like ordinary identifiers; unlike a
|
||||||
keyword however, a redefinition may `shadow`:idx: the definition in
|
keyword however, a redefinition may `shadow`:idx: the definition in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue