From 0297c613787b5985f68021cb8f475489f1c8b3c6 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 20 Jul 2014 01:06:03 +0200 Subject: [PATCH] first steps --- compiler/ast.nim | 11 +++++++---- compiler/ccgexprs.nim | 8 ++++---- compiler/msgs.nim | 2 +- compiler/semdestruct.nim | 20 ++++++++++---------- compiler/suggest.nim | 2 +- lib/pure/asyncdispatch.nim | 14 +++++++++++--- lib/pure/asynchttpserver.nim | 14 +++++++++++--- 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index bdb8d1c23..cdae2e9e6 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -768,6 +768,8 @@ type # it won't cause problems TTypeSeq* = seq[PType] + TTypeAttachedOp* = enum + attachedDestructor, attachedAsgn, attachedDeepCopy TType* {.acyclic.} = object of TIdObj # \ # types are identical iff they have the # same id; there may be multiple copies of a type @@ -785,12 +787,13 @@ type # the body of the user-defined type class # formal param list # else: unused - destructor*: PSym # destructor. warning: nil here may not necessary - # mean that there is no destructor. - # see instantiateDestructor in types.nim owner*: PSym # the 'owner' of the type sym*: PSym # types have the sym associated with them # it is used for converting types to strings + attachedOp*: array[TTypeAttachedOp, PSym] # \ + # destructor. warning: nil here may not necessary + # mean that there is no destructor. + # see instantiateDestructor in types.nim size*: BiggestInt # the size of the type in bytes # -1 means that the size is unkwown align*: int # the type's alignment requirements @@ -1189,7 +1192,7 @@ proc assignType(dest, src: PType) = dest.n = src.n dest.size = src.size dest.align = src.align - dest.destructor = src.destructor + dest.attachedOps = src.attachedOps # this fixes 'type TLock = TSysLock': if src.sym != nil: if dest.sym != nil: diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 95167e157..bc9e4a27f 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -214,9 +214,9 @@ proc optAsgnLoc(a: TLoc, t: PType, field: PRope): TLoc = proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let newflags = if src.k == locData: - flags + { needToCopy } + flags + {needToCopy} elif tfShallow in dest.t.flags: - flags - { needToCopy } + flags - {needToCopy} else: flags for i in 0 .. ") echo("Future already finished, cannot finish twice.") - assert false + echo getStackTrace() + quit() + #assert false proc complete*[T](future: PFuture[T], val: T) = ## Completes ``future`` with value ``val``. @@ -836,16 +838,22 @@ template createCb*(retFutureSym, iteratorNameSym, var nameIterVar = iteratorNameSym #{.push stackTrace: off.} proc cb {.closure,gcsafe.} = + echo("cb") try: if not nameIterVar.finished: + echo("Executing iter") var next = nameIterVar() + echo(next.isNil, " ", next == nil, " ", nameIterVar.finished) if next == nil: assert retFutureSym.finished, "Async procedure's (" & name & ") return Future was not finished." else: next.callback = cb except: + echo(getCurrentExceptionMsg()) + echo(retFutureSym.stackTrace) retFutureSym.fail(getCurrentException()) + echo("hello") cb() #{.pop.} proc generateExceptionCheck(futSym, @@ -1068,8 +1076,8 @@ macro async*(prc: stmt): stmt {.immediate.} = result[6] = outerProcBody #echo(treeRepr(result)) - #if prc[0].getName == "routeReq": - #echo(toStrLit(result)) + if prc[0].getName == "processClient": + echo(toStrLit(result)) proc recvLine*(socket: TAsyncFD): PFuture[string] {.async.} = ## Reads a line of data from ``socket``. Returned future will complete once diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim index ee6658fd1..ed3d912c0 100644 --- a/lib/pure/asynchttpserver.nim +++ b/lib/pure/asynchttpserver.nim @@ -114,8 +114,10 @@ proc processClient(client: PAsyncSocket, address: string, return let lineParts = line.split(' ') if lineParts.len != 3: - await request.respond(Http400, "Invalid request. Got: " & line) - continue + echo("About to raise") + raise newException(EBase, "FUCK YA") + #await request.respond(Http400, "Invalid request. Got: " & line) + #continue let reqMethod = lineParts[0] let path = lineParts[1] @@ -198,7 +200,13 @@ proc serve*(server: PAsyncHttpServer, port: TPort, # TODO: Causes compiler crash. #var (address, client) = await server.socket.acceptAddr() var fut = await server.socket.acceptAddr() - asyncCheck processClient(fut.client, fut.address, callback) + var f = processClient(fut.client, fut.address, callback) + #echo(f.isNil) + #echo(f.repr) + f.callback = + proc () = + echo("processClient end") + echo(f.failed) proc close*(server: PAsyncHttpServer) = ## Terminates the async http server instance.