overloading of [] for derefence operation should be possible now

This commit is contained in:
Araq
2011-06-05 13:59:41 +02:00
parent e5eb36e472
commit 958961bd8d
3 changed files with 31 additions and 5 deletions

View File

@@ -772,8 +772,8 @@ proc genEcho(p: BProc, n: PNode) =
for i in countup(1, n.len-1):
initLocExpr(p, n.sons[i], a)
appf(args, ", ($1)->data", [rdLoc(a)])
appcg(p, cpsStmts, "printf(\"" & repeatStr(n.len-1, "%s") &
"\\n\"$1);$n", [args])
appcg(p, cpsStmts, "printf($1$2);$n", [
makeCString(repeatStr(n.len-1, "%s") & tnl), args])
proc genCall(p: BProc, t: PNode, d: var TLoc) =
var op, a: TLoc

View File

@@ -726,13 +726,15 @@ proc semDeref(c: PContext, n: PNode): PNode =
var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar})
case t.kind
of tyRef, tyPtr: n.typ = t.sons[0]
else: GlobalError(n.sons[0].info, errCircumNeedsPointer)
result = n
else: result = nil
#GlobalError(n.sons[0].info, errCircumNeedsPointer)
proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
## returns nil if not a built-in subscript operator;
## returns nil if not a built-in subscript operator; also called for the
## checking of assignments
if sonsLen(n) == 1:
var x = semDeref(c, n)
if x == nil: return nil
result = newNodeIT(nkDerefExpr, x.info, x.typ)
result.add(x[0])
return

View File

@@ -0,0 +1,24 @@
discard """
output: '''came here'''
"""
type
TAny* = object {.pure.}
value*: pointer
rawType: pointer
proc newAny(value, rawType: pointer): TAny =
result.value = value
result.rawType = rawType
var name: cstring = "example"
var ret: seq[tuple[name: string, a: TAny]] = @[]
for i in 0..8000:
var tup = ($name, newAny(nil, nil))
assert(tup[0] == "example")
ret.add(tup)
assert(ret[ret.len()-1][0] == "example")
echo "came here"