Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
2b49000cbb
4 changed files with 31 additions and 24 deletions
|
|
@ -114,6 +114,16 @@ proc semConstExpr(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
include hlo, seminst, semcall
|
include hlo, seminst, semcall
|
||||||
|
|
||||||
|
proc symFromType(t: PType, info: TLineInfo): PSym =
|
||||||
|
if t.sym != nil: return t.sym
|
||||||
|
result = newSym(skType, getIdent"AnonType", t.owner, info)
|
||||||
|
result.flags.incl sfAnon
|
||||||
|
result.typ = t
|
||||||
|
|
||||||
|
proc symNodeFromType(c: PContext, t: PType, info: TLineInfo): PNode =
|
||||||
|
result = newSymNode(symFromType(t, info), info)
|
||||||
|
result.typ = makeTypeDesc(c, t)
|
||||||
|
|
||||||
proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
inc(evalTemplateCounter)
|
inc(evalTemplateCounter)
|
||||||
if evalTemplateCounter > 100:
|
if evalTemplateCounter > 100:
|
||||||
|
|
@ -133,7 +143,8 @@ proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
result = semStmt(c, result)
|
result = semStmt(c, result)
|
||||||
of tyTypeDesc:
|
of tyTypeDesc:
|
||||||
if n.kind == nkStmtList: result.kind = nkStmtListType
|
if n.kind == nkStmtList: result.kind = nkStmtListType
|
||||||
result.typ = semTypeNode(c, result, nil)
|
var typ = semTypeNode(c, result, nil)
|
||||||
|
result = symNodeFromType(c, typ, n.info)
|
||||||
else:
|
else:
|
||||||
result = semExpr(c, result)
|
result = semExpr(c, result)
|
||||||
result = fitNode(c, s.typ.sons[0], result)
|
result = fitNode(c, s.typ.sons[0], result)
|
||||||
|
|
|
||||||
|
|
@ -1573,11 +1573,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result = semExpr(c, n.sons[0], flags)
|
result = semExpr(c, n.sons[0], flags)
|
||||||
of nkTypeOfExpr:
|
of nkTypeOfExpr:
|
||||||
var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc})
|
var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc})
|
||||||
typ = makeTypedesc(c, typ)
|
result = symNodeFromType(c, typ, n.info)
|
||||||
var sym = newSym(skType, getIdent"TypeOfExpr",
|
|
||||||
typ.owner, n.info).linkTo(typ)
|
|
||||||
sym.flags.incl(sfAnon)
|
|
||||||
result = newSymNode(sym, n.info)
|
|
||||||
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit:
|
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit:
|
||||||
# check if it is an expression macro:
|
# check if it is an expression macro:
|
||||||
checkMinSonsLen(n, 1)
|
checkMinSonsLen(n, 1)
|
||||||
|
|
|
||||||
|
|
@ -142,22 +142,7 @@ proc run*(handleRequest: proc (client: TSocket, input: string,
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
# -- AsyncIO start
|
# -- AsyncIO start
|
||||||
|
proc handleAccept(sock: PAsyncSocket, s: PAsyncScgiState) =
|
||||||
proc open*(handleRequest: proc (server: var TAsyncScgiState, client: TSocket,
|
|
||||||
input: string, headers: PStringTable) {.closure.},
|
|
||||||
port = TPort(4000), address = "127.0.0.1"): PAsyncScgiState =
|
|
||||||
## Alternative of ``open`` for asyncio compatible SCGI.
|
|
||||||
new(result)
|
|
||||||
result.bufLen = 4000
|
|
||||||
result.input = newString(result.buflen) # will be reused
|
|
||||||
|
|
||||||
result.asyncServer = AsyncSocket()
|
|
||||||
bindAddr(result.asyncServer, port, address)
|
|
||||||
listen(result.asyncServer)
|
|
||||||
result.handleRequest = handleRequest
|
|
||||||
|
|
||||||
proc handleAccept(h: PObject) =
|
|
||||||
var s = PAsyncScgiState(h)
|
|
||||||
|
|
||||||
accept(getSocket(s.asyncServer), s.client)
|
accept(getSocket(s.asyncServer), s.client)
|
||||||
var L = 0
|
var L = 0
|
||||||
|
|
@ -179,6 +164,22 @@ proc handleAccept(h: PObject) =
|
||||||
|
|
||||||
s.handleRequest(s[], s.client, s.input, s.headers)
|
s.handleRequest(s[], s.client, s.input, s.headers)
|
||||||
|
|
||||||
|
proc open*(handleRequest: proc (server: var TAsyncScgiState, client: TSocket,
|
||||||
|
input: string, headers: PStringTable) {.closure.},
|
||||||
|
port = TPort(4000), address = "127.0.0.1"): PAsyncScgiState =
|
||||||
|
## Alternative of ``open`` for asyncio compatible SCGI.
|
||||||
|
var cres: PAsyncScgiState
|
||||||
|
new(cres)
|
||||||
|
cres.bufLen = 4000
|
||||||
|
cres.input = newString(cres.buflen) # will be reused
|
||||||
|
|
||||||
|
cres.asyncServer = AsyncSocket()
|
||||||
|
cres.asyncServer.handleAccept = proc (s: PAsyncSocket) = handleAccept(s, cres)
|
||||||
|
bindAddr(cres.asyncServer, port, address)
|
||||||
|
listen(cres.asyncServer)
|
||||||
|
cres.handleRequest = handleRequest
|
||||||
|
result = cres
|
||||||
|
|
||||||
proc register*(d: PDispatcher, s: PAsyncScgiState): PDelegate {.discardable.} =
|
proc register*(d: PDispatcher, s: PAsyncScgiState): PDelegate {.discardable.} =
|
||||||
## Registers ``s`` with dispatcher ``d``.
|
## Registers ``s`` with dispatcher ``d``.
|
||||||
result = d.register(s.asyncServer)
|
result = d.register(s.asyncServer)
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ template selectType(x: int): typeDesc =
|
||||||
template simpleTypeTempl: typeDesc =
|
template simpleTypeTempl: typeDesc =
|
||||||
string
|
string
|
||||||
|
|
||||||
macro typeFromMacro(s: expr): typeDesc =
|
macro typeFromMacro: typedesc = string
|
||||||
result = newIdentNode"string"
|
|
||||||
|
|
||||||
proc t1*(x: int): simpleTypeTempl() =
|
proc t1*(x: int): simpleTypeTempl() =
|
||||||
result = "test"
|
result = "test"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue