-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] All lang specification tests pass locally
- Loading branch information
1 parent
be7ae6d
commit 35f52bc
Showing
20 changed files
with
307 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int c_compiled_only(int arg) { return arg * 2; } | ||
|
||
#ifdef NIM_DEFINED_FLAG | ||
int c_in_define() { return 228; }; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,49 @@ | ||
{.compile: "t01_c_implementation.c".} | ||
{.compile("t01_c_implementation.c", "-DNIM_DEFINED_FLAG").} | ||
|
||
const h = "t01_c_header.h" | ||
|
||
|
||
block wrap_void_proc: | ||
proc cVoid() {.importc: "c_void", header: "t01_c_header.h".} | ||
|
||
block wrap_prec_with_value: | ||
proc c_return_int(): cint {.importc, header: h.} | ||
|
||
doAssert c_return_int() == 12 | ||
|
||
block wrap_variadic_c_function: | ||
proc sumVariadic(count: cint): cint {.importc: "c_sum_variadic", varargs, header: h.} | ||
|
||
doAssert sumVariadic(2, 3, 1) == 3 + 1 | ||
doAssert sumVariadic(3, 0, 0, 0) == 0 + 0 + 0 | ||
|
||
block wrap_struct_with_no_typedef: | ||
type | ||
NoTypedef {.importc: "struct NoTypedef".} = object | ||
field1: cint | ||
field2: cint | ||
field3 {.importc: "__field3".}: cint | ||
|
||
proc returnNoTypedef(f1, f2, f3: cint): NoTypedef {.importc: "c_return_no_typedef", header: h.} | ||
|
||
let res = returnNoTypedef(1, 2, 3) | ||
|
||
doAssert res.field1 == 1 | ||
doAssert res.field2 == 2 | ||
doAssert res.field3 == 3 | ||
|
||
block wrap_proc_without_header: | ||
proc compileOnly(arg: cint): cint {.importc: "c_compiled_only".} | ||
|
||
doAssert compileOnly(1) == 1 * 2 | ||
|
||
proc inDefine(): cint {.importc: "c_in_define".} | ||
|
||
doAssert inDefine() == 228 | ||
|
||
block wrap_typedefed_struct: | ||
type | ||
WithTypedef {.importc.} = object | ||
field1: cint | ||
field2: cint | ||
field3 {.importc: "__field3".}: cint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
block emit_type: | ||
{.emit: """/*TYPESECTION*/ | ||
struct CStruct { int field; }; | ||
""".} | ||
|
||
type | ||
CStruct {.importc: "struct CStruct".} = object | ||
field: cint | ||
|
||
|
||
var struct = CStruct() | ||
struct.field = 12 | ||
|
||
block interpolate_variables: | ||
proc impl() = | ||
var nimValue: cint = 0 | ||
|
||
doAssert nimValue == 0 | ||
{.emit: [nimValue, " += 2;"].} | ||
|
||
doAssert nimValue == 2 | ||
|
||
{.emit: "`nimValue` += 2;".} | ||
doAssert nimValue == 4 | ||
|
||
impl() |
2 changes: 1 addition & 1 deletion
2
tests/lang/s05_pragmas/s04_misc/readme.md → tests/lang/s05_pragmas/s02_misc/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
This section contains specification of pragmas that cannot be characterized as | ||
purely "interop", "object" or "procedure"-related. | ||
purely "interop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
discard """ | ||
description: ''' | ||
Test pragma annotations that can be used on identifier declaratios. | ||
''' | ||
cmd: "nim c -r -d:strdefineUsed='test' -d:intdefineUsed=2 -d:booldefineUsed=false $options $file" | ||
""" | ||
|
||
## It is possible to put pragma annotations on different variable declarations. | ||
|
||
block const_define: | ||
const strdefineDefault {.strdefine.} = "default value" | ||
const strdefineUsed {.strdefine.} = "default value" | ||
|
||
doAssert strdefineDefault == "default value" | ||
doAssert strdefineUsed == "test" | ||
|
||
const intdefineDefault {.intdefine.} = 12 | ||
const intdefineUsed {.intdefine.} = 12 | ||
|
||
doAssert intdefineDefault == 12 | ||
doAssert intdefineUsed == 2 | ||
|
||
const booldefineDefault {.booldefine.} = true | ||
const booldefineUsed {.booldefine.} = true | ||
|
||
doAssert booldefineDefault == true | ||
doAssert booldefineUsed == false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
discard """ | ||
description: ''' | ||
Disable or enable safety checks | ||
''' | ||
""" | ||
|
||
## The listed pragmas here can be used to override the code | ||
## generation options for a proc/method/converter. | ||
|
||
block enable_bound_checking: | ||
{.push boundChecks:on.} | ||
proc impl() = | ||
var gotDefect = false | ||
try: | ||
var a: array[10, int] | ||
let idx = 9 | ||
assert cast[ptr array[9, int]](a.addr)[idx] == 0 | ||
|
||
except IndexDefect: | ||
gotDefect = true | ||
|
||
doAssert gotDefect | ||
|
||
{.pop.} | ||
|
||
impl() | ||
|
||
block disable_bound_checking: | ||
{.push boundChecks:off.} | ||
proc impl() = | ||
|
||
var a: array[10, int] | ||
let idx = 9 | ||
a[idx] = 10 | ||
assert cast[ptr array[9, int]](a.addr)[idx] == 10 | ||
|
||
|
||
{.pop.} | ||
|
||
impl() | ||
|
||
block enable_overflow_checks: | ||
{.push overflowChecks:on.} | ||
proc impl() = | ||
var gotDefect = false | ||
try: | ||
var value = high(int) | ||
inc value | ||
|
||
except OverflowDefect: | ||
gotDefect = true | ||
|
||
doAssert gotDefect | ||
|
||
{.pop.} | ||
|
||
impl() | ||
|
||
block disable_overflow_checks: | ||
{.push overflowChecks:off.} | ||
proc impl() = | ||
var value = high(int) | ||
inc value | ||
|
||
{.pop.} | ||
|
||
impl() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
discard """ | ||
description: ''' | ||
`{.hint.}` pragma test | ||
''' | ||
nimout: ''' | ||
t03_hint_pragmas.nim(15, 7) Hint: User-provided hint message [User] | ||
t03_hint_pragmas.nim(19, 9) Hint: gen1 size of the argument is 8 [User] | ||
t03_hint_pragmas.nim(34, 6) Hint: 'declaredButNotUsed' is declared but not used [XDeclaredButNotUsed] | ||
''' | ||
""" | ||
|
||
{.hint: "User-provided hint message".} | ||
|
||
|
||
proc gen1[T](arg: T) = | ||
{.hint: "gen1 size of the argument is " & $sizeof(arg).} | ||
|
||
gen1[int](1) | ||
|
||
when false: | ||
proc gen2[T](arg: T) = | ||
{.line: instantiationInfo().}: | ||
{.hint: "gen2 size of the argument is " & $sizeof(arg).} | ||
|
||
gen2[int](1) | ||
|
||
# REVIEW - this does not work. It should work or not? | ||
{.line: ("override-file.nim", 999, 999).}: | ||
{.hint: "Hint in overriden location".} | ||
|
||
proc declaredButNotUsed() = discard | ||
|
||
when false: | ||
# FIXME - does not work, hint is still emitted | ||
{.push hint[XDeclaredButNotUsed]:off.} | ||
|
||
proc declaredButNotUsedOff() = discard | ||
|
||
{.pop.} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
discard """ | ||
description: ''' | ||
`{.warning.}` pragma test | ||
''' | ||
nimout: ''' | ||
t04_warning.nim(17, 10) Warning: User-provided warning message [User] | ||
t04_warning.nim(22, 5) template/generic instantiation of `gen1` from here | ||
t04_warning.nim(20, 12) Warning: gen1 size of the argument is 8 [User] | ||
t04_warning.nim(23, 5) template/generic instantiation of `gen1` from here | ||
t04_warning.nim(20, 12) Warning: gen1 size of the argument is 8 [User] | ||
''' | ||
""" | ||
|
||
{.warning: "User-provided warning message".} | ||
|
||
proc gen1[T](arg: T) = | ||
{.warning: "gen1 size of the argument is " & $sizeof(arg).} | ||
|
||
gen1[int](1) | ||
gen1[float](1.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
proc getGlobal(): int = | ||
var state {.global.}: int | ||
inc state | ||
return state | ||
|
||
doAssert getGlobal() == 1 | ||
doAssert getGlobal() == 2 |
Oops, something went wrong.