This commit is contained in:
Araq 2012-10-19 13:24:42 +02:00
commit b20663ce19
4 changed files with 24 additions and 3 deletions

View file

@ -1036,6 +1036,9 @@ proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
while (t.kind == tyObject) and (t.sons[0] != nil): while (t.kind == tyObject) and (t.sons[0] != nil):
app(r, ".Sup") app(r, ".Sup")
t = skipTypes(t.sons[0], typedescInst) t = skipTypes(t.sons[0], typedescInst)
if isObjLackingTypeField(t):
GlobalError(x.info, errGenerated,
"no 'of' operator available for pure objects")
if nilCheck != nil: if nilCheck != nil:
r = ropecg(p.module, "(($1) && #isObj($2.m_type, $3))", r = ropecg(p.module, "(($1) && #isObj($2.m_type, $3))",
[nilCheck, r, genTypeInfo(p.module, dest)]) [nilCheck, r, genTypeInfo(p.module, dest)])
@ -1597,7 +1600,7 @@ proc upConv(p: BProc, n: PNode, d: var TLoc) =
var a: TLoc var a: TLoc
initLocExpr(p, n.sons[0], a) initLocExpr(p, n.sons[0], a)
var dest = skipTypes(n.typ, abstractPtrs) var dest = skipTypes(n.typ, abstractPtrs)
if optObjCheck in p.options and not isPureObject(dest): if optObjCheck in p.options and not isObjLackingTypeField(dest):
var r = rdLoc(a) var r = rdLoc(a)
var nilCheck: PRope = nil var nilCheck: PRope = nil
var t = skipTypes(a.t, abstractInst) var t = skipTypes(a.t, abstractInst)

View file

@ -694,11 +694,14 @@ when false:
var tmp = getNimType(m) var tmp = getNimType(m)
appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name]) appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name])
proc isObjLackingTypeField(typ: PType): bool {.inline.} =
result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and
(typ.sons[0] == nil) or isPureObject(typ))
proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) = proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
var nimtypeKind: int var nimtypeKind: int
#allocMemTI(m, typ, name) #allocMemTI(m, typ, name)
if (typ.kind == tyObject) and (tfFinal in typ.flags) and if isObjLackingTypeField(typ):
(typ.sons[0] == nil):
nimtypeKind = ord(tyPureObject) nimtypeKind = ord(tyPureObject)
else: else:
nimtypeKind = ord(typ.kind) nimtypeKind = ord(typ.kind)

View file

@ -185,7 +185,11 @@ when not defined(useNimRtl):
proc reprRecord(result: var string, p: pointer, typ: PNimType, proc reprRecord(result: var string, p: pointer, typ: PNimType,
cl: var TReprClosure) = cl: var TReprClosure) =
add result, "[" add result, "["
let oldLen = result.len
reprRecordAux(result, p, typ.node, cl) reprRecordAux(result, p, typ.node, cl)
if typ.base != nil:
if oldLen != result.len: add result, ",\n"
reprRecordAux(result, p, typ.base.node, cl)
add result, "]" add result, "]"
proc reprRef(result: var string, p: pointer, typ: PNimType, proc reprRef(result: var string, p: pointer, typ: PNimType,

View file

@ -11,6 +11,17 @@ var val = {a, b}
stdout.write(repr(val)) stdout.write(repr(val))
stdout.writeln(repr({'a'..'z', 'A'..'Z'})) stdout.writeln(repr({'a'..'z', 'A'..'Z'}))
type
TObj {.pure, inheritable.} = object
data: int
TFoo = ref object of TObj
d2: float
var foo: TFoo
new(foo)
when false:
# cannot capture this output as it contains a memory address :-/
echo foo.repr
#var testseq: seq[string] = @[ #var testseq: seq[string] = @[
# "a", "b", "c", "d", "e" # "a", "b", "c", "d", "e"
#] #]