concept example from the manual now works again

This commit is contained in:
Araq
2015-03-23 11:18:02 +01:00
parent f6ff01572e
commit 3bcafb1c3a
5 changed files with 18 additions and 32 deletions

View File

@@ -587,22 +587,15 @@ proc unknownLineInfo*(): TLineInfo =
var
msgContext: seq[TLineInfo] = @[]
lastError = unknownLineInfo()
bufferedMsgs*: seq[string]
errorOutputs* = {eStdOut, eStdErr}
writelnHook*: proc (output: string) {.closure.}
proc clearBufferedMsgs* =
bufferedMsgs = nil
proc suggestWriteln*(s: string) =
if eStdOut in errorOutputs:
if isNil(writelnHook): writeln(stdout, s)
else: writelnHook(s)
if eInMemory in errorOutputs:
bufferedMsgs.safeAdd(s)
proc msgQuit*(x: int8) = quit x
proc msgQuit*(x: string) = quit x
@@ -705,8 +698,6 @@ proc msgWriteln*(s: string) =
else:
if eStdOut in errorOutputs: writeln(stdout, s)
if eInMemory in errorOutputs: bufferedMsgs.safeAdd(s)
proc coordToStr(coord: int): string =
if coord == -1: result = "???"
else: result = $coord

View File

@@ -12,6 +12,11 @@
# included from sem.nim
type
TTypeAttachedOp = enum
attachedDestructor,
attachedAsgn,
attachedDeepCopy
TLiftCtx = object
c: PContext
info: TLineInfo # for construction
@@ -78,7 +83,7 @@ proc liftBodyObj(c: TLiftCtx; typ, x, y: PNode) =
let L = forLoop.len
let call = forLoop.sons[L-2]
if call.len > 2:
localError(forLoop.info, errGenerated,
localError(forLoop.info, errGenerated,
"parallel 'fields' iterator does not work for 'case' objects")
return
# iterate over the selector:
@@ -117,7 +122,7 @@ proc newAsgnStmt(le, ri: PNode): PNode =
proc newDestructorCall(op: PSym; x: PNode): PNode =
result = newNodeIT(nkCall, x.info, op.typ.sons[0])
result.add(newSymNode(op))
result.add x
result.add x
proc newDeepCopyCall(op: PSym; x, y: PNode): PNode =
result = newAsgnStmt(x, newDestructorCall(op, y))
@@ -158,7 +163,7 @@ proc liftBodyAux(c: TLiftCtx; t: PType; x, y: PNode) =
of tyArrayConstr, tyArray, tySequence:
if iterOverType(lastSon(t), hasAttachedOp[c.kind], nil):
# generate loop and call the attached Op:
else:
defaultOp(c, t, x, y)
of tyObject:
@@ -167,7 +172,7 @@ proc liftBodyAux(c: TLiftCtx; t: PType; x, y: PNode) =
liftBodyTup(c, t, x, y)
of tyRef:
# we MUST not check for acyclic here as a DAG might still share nodes:
of tyProc:
if t.callConv != ccClosure or c.kind != attachedDeepCopy:
defaultOp(c, t, x, y)
@@ -195,3 +200,4 @@ proc liftBody(c: PContext; typ: PType; info: TLineInfo): PNode =
a.info = info
a.result = newNodeI(nkStmtList, info)
liftBodyAux(a, typ)
result = a.result

View File

@@ -499,6 +499,7 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
param.typ = makeTypeDesc(c, typ)
addDecl(c, param)
#echo "A ", param.name.s, " ", typeToString(param.typ), " ", param.kind
for param in body.n[0]:
var
@@ -507,30 +508,19 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
if param.kind == nkVarTy:
dummyName = param[0]
dummyType = if a.kind != tyVar: makeVarType(c, a)
else: a
dummyType = if a.kind != tyVar: makeVarType(c, a) else: a
else:
dummyName = param
dummyType = a
internalAssert dummyName.kind == nkIdent
var dummyParam = newSym(skType, dummyName.ident, body.sym, body.sym.info)
var dummyParam = newSym(skVar, dummyName.ident, body.sym, body.sym.info)
dummyParam.typ = dummyType
addDecl(c, dummyParam)
#echo "B ", dummyName.ident.s, " ", typeToString(dummyType), " ", dummyparam.kind
var checkedBody = c.semTryExpr(c, body.n[3].copyTree)
#m.errors = bufferedMsgs
clearBufferedMsgs()
if checkedBody == nil: return isNone
if checkedBody.kind == nkStmtList:
for stmt in checkedBody:
case stmt.kind
of nkReturnStmt: discard
of nkTypeSection: discard
of nkConstDef: discard
else: discard
return isGeneric
proc shouldSkipDistinct(rules: PNode, callIdent: PIdent): bool =

View File

@@ -12,7 +12,6 @@ e
s
t
'''
disabled: "true"
"""
template accept(e: expr) =
@@ -22,10 +21,10 @@ template reject(e: expr) =
static: assert(not compiles(e))
type
Container[T] = concept C
C.len is Ordinal
Container[T] = concept c
c.len is Ordinal
items(c) is iterator
for value in C:
for value in c:
type(value) is T
proc takesIntContainer(c: Container[int]) =

View File

@@ -6,12 +6,12 @@ version 0.10.4
- make 'nil' work for 'add' and 'len'
- add "all threads are blocked" detection to 'spawn'
- overloading of '='
- disallow negative indexing
version 1.0
===========
- disallow negative indexing
- figure out why C++ bootstrapping is so much slower
- nimsuggest: auto-completion needs to work in 'class' macros
- improve the docs for inheritance