make tests green again

This commit is contained in:
Andreas Rumpf 2018-05-01 15:44:23 +02:00 • committed by Araq
commit 74fe7a800b
19 changed files with 103 additions and 103 deletions

View file

@ -40,4 +40,4 @@ proc reraiseException() {.compilerRtl.} =
proc writeStackTrace() = discard proc writeStackTrace() = discard
proc setControlCHook(hook: proc () {.noconv.} not nil) = discard proc setControlCHook(hook: proc () {.noconv.}) = discard

View file

@ -1,6 +1,6 @@
# bug #3313 # bug #3313
import unittest, future import unittest, sugar
{.experimental: "notnil".}
type type
ListNodeKind = enum ListNodeKind = enum
lnkNil, lnkCons lnkNil, lnkCons

View file

@ -3,12 +3,12 @@ template accept(x) =
template reject(x) = template reject(x) =
static: assert(not compiles(x)) static: assert(not compiles(x))
{.experimental: "notnil".}
type type
TRefObj = ref object TRefObj = ref object
x: int x: int
THasNotNils = object of TObject THasNotNils = object of RootObj
a: TRefObj not nil a: TRefObj not nil
b: TRefObj not nil b: TRefObj not nil
c: TRefObj c: TRefObj

View file

@ -15,6 +15,6 @@ type TFoo = object
converter toPtr*(some: var TFoo): ptr TFoo = (addr some) converter toPtr*(some: var TFoo): ptr TFoo = (addr some)
proc zoot(x: ptr TFoo) = nil proc zoot(x: ptr TFoo) = discard
var x: Tfoo var x: Tfoo
zoot(x) zoot(x)

View file

@ -12,7 +12,7 @@ type
EIO2 = ref object of EIO EIO2 = ref object of EIO
proc q() {.tags: [FIO].} = proc q() {.tags: [FIO].} =
nil discard
proc raiser(): int = proc raiser(): int =
writeLine stdout, "arg" writeLine stdout, "arg"

View file

@ -388,13 +388,13 @@ type
cdecl.} cdecl.}
##cp property emulators ##cp property emulators
template defGetter(otype: typedesc, memberType: typedesc, memberName: expr, procName: expr): stmt {.immediate.} = template defGetter(otype: typedesc, memberType: typedesc, memberName, procName: untyped) =
proc `get procName`*(obj: otype): memberType {.cdecl.} = proc `get procName`*(obj: otype): memberType {.cdecl.} =
return obj.memberName return obj.memberName
template defSetter(otype: typedesc, memberType: typedesc, memberName: expr, procName: expr): stmt {.immediate.} = template defSetter(otype: typedesc, memberType: typedesc, memberName, procName: untyped) =
proc `set procName`*(obj: otype, value: memberType) {.cdecl.} = proc `set procName`*(obj: otype, value: memberType) {.cdecl.} =
obj.memberName = value obj.memberName = value
template defProp(otype: typedesc, memberType: typedesc, memberName: expr, procName: expr): stmt {.immediate.} = template defProp(otype: typedesc, memberType: typedesc, memberName, procName: untyped) =
defGetter(otype, memberType, memberName, procName) defGetter(otype, memberType, memberName, procName)
defSetter(otype, memberType, memberName, procName) defSetter(otype, memberType, memberName, procName)
@ -908,7 +908,7 @@ proc getShapes*(arb: PArbiter, a, b: var PShape) {.inline.} =
#/ A macro shortcut for defining and retrieving the shapes from an arbiter. #/ A macro shortcut for defining and retrieving the shapes from an arbiter.
#define CP_ARBITER_GET_SHAPES(arb, a, b) cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b); #define CP_ARBITER_GET_SHAPES(arb, a, b) cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
template getShapes*(arb: PArbiter, name1, name2: expr): stmt {.immediate.} = template getShapes*(arb: PArbiter, name1, name2: untyped) =
var name1, name2: PShape var name1, name2: PShape
getShapes(arb, name1, name2) getShapes(arb, name1, name2)
@ -923,7 +923,7 @@ template getShapes*(arb: PArbiter, name1, name2: expr): stmt {.immediate.} =
#/ A macro shortcut for defining and retrieving the bodies from an arbiter. #/ A macro shortcut for defining and retrieving the bodies from an arbiter.
#define CP_ARBITER_GET_BODIES(arb, a, b) cpBody *a, *b; cpArbiterGetBodies(arb, &a, &b); #define CP_ARBITER_GET_BODIES(arb, a, b) cpBody *a, *b; cpArbiterGetBodies(arb, &a, &b);
template getBodies*(arb: PArbiter, name1, name2: expr): stmt {.immediate.} = template getBodies*(arb: PArbiter, name1, name2: untyped) =
var name1, name2: PBOdy var name1, name2: PBOdy
getBodies(arb, name1, name2) getBodies(arb, name1, name2)
@ -947,11 +947,11 @@ proc getDepth*(arb: PArbiter; i: cint): CpFloat {.
cdecl, importc: "cpArbiterGetDepth", dynlib: Lib.} cdecl, importc: "cpArbiterGetDepth", dynlib: Lib.}
##Shapes ##Shapes
template defShapeSetter(memberType: typedesc, memberName: expr, procName: expr, activates: bool): stmt {.immediate.} = template defShapeSetter(memberType: typedesc, memberName: untyped, procName: untyped, activates: bool) =
proc `set procName`*(obj: PShape, value: memberType) {.cdecl.} = proc `set procName`*(obj: PShape, value: memberType) {.cdecl.} =
if activates and obj.body != nil: obj.body.activate() if activates and obj.body != nil: obj.body.activate()
obj.memberName = value obj.memberName = value
template defShapeProp(memberType: typedesc, memberName: expr, procName: expr, activates: bool): stmt {.immediate.} = template defShapeProp(memberType: typedesc, memberName: untyped, procName: untyped, activates: bool) =
defGetter(PShape, memberType, memberName, procName) defGetter(PShape, memberType, memberName, procName)
defShapeSetter(memberType, memberName, procName, activates) defShapeSetter(memberType, memberName, procName, activates)
@ -1272,11 +1272,11 @@ proc activateBodies(constraint: PConstraint) {.inline.} =
# cpConstraintActivateBodies(constraint); \ # cpConstraintActivateBodies(constraint); \
# constraint->member = value; \ # constraint->member = value; \
# } # }
template defConstraintSetter(memberType: typedesc, member: expr, name: expr): stmt {.immediate.} = template defConstraintSetter(memberType: typedesc, member, name: untyped) =
proc `set name`*(constraint: PConstraint, value: memberType) {.cdecl.} = proc `set name`*(constraint: PConstraint, value: memberType) {.cdecl.} =
activateBodies(constraint) activateBodies(constraint)
constraint.member = value constraint.member = value
template defConstraintProp(memberType: typedesc, member: expr, name: expr): stmt {.immediate.} = template defConstraintProp(memberType: typedesc, member, name: untyped) =
defGetter(PConstraint, memberType, member, name) defGetter(PConstraint, memberType, member, name)
defConstraintSetter(memberType, member, name) defConstraintSetter(memberType, member, name)
# CP_DefineConstraintStructGetter(cpSpace*, CP_PRIVATE(space), Space) # CP_DefineConstraintStructGetter(cpSpace*, CP_PRIVATE(space), Space)
@ -1306,18 +1306,18 @@ proc getImpulse*(constraint: PConstraint): CpFloat {.inline.} =
# cpConstraintActivateBodies(constraint); \ # cpConstraintActivateBodies(constraint); \
# ((struct *)constraint)->member = value; \ # ((struct *)constraint)->member = value; \
# } # }
template constraintCheckCast(constraint: PConstraint, ctype: expr): stmt {.immediate.} = template constraintCheckCast(constraint: PConstraint, ctype: untyped) =
assert(constraint.klass == `ctype getClass`(), "Constraint is the wrong class") assert(constraint.klass == `ctype getClass`(), "Constraint is the wrong class")
template defCGetter(ctype: expr, memberType: typedesc, member: expr, name: expr): stmt {.immediate.} = template defCGetter(ctype: untyped, memberType: typedesc, member, name: untyped) =
proc `get ctype name`*(constraint: PConstraint): memberType {.cdecl.} = proc `get ctype name`*(constraint: PConstraint): memberType {.cdecl.} =
constraintCheckCast(constraint, ctype) constraintCheckCast(constraint, ctype)
result = cast[`P ctype`](constraint).member result = cast[`P ctype`](constraint).member
template defCSetter(ctype: expr, memberType: typedesc, member: expr, name: expr): stmt {.immediate.} = template defCSetter(ctype: untyped, memberType: typedesc, member, name: untyped) =
proc `set ctype name`*(constraint: PConstraint, value: memberType) {.cdecl.} = proc `set ctype name`*(constraint: PConstraint, value: memberType) {.cdecl.} =
constraintCheckCast(constraint, ctype) constraintCheckCast(constraint, ctype)
activateBodies(constraint) activateBodies(constraint)
cast[`P ctype`](constraint).member = value cast[`P ctype`](constraint).member = value
template defCProp(ctype: expr, memberType: typedesc, member: expr, name: expr): stmt {.immediate.} = template defCProp(ctype: untyped, memberType: typedesc, member, name: untyped) =
defCGetter(ctype, memberType, member, name) defCGetter(ctype, memberType, member, name)
defCSetter(ctype, memberType, member, name) defCSetter(ctype, memberType, member, name)

View file

@ -24,7 +24,7 @@ const
ENET_VERSION_MAJOR* = 1 ENET_VERSION_MAJOR* = 1
ENET_VERSION_MINOR* = 3 ENET_VERSION_MINOR* = 3
ENET_VERSION_PATCH* = 3 ENET_VERSION_PATCH* = 3
template ENET_VERSION_CREATE(major, minor, patch: expr): expr = template ENET_VERSION_CREATE(major, minor, patch: untyped): untyped =
(((major) shl 16) or ((minor) shl 8) or (patch)) (((major) shl 16) or ((minor) shl 8) or (patch))
const const
@ -277,22 +277,22 @@ when defined(Linux) or true:
dataLength*: csize dataLength*: csize
TENetSocketSet* = Tfd_set TENetSocketSet* = Tfd_set
## see if these are different on win32, if not then get rid of these ## see if these are different on win32, if not then get rid of these
template ENET_HOST_TO_NET_16*(value: expr): expr = template ENET_HOST_TO_NET_16*(value: untyped): untyped =
(htons(value)) (htons(value))
template ENET_HOST_TO_NET_32*(value: expr): expr = template ENET_HOST_TO_NET_32*(value: untyped): untyped =
(htonl(value)) (htonl(value))
template ENET_NET_TO_HOST_16*(value: expr): expr = template ENET_NET_TO_HOST_16*(value: untyped): untyped =
(ntohs(value)) (ntohs(value))
template ENET_NET_TO_HOST_32*(value: expr): expr = template ENET_NET_TO_HOST_32*(value: untyped): untyped =
(ntohl(value)) (ntohl(value))
template ENET_SOCKETSET_EMPTY*(sockset: expr): expr = template ENET_SOCKETSET_EMPTY*(sockset: untyped): untyped =
FD_ZERO(addr((sockset))) FD_ZERO(addr((sockset)))
template ENET_SOCKETSET_ADD*(sockset, socket: expr): expr = template ENET_SOCKETSET_ADD*(sockset, socket: untyped): untyped =
FD_SET(socket, addr((sockset))) FD_SET(socket, addr((sockset)))
template ENET_SOCKETSET_REMOVE*(sockset, socket: expr): expr = template ENET_SOCKETSET_REMOVE*(sockset, socket: untyped): untyped =
FD_CLEAR(socket, addr((sockset))) FD_CLEAR(socket, addr((sockset)))
template ENET_SOCKETSET_CHECK*(sockset, socket: expr): expr = template ENET_SOCKETSET_CHECK*(sockset, socket: untyped): untyped =
FD_ISSET(socket, addr((sockset))) FD_ISSET(socket, addr((sockset)))
when defined(Windows): when defined(Windows):
@ -606,7 +606,7 @@ proc protocolCommandSize*(commandNumber: cuchar): csize{.
{.pop.} {.pop.}
from hashes import `!$`, `!&`, THash, hash from hashes import `!$`, `!&`, Hash, hash
proc hash*(x: TAddress): THash {.nimcall, noSideEffect.} = proc hash*(x: TAddress): Hash {.nimcall, noSideEffect.} =
result = !$(hash(x.host.int32) !& hash(x.port.int16)) result = !$(hash(x.host.int32) !& hash(x.port.int16))

View file

@ -1,15 +1,15 @@
import macros, macro_dsl, estreams import macros, macro_dsl, estreams
from strutils import format from strutils import format
template newLenName(): stmt {.immediate.} = template newLenName() =
let lenName {.inject.} = ^("len"& $lenNames) let lenName {.inject.} = ^("len"& $lenNames)
inc(lenNames) inc(lenNames)
template defPacketImports*(): stmt {.immediate, dirty.} = template defPacketImports*() {.dirty.} =
import macros, macro_dsl, estreams import macros, macro_dsl, estreams
from strutils import format from strutils import format
macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = macro defPacket*(typeNameN: untyped, typeFields: untyped): untyped =
result = newNimNode(nnkStmtList) result = newNimNode(nnkStmtList)
let let
typeName = quoted2ident(typeNameN) typeName = quoted2ident(typeNameN)
@ -60,7 +60,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} =
let let
name = typeFields[i][0] name = typeFields[i][0]
dotName = packetID.dot(name) dotName = packetID.dot(name)
resName = newIdentNode(!"result").dot(name) resName = newIdentNode("result").dot(name)
case typeFields[i][1].kind case typeFields[i][1].kind
of nnkBracketExpr: #ex: paddedstring[32, '\0'], array[range, type] of nnkBracketExpr: #ex: paddedstring[32, '\0'], array[range, type]
case $typeFields[i][1][0].ident case $typeFields[i][1][0].ident
@ -141,7 +141,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} =
const emptyFields = {nnkEmpty, nnkNilLit} const emptyFields = {nnkEmpty, nnkNilLit}
var objFields = newNimNode(nnkRecList) var objFields = newNimNode(nnkRecList)
for i in 0.. < len(typeFields): for i in 0 ..< len(typeFields):
let fname = typeFields[i][0] let fname = typeFields[i][0]
constructorParams.add(newNimNode(nnkIdentDefs).und( constructorParams.add(newNimNode(nnkIdentDefs).und(
fname, fname,
@ -200,7 +200,7 @@ proc iddefs*(a: string; b: NimNode): NimNode {.compileTime.} =
proc varTy*(a: NimNode): NimNode {.compileTime.} = proc varTy*(a: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkVarTy).und(a) result = newNimNode(nnkVarTy).und(a)
macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} = macro forwardPacket*(typeName: untyped, underlyingType: untyped): untyped =
var var
packetID = ^"p" packetID = ^"p"
streamID = ^"s" streamID = ^"s"
@ -234,7 +234,7 @@ macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} =
echo "unknown type:", repr(underlyingtype) echo "unknown type:", repr(underlyingtype)
echo(repr(result)) echo(repr(result))
template forwardPacketT*(typeName: expr; underlyingType: expr): stmt {.dirty, immediate.} = template forwardPacketT*(typeName: untyped; underlyingType: untyped) {.dirty.} =
proc `read typeName`*(buffer: PBuffer): typeName = proc `read typeName`*(buffer: PBuffer): typeName =
#discard readData(s, addr result, sizeof(result)) #discard readData(s, addr result, sizeof(result))
var res: underlyingType var res: underlyingType

View file

@ -10,7 +10,7 @@ proc und*(a: NimNode; b: varargs[NimNode]): NimNode {.compileTime.} =
proc `^`*(a: string): NimNode {.compileTime.} = proc `^`*(a: string): NimNode {.compileTime.} =
## new ident node ## new ident node
result = newIdentNode(!a) result = newIdentNode(a)
proc `[]`*(a, b: NimNode): NimNode {.compileTime.} = proc `[]`*(a, b: NimNode): NimNode {.compileTime.} =
## new bracket expression: node[node] not to be confused with node[indx] ## new bracket expression: node[node] not to be confused with node[indx]
result = newNimNode(nnkBracketExpr).und(a, b) result = newNimNode(nnkBracketExpr).und(a, b)
@ -34,7 +34,7 @@ proc emptyNode*(): NimNode {.compileTime.} =
proc dot*(left, right: NimNode): NimNode {.compileTime.} = proc dot*(left, right: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkDotExpr).und(left, right) result = newNimNode(nnkDotExpr).und(left, right)
proc prefix*(a: string, b: NimNode): NimNode {.compileTime.} = proc prefix*(a: string, b: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkPrefix).und(newIdentNode(!a), b) result = newNimNode(nnkPrefix).und(newIdentNode(a), b)
proc quoted2ident*(a: NimNode): NimNode {.compileTime.} = proc quoted2ident*(a: NimNode): NimNode {.compileTime.} =
if a.kind != nnkAccQuoted: if a.kind != nnkAccQuoted:
@ -45,13 +45,13 @@ proc quoted2ident*(a: NimNode): NimNode {.compileTime.} =
result = ^pname result = ^pname
macro `?`(a: expr): expr = macro `?`(a: untyped): untyped =
## Character literal ?A #=> 'A' ## Character literal ?A #=> 'A'
result = ($a[1].ident)[0].lit result = ($a[1].ident)[0].lit
## echo(?F,?a,?t,?t,?y) ## echo(?F,?a,?t,?t,?y)
when isMainModule: when isMainModule:
macro foo(x: stmt): stmt = macro foo(x: untyped) =
result = newNimNode(nnkStmtList) result = newNimNode(nnkStmtList)
result.add(newNimNode(nnkCall).und(!!"echo", "Hello thar".lit)) result.add(newNimNode(nnkCall).und(!!"echo", "Hello thar".lit))
result.add(newCall("echo", lit("3 * 45 = "), (3.lit.infix("*", 45.lit)))) result.add(newCall("echo", lit("3 * 45 = "), (3.lit.infix("*", 45.lit))))

View file

@ -78,7 +78,7 @@ proc write*(buffer: PBuffer; val: var string) =
setLen buffer.data, buffer.pos + length.int setLen buffer.data, buffer.pos + length.int
copyMem(addr buffer.data[buffer.pos], addr val[0], length.int) copyMem(addr buffer.data[buffer.pos], addr val[0], length.int)
inc buffer.pos, length.int inc buffer.pos, length.int
proc write*[T: TNumber|bool|char|byte](buffer: PBuffer; val: T) = proc write*[T: SomeNumber|bool|char|byte](buffer: PBuffer; val: T) =
var v: T var v: T
shallowCopy v, val shallowCopy v, val
writeBE buffer, v writeBE buffer, v

View file

@ -5,8 +5,8 @@ type
TInputFinishedProc* = proc() TInputFinishedProc* = proc()
TKeyCallback = proc() TKeyCallback = proc()
PKeyClient* = ref object PKeyClient* = ref object
onKeyDown: TTable[int32, TKeyCallback] onKeyDown: Table[int32, TKeyCallback]
onKeyUp: TTable[int32, TKeyCallback] onKeyUp: Table[int32, TKeyCallback]
name: string name: string
PTextInput* = ref object PTextInput* = ref object
text*: string text*: string
@ -134,5 +134,5 @@ iterator pollEvents*(window: PRenderWindow): PEvent =
of EvtMouseButtonReleased: addButtonEvent(event.mouseButton.button, up) of EvtMouseButtonReleased: addButtonEvent(event.mouseButton.button, up)
of EvtTextEntered: recordText(activeInput, event.text) of EvtTextEntered: recordText(activeInput, event.text)
of EvtMouseMoved: setMousePos(event.mouseMove.x, event.mouseMove.y) of EvtMouseMoved: setMousePos(event.mouseMove.x, event.mouseMove.y)
else: nil else: discard
yield(addr event) yield(addr event)

View file

@ -59,7 +59,7 @@ type
of Projectile: of Projectile:
bullet*: PBulletRecord bullet*: PBulletRecord
else: else:
nil discard
PBulletRecord* = ref TBulletRecord PBulletRecord* = ref TBulletRecord
TBulletRecord* = object TBulletRecord* = object
id*: int16 id*: int16
@ -115,10 +115,10 @@ var
cfg: PZoneSettings cfg: PZoneSettings
SpriteSheets* = initTable[string, PSpriteSheet](64) SpriteSheets* = initTable[string, PSpriteSheet](64)
SoundCache * = initTable[string, PSoundRecord](64) SoundCache * = initTable[string, PSoundRecord](64)
nameToVehID*: TTable[string, int] nameToVehID*: Table[string, int]
nameToItemID*: TTable[string, int] nameToItemID*: Table[string, int]
nameToObjID*: TTable[string, int] nameToObjID*: Table[string, int]
nameToBulletID*: TTable[string, int] nameToBulletID*: Table[string, int]
activeState = Lobby activeState = Lobby
proc newSprite*(filename: string; errors: var seq[string]): PSpriteSheet proc newSprite*(filename: string; errors: var seq[string]): PSpriteSheet
@ -126,7 +126,7 @@ proc load*(ss: PSpriteSheet): bool {.discardable.}
proc newSound*(filename: string; errors: var seq[string]): PSoundRecord proc newSound*(filename: string; errors: var seq[string]): PSoundRecord
proc load*(s: PSoundRecord): bool {.discardable.} proc load*(s: PSoundRecord): bool {.discardable.}
proc validateSettings*(settings: PJsonNode; errors: var seq[string]): bool proc validateSettings*(settings: JsonNode; errors: var seq[string]): bool
proc loadSettings*(rawJson: string, errors: var seq[string]): bool proc loadSettings*(rawJson: string, errors: var seq[string]): bool
proc loadSettingsFromFile*(filename: string, errors: var seq[string]): bool proc loadSettingsFromFile*(filename: string, errors: var seq[string]): bool
@ -135,17 +135,17 @@ proc fetchItm*(itm: string): PItemRecord
proc fetchObj*(name: string): PObjectRecord proc fetchObj*(name: string): PObjectRecord
proc fetchBullet(name: string): PBulletRecord proc fetchBullet(name: string): PBulletRecord
proc importLevel(data: PJsonNode; errors: var seq[string]): PLevelSettings proc importLevel(data: JsonNode; errors: var seq[string]): PLevelSettings
proc importVeh(data: PJsonNode; errors: var seq[string]): PVehicleRecord proc importVeh(data: JsonNode; errors: var seq[string]): PVehicleRecord
proc importObject(data: PJsonNode; errors: var seq[string]): PObjectRecord proc importObject(data: JsonNode; errors: var seq[string]): PObjectRecord
proc importItem(data: PJsonNode; errors: var seq[string]): PItemRecord proc importItem(data: JsonNode; errors: var seq[string]): PItemRecord
proc importPhys(data: PJsonNode): TPhysicsRecord proc importPhys(data: JsonNode): TPhysicsRecord
proc importAnim(data: PJsonNode; errors: var seq[string]): PAnimationRecord proc importAnim(data: JsonNode; errors: var seq[string]): PAnimationRecord
proc importHandling(data: PJsonNode): THandlingRecord proc importHandling(data: JsonNode): THandlingRecord
proc importBullet(data: PJsonNode; errors: var seq[string]): PBulletRecord proc importBullet(data: JsonNode; errors: var seq[string]): PBulletRecord
proc importSoul(data: PJsonNode): TSoulRecord proc importSoul(data: JsonNode): TSoulRecord
proc importExplosion(data: PJsonNode; errors: var seq[string]): TExplosionRecord proc importExplosion(data: JsonNode; errors: var seq[string]): TExplosionRecord
proc importSound*(data: PJsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord
## this is the only pipe between lobby and main.nim ## this is the only pipe between lobby and main.nim
proc getActiveState*(): TGameState = proc getActiveState*(): TGameState =
@ -203,7 +203,7 @@ iterator playableVehicles*(): PVehicleRecord =
if v.playable: if v.playable:
yield v yield v
template allAssets*(body: stmt) {.dirty.}= template allAssets*(body: untyped) {.dirty.}=
block: block:
var assetType = FGraphics var assetType = FGraphics
for file, asset in pairs(SpriteSheets): for file, asset in pairs(SpriteSheets):
@ -212,7 +212,7 @@ template allAssets*(body: stmt) {.dirty.}=
for file, asset in pairs(SoundCache): for file, asset in pairs(SoundCache):
body body
template cacheImpl(procName, cacheName, resultType: expr; body: stmt) {.dirty, immediate.} = template cacheImpl(procName, cacheName, resultType, body: untyped) {.dirty.} =
proc procName*(filename: string; errors: var seq[string]): resulttype = proc procName*(filename: string; errors: var seq[string]): resulttype =
if hasKey(cacheName, filename): if hasKey(cacheName, filename):
return cacheName[filename] return cacheName[filename]
@ -220,7 +220,7 @@ template cacheImpl(procName, cacheName, resultType: expr; body: stmt) {.dirty, i
body body
cacheName[filename] = result cacheName[filename] = result
template checkFile(path: expr): stmt {.dirty, immediate.} = template checkFile(path: untyped) {.dirty.} =
if not existsFile(path): if not existsFile(path):
errors.add("File missing: "& path) errors.add("File missing: "& path)
@ -243,7 +243,7 @@ proc expandPath*(assetType: TAssetType; fileName: string): string =
case assetType case assetType
of FGraphics: result.add "gfx/" of FGraphics: result.add "gfx/"
of FSound: result.add "sfx/" of FSound: result.add "sfx/"
else: nil else: discard
result.add fileName result.add fileName
proc expandPath*(fc: ScFileChallenge): string {.inline.} = proc expandPath*(fc: ScFileChallenge): string {.inline.} =
result = expandPath(fc.assetType, fc.file) result = expandPath(fc.assetType, fc.file)
@ -280,10 +280,10 @@ else:
if not s.soundBuf.isNil: if not s.soundBuf.isNil:
result = true result = true
template addError(e: expr): stmt {.immediate.} = template addError(e: untyped) =
errors.add(e) errors.add(e)
result = false result = false
proc validateSettings*(settings: PJsonNode, errors: var seq[string]): bool = proc validateSettings*(settings: JsonNode, errors: var seq[string]): bool =
result = true result = true
if settings.kind != JObject: if settings.kind != JObject:
addError("Settings root must be an object") addError("Settings root must be an object")
@ -328,10 +328,10 @@ proc loadSettingsFromFile*(filename: string, errors: var seq[string]): bool =
result = loadSettings(readFile(filename), errors) result = loadSettings(readFile(filename), errors)
proc loadSettings*(rawJson: string, errors: var seq[string]): bool = proc loadSettings*(rawJson: string, errors: var seq[string]): bool =
var settings: PJsonNode var settings: JsonNode
try: try:
settings = parseJson(rawJson) settings = parseJson(rawJson)
except EJsonParsingError: except JsonParsingError:
errors.add("JSON parsing error: "& getCurrentExceptionMsg()) errors.add("JSON parsing error: "& getCurrentExceptionMsg())
return return
except: except:
@ -407,21 +407,21 @@ proc fetchObj*(name: string): PObjectRecord =
proc fetchBullet(name: string): PBulletRecord = proc fetchBullet(name: string): PBulletRecord =
return cfg.bullets[nameToBulletID[name]] return cfg.bullets[nameToBulletID[name]]
proc getField(node: PJsonNode, field: string, target: var float) = proc getField(node: JsonNode, field: string, target: var float) =
if not node.hasKey(field): if not node.hasKey(field):
return return
if node[field].kind == JFloat: if node[field].kind == JFloat:
target = node[field].fnum target = node[field].fnum
elif node[field].kind == JInt: elif node[field].kind == JInt:
target = node[field].num.float target = node[field].num.float
proc getField(node: PJsonNode, field: string, target: var int) = proc getField(node: JsonNode, field: string, target: var int) =
if not node.hasKey(field): if not node.hasKey(field):
return return
if node[field].kind == JInt: if node[field].kind == JInt:
target = node[field].num.int target = node[field].num.int
elif node[field].kind == JFloat: elif node[field].kind == JFloat:
target = node[field].fnum.int target = node[field].fnum.int
proc getField(node: PJsonNode; field: string; target: var bool) = proc getField(node: JsonNode; field: string; target: var bool) =
if not node.hasKey(field): if not node.hasKey(field):
return return
case node[field].kind case node[field].kind
@ -431,19 +431,19 @@ proc getField(node: PJsonNode; field: string; target: var bool) =
target = (node[field].num != 0) target = (node[field].num != 0)
of JFloat: of JFloat:
target = (node[field].fnum != 0.0) target = (node[field].fnum != 0.0)
else: nil else: discard
template checkKey(node: expr; key: string): stmt = template checkKey(node: untyped; key: string) =
if not hasKey(node, key): if not hasKey(node, key):
return return
proc importTrail(data: PJsonNode; errors: var seq[string]): TTrailRecord = proc importTrail(data: JsonNode; errors: var seq[string]): TTrailRecord =
checkKey(data, "trail") checkKey(data, "trail")
result.anim = importAnim(data["trail"], errors) result.anim = importAnim(data["trail"], errors)
result.timer = 1000.0 result.timer = 1000.0
getField(data["trail"], "timer", result.timer) getField(data["trail"], "timer", result.timer)
result.timer /= 1000.0 result.timer /= 1000.0
proc importLevel(data: PJsonNode; errors: var seq[string]): PLevelSettings = proc importLevel(data: JsonNode; errors: var seq[string]): PLevelSettings =
new(result) new(result)
result.size = vec2i(5000, 5000) result.size = vec2i(5000, 5000)
result.starfield = @[] result.starfield = @[]
@ -456,7 +456,7 @@ proc importLevel(data: PJsonNode; errors: var seq[string]): PLevelSettings =
if level.hasKey("starfield"): if level.hasKey("starfield"):
for star in level["starfield"].items: for star in level["starfield"].items:
result.starfield.add(newSprite(star.str, errors)) result.starfield.add(newSprite(star.str, errors))
proc importPhys(data: PJsonNode): TPhysicsRecord = proc importPhys(data: JsonNode): TPhysicsRecord =
result.radius = 20.0 result.radius = 20.0
result.mass = 10.0 result.mass = 10.0
@ -466,7 +466,7 @@ proc importPhys(data: PJsonNode): TPhysicsRecord =
phys.getField("mass", result.mass) phys.getField("mass", result.mass)
when not defined(NoChipmunk): when not defined(NoChipmunk):
result.moment = momentForCircle(result.mass, 0.0, result.radius, VectorZero) * MomentMult result.moment = momentForCircle(result.mass, 0.0, result.radius, VectorZero) * MomentMult
proc importHandling(data: PJsonNode): THandlingRecord = proc importHandling(data: JsonNode): THandlingRecord =
result.thrust = 45.0 result.thrust = 45.0
result.topSpeed = 100.0 #unused result.topSpeed = 100.0 #unused
result.reverse = 30.0 result.reverse = 30.0
@ -483,7 +483,7 @@ proc importHandling(data: PJsonNode): THandlingRecord =
hand.getField("reverse", result.reverse) hand.getField("reverse", result.reverse)
hand.getField("strafe", result.strafe) hand.getField("strafe", result.strafe)
hand.getField("rotation", result.rotation) hand.getField("rotation", result.rotation)
proc importAnim(data: PJsonNode, errors: var seq[string]): PAnimationRecord = proc importAnim(data: JsonNode, errors: var seq[string]): PAnimationRecord =
new(result) new(result)
result.angle = 0.0 result.angle = 0.0
result.delay = 1000.0 result.delay = 1000.0
@ -502,26 +502,26 @@ proc importAnim(data: PJsonNode, errors: var seq[string]): PAnimationRecord =
result.angle = radians(result.angle) ## comes in as degrees result.angle = radians(result.angle) ## comes in as degrees
result.delay /= 1000 ## delay comes in as milliseconds result.delay /= 1000 ## delay comes in as milliseconds
proc importSoul(data: PJsonNode): TSoulRecord = proc importSoul(data: JsonNode): TSoulRecord =
result.energy = 10000 result.energy = 10000
result.health = 1 result.health = 1
checkKey(data, "soul") checkKey(data, "soul")
let soul = data["soul"] let soul = data["soul"]
soul.getField("energy", result.energy) soul.getField("energy", result.energy)
soul.getField("health", result.health) soul.getField("health", result.health)
proc importExplosion(data: PJsonNode; errors: var seq[string]): TExplosionRecord = proc importExplosion(data: JsonNode; errors: var seq[string]): TExplosionRecord =
checkKey(data, "explode") checkKey(data, "explode")
let expl = data["explode"] let expl = data["explode"]
result.anim = importAnim(expl, errors) result.anim = importAnim(expl, errors)
result.sound = importSound(expl, errors, "sound") result.sound = importSound(expl, errors, "sound")
proc importSound*(data: PJsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord = proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord =
if data.kind == JObject: if data.kind == JObject:
checkKey(data, fieldName) checkKey(data, fieldName)
result = newSound(data[fieldName].str, errors) result = newSound(data[fieldName].str, errors)
elif data.kind == JString: elif data.kind == JString:
result = newSound(data.str, errors) result = newSound(data.str, errors)
proc importVeh(data: PJsonNode; errors: var seq[string]): PVehicleRecord = proc importVeh(data: JsonNode; errors: var seq[string]): PVehicleRecord =
new(result) new(result)
result.playable = false result.playable = false
if data.kind != JArray or data.len != 2 or if data.kind != JArray or data.len != 2 or
@ -538,7 +538,7 @@ proc importVeh(data: PJsonNode; errors: var seq[string]): PVehicleRecord =
vehdata.getField("playable", result.playable) vehdata.getField("playable", result.playable)
if result.anim.spriteSheet.isNil and result.playable: if result.anim.spriteSheet.isNil and result.playable:
result.playable = false result.playable = false
proc importObject(data: PJsonNode; errors: var seq[string]): PObjectRecord = proc importObject(data: JsonNode; errors: var seq[string]): PObjectRecord =
new(result) new(result)
if data.kind != JArray or data.len != 2: if data.kind != JArray or data.len != 2:
result.name = "(broken)" result.name = "(broken)"
@ -546,7 +546,7 @@ proc importObject(data: PJsonNode; errors: var seq[string]): PObjectRecord =
result.name = data[0].str result.name = data[0].str
result.anim = importAnim(data[1], errors) result.anim = importAnim(data[1], errors)
result.physics = importPhys(data[1]) result.physics = importPhys(data[1])
proc importItem(data: PJsonNode; errors: var seq[string]): PItemRecord = proc importItem(data: JsonNode; errors: var seq[string]): PItemRecord =
new(result) new(result)
if data.kind != JArray or data.len != 3: if data.kind != JArray or data.len != 3:
result.name = "(broken)" result.name = "(broken)"
@ -576,15 +576,15 @@ proc importItem(data: PJsonNode; errors: var seq[string]): PItemRecord =
of "ammo": of "ammo":
result.kind = Ammo result.kind = Ammo
of "utility": of "utility":
nil discard
else: else:
errors.add "Invalid item type \""&data[1].str&"\" for item "&result.name errors.add "Invalid item type \""&data[1].str&"\" for item "&result.name
proc importBullet(data: PJsonNode; errors: var seq[string]): PBulletRecord = proc importBullet(data: JsonNode; errors: var seq[string]): PBulletRecord =
new(result) new(result)
result.id = -1 result.id = -1
var bdata: PJsonNode var bdata: JsonNode
if data.kind == JArray: if data.kind == JArray:
result.name = data[0].str result.name = data[0].str
bdata = data[1] bdata = data[1]

View file

@ -4,14 +4,14 @@ defPacketImports()
type type
PacketID* = char PacketID* = char
template idpacket(pktName, id, s2c, c2s: expr): stmt {.immediate, dirty.} = template idpacket(pktName, id, s2c, c2s: untyped) {.dirty.} =
let `H pktName`* {.inject.} = id let `H pktName`* {.inject.} = id
defPacket(`Sc pktName`, s2c) defPacket(`Sc pktName`, s2c)
defPacket(`Cs pktName`, c2s) defPacket(`Cs pktName`, c2s)
forwardPacketT(uint8, int8) forwardPacketT(uint8, int8)
forwardPacketT(uint16, int16) forwardPacketT(uint16, int16)
forwardPacketT(TPort, int16) forwardPacketT(Port, int16)
idPacket(Login, 'a', idPacket(Login, 'a',
tuple[id: int32; alias: string; sessionKey: string], tuple[id: int32; alias: string; sessionKey: string],
@ -22,7 +22,7 @@ defPacket(CsZoneJoinReq, tuple[session: ScLogin])
defPacket(ScZoneRecord, tuple[ defPacket(ScZoneRecord, tuple[
name: string = "", desc: string = "", name: string = "", desc: string = "",
ip: string = "", port: TPort = 0.Tport]) ip: string = "", port: Port = 0.Port])
idPacket(ZoneList, 'z', idPacket(ZoneList, 'z',
tuple[network: string = "", zones: seq[ScZoneRecord]], tuple[network: string = "", zones: seq[ScZoneRecord]],
tuple[time: string]) tuple[time: string])

View file

@ -46,7 +46,7 @@ type
type1 = typedesc type1 = typedesc
type2 = typedesc type2 = typedesc
proc typePairs(A, B: type1; C, D: type2) = nil proc typePairs(A, B: type1; C, D: type2) = discard
accept typePairs(int, int, TFoo, TFOO) accept typePairs(int, int, TFoo, TFOO)
accept typePairs(TBAR, TBar, TBAR, TBAR) accept typePairs(TBAR, TBar, TBAR, TBAR)
@ -55,7 +55,7 @@ accept typePairs(int, int, string, string)
reject typePairs(TBAR, TBar, TBar, TFoo) reject typePairs(TBAR, TBar, TBar, TFoo)
reject typePairs(string, int, TBAR, TBAR) reject typePairs(string, int, TBAR, TBAR)
proc typePairs2[T: typedesc, U: typedesc](A, B: T; C, D: U) = nil proc typePairs2[T: typedesc, U: typedesc](A, B: T; C, D: U) = discard
accept typePairs2(int, int, TFoo, TFOO) accept typePairs2(int, int, TFoo, TFOO)
accept typePairs2(TBAR, TBar, TBAR, TBAR) accept typePairs2(TBAR, TBar, TBAR, TBAR)
@ -71,12 +71,12 @@ proc dontBind(a: typedesc, b: typedesc) =
accept dontBind(int, float) accept dontBind(int, float)
accept dontBind(TFoo, TFoo) accept dontBind(TFoo, TFoo)
proc dontBind2(a, b: typedesc) = nil proc dontBind2(a, b: typedesc) = discard
accept dontBind2(int, float) accept dontBind2(int, float)
accept dontBind2(TBar, int) accept dontBind2(TBar, int)
proc bindArg(T: typedesc, U: typedesc, a, b: T, c, d: U) = nil proc bindArg(T: typedesc, U: typedesc, a, b: T, c, d: U) = discard
accept bindArg(int, string, 10, 20, "test", "nest") accept bindArg(int, string, 10, 20, "test", "nest")
accept bindArg(int, int, 10, 20, 30, 40) accept bindArg(int, int, 10, 20, 30, 40)

View file

@ -11,7 +11,7 @@ type
x, y: int x, y: int
proc q(x: pointer not nil) = proc q(x: pointer not nil) =
nil discard
proc p() = proc p() =
var x: pointer var x: pointer

View file

@ -6,7 +6,7 @@ discard """
import strutils import strutils
{.warning[ProveField]: on.} {.warning[ProveField]: on.}
{.experimental: "notnil".}
type type
TNodeKind = enum TNodeKind = enum
nkBinary, nkTernary, nkStr nkBinary, nkTernary, nkStr

View file

@ -5,7 +5,7 @@ discard """
type type
PTest = ref object PTest = ref object
proc test(x: PTest, y: int) = nil proc test(x: PTest, y: int) = discard
var buf: PTest var buf: PTest
buf.test() buf.test()

View file

@ -4,6 +4,6 @@ discard """
errormsg: "redefinition of \'foo\'" errormsg: "redefinition of \'foo\'"
""" """
proc foo(a: int, b: string) = nil proc foo(a: int, b: string) = discard
proc foo(a: int, b: string) = nil proc foo(a: int, b: string) = discard

View file

@ -7,7 +7,7 @@ type
TRange = range[0..40] TRange = range[0..40]
proc p(r: TRange) = proc p(r: TRange) =
nil discard
var var
r: TRange r: TRange