diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/destructor/tarc3.nim | 21 | ||||
-rw-r--r-- | tests/misc/tsizeof.nim | 17 |
2 files changed, 30 insertions, 8 deletions
diff --git a/tests/destructor/tarc3.nim b/tests/destructor/tarc3.nim index 1ca4c70e9..d3b9639ad 100644 --- a/tests/destructor/tarc3.nim +++ b/tests/destructor/tarc3.nim @@ -4,7 +4,7 @@ discard """ """ when defined(cpp): - {.passC: "-std=gnu++17".} + {.passC: "-std=gnu++2a".} type TokenKind* = enum @@ -24,6 +24,23 @@ type else: discard pos*: Natural + + Token2* = object + case kind*: TokenKind + of tkString: strVal*: string + of tkNumber: numVal*: float + of tkInt64, tkColon..tkComma: + str1*: array[2, string] + float: float + else: discard + pos*: Natural + + Token3* = object + case kind*: TokenKind + of tkNumber: numVal*: float + of tkInt64, tkComma..tkString: ff: seq[float] + else: str1*: string + BaseLexer* = object of RootObj input*: string pos*: Natural @@ -39,6 +56,8 @@ type Parser[T: Lexer] = object l: T tok: Token + tok2: Token2 + tok3: Token3 allowTrailingComma: bool allowIdentifierObjectKey: bool diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index a2a9fe59e..7b92d3639 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -74,20 +74,23 @@ proc strAlign(arg: string): string = for i in 0 ..< minLen - arg.len: result &= ' ' -macro c_offsetof(a: typed, b: untyped): int32 = +macro c_offsetof(fieldAccess: typed): int32 = ## Bullet proof implementation that works on actual offsetof operator ## in the c backend. Assuming of course this implementation is ## correct. - let bliteral = - if b.kind == nnkStrLit: - b - else: - newLit(repr(b)) + let s = if fieldAccess.kind == nnkCheckedFieldExpr: fieldAccess[0] + else: fieldAccess + let a = s[0].getTypeInst + let b = s[1] result = quote do: var res: int32 - {.emit: [res, " = offsetof(", `a`, ", ", `bliteral`, ");"] .} + {.emit: [res, " = offsetof(", `a`, ", ", `b`, ");"] .} res +template c_offsetof(t: typedesc, a: untyped): int32 = + var x: ptr t + c_offsetof(x[].a) + macro c_sizeof(a: typed): int32 = ## Bullet proof implementation that works using the sizeof operator ## in the c backend. Assuming of course this implementation is |