mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 15:01:24 +00:00
syntax compatibility between do blocks and stmt blocks
See the section `do notation` in the manual for more info. * nkMacroStmt has been removed Macro statements are now mapped to regular nkCall nodes. The support for additional clauses (such as else, except, of, etc) have been restored - they will now appear as additional arguments for the nkCall node (as nkElse, nkExcept, etc nodes) * fixed some regressions in the `is` operator and semCompiles
This commit is contained in:
@@ -38,7 +38,7 @@ type
|
||||
nnkFastAsgn, nnkGenericParams, nnkFormalParams, nnkOfInherit,
|
||||
nnkModule, nnkProcDef, nnkMethodDef, nnkConverterDef,
|
||||
nnkMacroDef, nnkTemplateDef, nnkIteratorDef, nnkOfBranch,
|
||||
nnkElifBranch, nnkExceptBranch, nnkElse, nnkMacroStmt,
|
||||
nnkElifBranch, nnkExceptBranch, nnkElse,
|
||||
nnkAsmStmt, nnkPragma, nnkPragmaBlock, nnkIfStmt, nnkWhenStmt,
|
||||
nnkForStmt, nnkParForStmt, nnkWhileStmt, nnkCaseStmt,
|
||||
nnkTypeSection, nnkVarSection, nnkLetSection, nnkConstSection,
|
||||
|
||||
@@ -22,7 +22,7 @@ type
|
||||
|
||||
PSurface* = ref TSurface ## a surface to draw onto
|
||||
TSurface* {.pure, final.} = object
|
||||
w*, h*: int
|
||||
w*, h*: Natural
|
||||
s*: sdl.PSurface
|
||||
|
||||
EGraphics* = object of EIO
|
||||
|
||||
@@ -940,7 +940,7 @@ proc readIntoBuf(socket: TSocket, flags: int32): int =
|
||||
socket.currPos = 0
|
||||
|
||||
template retRead(flags, readBytes: int) =
|
||||
let res = socket.readIntoBuf(flags)
|
||||
let res = socket.readIntoBuf(flags.int32)
|
||||
if res <= 0:
|
||||
if readBytes > 0:
|
||||
return readBytes
|
||||
|
||||
@@ -151,7 +151,7 @@ template require*(conditions: stmt): stmt {.immediate, dirty.} =
|
||||
const AbortOnError {.inject.} = true
|
||||
check conditions
|
||||
|
||||
macro expect*(exp: stmt): stmt {.immediate.} =
|
||||
macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} =
|
||||
let exp = callsite()
|
||||
template expectBody(errorTypes, lineInfoLit: expr,
|
||||
body: stmt): PNimrodNode {.dirty.} =
|
||||
@@ -162,12 +162,11 @@ macro expect*(exp: stmt): stmt {.immediate.} =
|
||||
except errorTypes:
|
||||
nil
|
||||
|
||||
var expectCall = exp[0]
|
||||
var body = exp[1]
|
||||
|
||||
var body = exp[exp.len - 1]
|
||||
|
||||
var errorTypes = newNimNode(nnkBracket)
|
||||
for i in countup(1, expectCall.len - 1):
|
||||
errorTypes.add(expectCall[i])
|
||||
for i in countup(1, exp.len - 2):
|
||||
errorTypes.add(exp[i])
|
||||
|
||||
result = getAst(expectBody(errorTypes, exp.lineinfo, body))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user