first steps
This commit is contained in:
parent
ed226eba6d
commit
0297c61378
7 changed files with 45 additions and 26 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 .. <dest.t.len:
|
||||
|
|
@ -230,9 +230,9 @@ proc genOptAsgnObject(p: BProc, dest, src: TLoc, flags: TAssignmentFlags,
|
|||
if t == nil: return
|
||||
let newflags =
|
||||
if src.k == locData:
|
||||
flags + { needToCopy }
|
||||
flags + {needToCopy}
|
||||
elif tfShallow in dest.t.flags:
|
||||
flags - { needToCopy }
|
||||
flags - {needToCopy}
|
||||
else:
|
||||
flags
|
||||
case t.kind
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ const
|
|||
errUsingNoSymbol: "'$1' is not a variable, constant or a proc name",
|
||||
errMacroBodyDependsOnGenericTypes: "the macro body cannot be compiled, " &
|
||||
"because the parameter '$1' has a generic type",
|
||||
errDestructorNotGenericEnough: "Destructor signarue is too specific. " &
|
||||
errDestructorNotGenericEnough: "Destructor signature is too specific. " &
|
||||
"A destructor must be associated will all instantiations of a generic type",
|
||||
errInlineIteratorsAsProcParams: "inline iterators can be used as parameters only for " &
|
||||
"templates, macros and other inline iterators",
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
|
|||
localError(n.info, errDestructorNotGenericEnough)
|
||||
return
|
||||
|
||||
t.destructor = s
|
||||
t.attachedOp[attachedDestructor] = s
|
||||
# automatically insert calls to base classes' destructors
|
||||
if n.sons[bodyPos].kind != nkEmpty:
|
||||
for i in countup(0, t.sonsLen - 1):
|
||||
|
|
@ -52,7 +52,7 @@ proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
|
|||
let destructableT = instantiateDestructor(c, t.sons[i])
|
||||
if destructableT != nil:
|
||||
n.sons[bodyPos].addSon(newNode(nkCall, t.sym.info, @[
|
||||
useSym(destructableT.destructor),
|
||||
useSym(destructableT.attachedOp[attachedDestructor]),
|
||||
n.sons[paramsPos][1][0]]))
|
||||
|
||||
proc destroyFieldOrFields(c: PContext, field: PNode, holder: PNode): PNode
|
||||
|
|
@ -61,7 +61,7 @@ proc destroySym(c: PContext, field: PSym, holder: PNode): PNode =
|
|||
let destructableT = instantiateDestructor(c, field.typ)
|
||||
if destructableT != nil:
|
||||
result = newNode(nkCall, field.info, @[
|
||||
useSym(destructableT.destructor),
|
||||
useSym(destructableT.attachedOp[attachedDestructor]),
|
||||
newNode(nkDotExpr, field.info, @[holder, useSym(field)])])
|
||||
|
||||
proc destroyCase(c: PContext, n: PNode, holder: PNode): PNode =
|
||||
|
|
@ -128,10 +128,10 @@ proc instantiateDestructor(c: PContext, typ: PType): PType =
|
|||
let typeHoldingUserDefinition = if t.kind == tyGenericInst: t.base
|
||||
else: t
|
||||
|
||||
if typeHoldingUserDefinition.destructor != nil:
|
||||
if typeHoldingUserDefinition.attachedOp[attachedDestructor] != nil:
|
||||
# XXX: This is not entirely correct for recursive types, but we need
|
||||
# it temporarily to hide the "destroy is already defined" problem
|
||||
if typeHoldingUserDefinition.destructor notin
|
||||
if typeHoldingUserDefinition.attachedOp[attachedDestructor] notin
|
||||
[analyzingDestructor, destructorIsTrivial]:
|
||||
return typeHoldingUserDefinition
|
||||
else:
|
||||
|
|
@ -143,12 +143,12 @@ proc instantiateDestructor(c: PContext, typ: PType): PType =
|
|||
if instantiateDestructor(c, t.sons[0]) != nil:
|
||||
if rangeDestructorProc == nil:
|
||||
rangeDestructorProc = searchInScopes(c, getIdent"nimDestroyRange")
|
||||
t.destructor = rangeDestructorProc
|
||||
t.attachedOp[attachedDestructor] = rangeDestructorProc
|
||||
return t
|
||||
else:
|
||||
return nil
|
||||
of tyTuple, tyObject:
|
||||
t.destructor = analyzingDestructor
|
||||
t.attachedOp[attachedDestructor] = analyzingDestructor
|
||||
let generated = generateDestructor(c, t)
|
||||
if generated != nil:
|
||||
internalAssert t.sym != nil
|
||||
|
|
@ -169,10 +169,10 @@ proc instantiateDestructor(c: PContext, typ: PType): PType =
|
|||
generated
|
||||
])
|
||||
let semantizedDef = semProc(c, fullDef)
|
||||
t.destructor = semantizedDef[namePos].sym
|
||||
t.attachedOp[attachedDestructor] = semantizedDef[namePos].sym
|
||||
return t
|
||||
else:
|
||||
t.destructor = destructorIsTrivial
|
||||
t.attachedOp[attachedDestructor] = destructorIsTrivial
|
||||
return nil
|
||||
else:
|
||||
return nil
|
||||
|
|
@ -226,7 +226,7 @@ proc insertDestructors(c: PContext,
|
|||
tryStmt.addSon(
|
||||
newNode(nkFinally, info, @[
|
||||
semStmt(c, newNode(nkCall, info, @[
|
||||
useSym(destructableT.destructor),
|
||||
useSym(destructableT.attachedOp[attachedDestructor]),
|
||||
useSym(varId.sym)]))]))
|
||||
|
||||
result.outer = newNodeI(nkStmtList, info)
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ proc suggestSym*(info: TLineInfo; s: PSym) {.inline.} =
|
|||
if isServing:
|
||||
addToSourceMap(s, info)
|
||||
|
||||
proc markUsed(info: TLineInfo; s: PSym) =
|
||||
proc markUsed*(info: TLineInfo; s: PSym) =
|
||||
incl(s.flags, sfUsed)
|
||||
if {sfDeprecated, sfError} * s.flags != {}:
|
||||
if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,9 @@ proc checkFinished[T](future: PFuture[T]) =
|
|||
echo("Contents: ", future.value.repr)
|
||||
echo("<----->")
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue