preparations for making 'closure' the default calling convention for proc types
This commit is contained in:
parent
56b4e3ad91
commit
8d99753d63
36 changed files with 117 additions and 102 deletions
|
|
@ -56,7 +56,7 @@ const
|
|||
onlySafeCode = true
|
||||
|
||||
proc merge[T](a, b: var openArray[T], lo, m, hi: int,
|
||||
cmp: proc (x, y: T): int, order: TSortOrder) =
|
||||
cmp: proc (x, y: T): int {.closure.}, order: TSortOrder) =
|
||||
template `<-` (a, b: expr) =
|
||||
when false:
|
||||
a = b
|
||||
|
|
@ -102,7 +102,7 @@ proc merge[T](a, b: var openArray[T], lo, m, hi: int,
|
|||
if k < j: copyMem(addr(a[k]), addr(b[i]), sizeof(T)*(j-k))
|
||||
|
||||
proc sort*[T](a: var openArray[T],
|
||||
cmp: proc (x, y: T): int,
|
||||
cmp: proc (x, y: T): int {.closure.},
|
||||
order = TSortOrder.Ascending) =
|
||||
## Default Nimrod sort. The sorting is guaranteed to be stable and
|
||||
## the worst case is guaranteed to be O(n log n).
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ type
|
|||
TDelegate = object
|
||||
deleVal*: PObject
|
||||
|
||||
handleRead*: proc (h: PObject)
|
||||
handleWrite*: proc (h: PObject)
|
||||
handleConnect*: proc (h: PObject)
|
||||
handleRead*: proc (h: PObject) {.nimcall.}
|
||||
handleWrite*: proc (h: PObject) {.nimcall.}
|
||||
handleConnect*: proc (h: PObject) {.nimcall.}
|
||||
|
||||
handleAccept*: proc (h: PObject)
|
||||
getSocket*: proc (h: PObject): tuple[info: TInfo, sock: TSocket]
|
||||
handleAccept*: proc (h: PObject) {.nimcall.}
|
||||
getSocket*: proc (h: PObject): tuple[info: TInfo, sock: TSocket] {.nimcall.}
|
||||
|
||||
task*: proc (h: PObject)
|
||||
task*: proc (h: PObject) {.nimcall.}
|
||||
mode*: TMode
|
||||
|
||||
PDelegate* = ref TDelegate
|
||||
|
|
@ -56,10 +56,10 @@ type
|
|||
|
||||
userArg: PObject
|
||||
|
||||
handleRead*: proc (s: PAsyncSocket, arg: PObject)
|
||||
handleConnect*: proc (s: PAsyncSocket, arg: PObject)
|
||||
handleRead*: proc (s: PAsyncSocket, arg: PObject) {.nimcall.}
|
||||
handleConnect*: proc (s: PAsyncSocket, arg: PObject) {.nimcall.}
|
||||
|
||||
handleAccept*: proc (s: PAsyncSocket, arg: PObject)
|
||||
handleAccept*: proc (s: PAsyncSocket, arg: PObject) {.nimcall.}
|
||||
|
||||
lineBuffer: TaintedString ## Temporary storage for ``recvLine``
|
||||
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ proc zip*[S, T](seq1: seq[S], seq2: seq[T]): seq[tuple[a: S, b: T]] =
|
|||
newSeq(result, m)
|
||||
for i in 0 .. m-1: result[i] = (seq1[i], seq2[i])
|
||||
|
||||
iterator filter*[T](seq1: seq[T], pred: proc(item: T): bool): T =
|
||||
iterator filter*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): T =
|
||||
## Iterates through a sequence and yields every item that fulfills the
|
||||
## predicate.
|
||||
for i in countup(0, len(seq1) -1):
|
||||
var item = seq1[i]
|
||||
if pred(item): yield seq1[i]
|
||||
|
||||
proc filter*[T](seq1: seq[T], pred: proc(item: T): bool): seq[T] =
|
||||
proc filter*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): seq[T] =
|
||||
## Returns all items in a sequence that fulfilled the predicate.
|
||||
accumulateResult(filter(seq1, pred))
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@
|
|||
##
|
||||
## This module implements an event system that is not dependant on external
|
||||
## graphical toolkits. It was originally called ``NimEE`` because
|
||||
## it was inspired by Python's PyEE module. There are two ways you can use events: one is a python-inspired way; the other is more of a C-style way.
|
||||
## it was inspired by Python's PyEE module. There are two ways you can use
|
||||
## events: one is a python-inspired way; the other is more of a C-style way.
|
||||
##
|
||||
## .. code-block:: Nimrod
|
||||
## var ee = initEventEmitter()
|
||||
|
|
@ -44,22 +45,21 @@ type
|
|||
|
||||
proc initEventHandler*(name: string): TEventHandler =
|
||||
## Initializes an EventHandler with the specified name and returns it.
|
||||
#new(result)
|
||||
result.handlers = @[]
|
||||
result.name = name
|
||||
|
||||
proc addHandler*(handler: var TEventHandler, func: proc(e: TEventArgs)) =
|
||||
proc addHandler*(handler: var TEventHandler, func: proc(e: TEventArgs) {.closure.}) =
|
||||
## Adds the callback to the specified event handler.
|
||||
handler.handlers.add(func)
|
||||
|
||||
proc removeHandler*(handler: var TEventHandler, func: proc(e: TEventArgs)) =
|
||||
proc removeHandler*(handler: var TEventHandler, func: proc(e: TEventArgs) {.closure.}) =
|
||||
## Removes the callback from the specified event handler.
|
||||
for i in countup(0, len(handler.handlers) -1):
|
||||
if func == handler.handlers[i]:
|
||||
handler.handlers.del(i)
|
||||
break
|
||||
|
||||
proc containsHandler*(handler: var TEventHandler, func: proc(e: TEventArgs)): bool =
|
||||
proc containsHandler*(handler: var TEventHandler, func: proc(e: TEventArgs) {.closure.}): bool =
|
||||
## Checks if a callback is registered to this event handler.
|
||||
return handler.handlers.contains(func)
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ proc getEventhandler(emitter: var TEventEmitter, event: string): int =
|
|||
if emitter.s[k].name == event: return k
|
||||
return -1
|
||||
|
||||
proc on*(emitter: var TEventEmitter, event: string, func: proc(e: TEventArgs)) =
|
||||
proc on*(emitter: var TEventEmitter, event: string, func: proc(e: TEventArgs) {.closure.}) =
|
||||
## Assigns a event handler with the specified callback. If the event
|
||||
## doesn't exist, it will be created.
|
||||
var i = getEventHandler(emitter, event)
|
||||
|
|
@ -99,5 +99,4 @@ proc emit*(emitter: var TEventEmitter, event: string, args: TEventArgs) =
|
|||
|
||||
proc initEventEmitter*(): TEventEmitter =
|
||||
## Creates and returns a new EventEmitter.
|
||||
#new(result)
|
||||
result.s = @[]
|
||||
|
|
|
|||
|
|
@ -347,7 +347,8 @@ proc close*(s: TServer) =
|
|||
## closes the server (and the socket the server uses).
|
||||
close(s.socket)
|
||||
|
||||
proc run*(handleRequest: proc (client: TSocket, path, query: string): bool,
|
||||
proc run*(handleRequest: proc (client: TSocket,
|
||||
path, query: string): bool {.closure.},
|
||||
port = TPort(80)) =
|
||||
## encapsulates the server object and main loop
|
||||
var s: TServer
|
||||
|
|
|
|||
|
|
@ -23,13 +23,14 @@ type
|
|||
## here shouldn't be used directly. They are
|
||||
## accessible so that a stream implementation
|
||||
## can override them.
|
||||
closeImpl*: proc (s: PStream)
|
||||
atEndImpl*: proc (s: PStream): bool
|
||||
setPositionImpl*: proc (s: PStream, pos: int)
|
||||
getPositionImpl*: proc (s: PStream): int
|
||||
readDataImpl*: proc (s: PStream, buffer: pointer, bufLen: int): int
|
||||
writeDataImpl*: proc (s: PStream, buffer: pointer, bufLen: int)
|
||||
flushImpl*: proc (s: PStream)
|
||||
closeImpl*: proc (s: PStream) {.nimcall.}
|
||||
atEndImpl*: proc (s: PStream): bool {.nimcall.}
|
||||
setPositionImpl*: proc (s: PStream, pos: int) {.nimcall.}
|
||||
getPositionImpl*: proc (s: PStream): int {.nimcall.}
|
||||
readDataImpl*: proc (s: PStream, buffer: pointer,
|
||||
bufLen: int): int {.nimcall.}
|
||||
writeDataImpl*: proc (s: PStream, buffer: pointer, bufLen: int) {.nimcall.}
|
||||
flushImpl*: proc (s: PStream) {.nimcall.}
|
||||
|
||||
proc flush*(s: PStream) =
|
||||
## flushes the buffers that the stream `s` might use.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue