macros: take multiple arguments at assert

The assertion record may have multiple fields, so take multiple
arguments.
This commit is contained in:
Emery Hemingway 2021-06-30 12:23:04 +02:00
parent 50afa0107f
commit 3de97c5cf1
1 changed files with 14 additions and 2 deletions

View File

@ -156,11 +156,23 @@ macro onRetracted*(class: static[RecordClass]; doHandler: untyped) =
macro onMessage*(class: static[RecordClass]; doHandler: untyped) =
onEvent(messageEvent, class, doHandler)
template assert*(class: RecordClass; field: untyped): untyped =
template onStart*(body: untyped): untyped =
mixin getCurrentFacet
getCurrentFacet().addStartScript do (facet: Facet):
proc getCurrentFacet(): Facet {.inject, used.} = facet
body
template onStop*(body: untyped): untyped =
mixin getCurrentFacet
getCurrentFacet().addStopScript do (facet: Facet):
proc getCurrentFacet(): Facet {.inject, used.} = facet
body
template assert*(class: RecordClass; fields: varargs[Preserve, toPreserve]): untyped =
mixin getCurrentFacet
let facet = getCurrentFacet()
discard facet.addEndpoint do (_: Facet) -> EndpointSpec:
let a = init(class, getPreserve(field))
let a = init(class, fields)
result.assertion = some(a)
template field*(F: untyped; T: typedesc; initial: T): untyped =