Compare commits

...

9 Commits

Author SHA1 Message Date
ringabout
a659dbff1b Merge branch 'devel' into pr_nodecl_type 2025-10-10 21:00:12 +08:00
ringabout
276840610b adds a changelog 2025-01-09 21:31:32 +08:00
ringabout
449511995f uses nodecl 2025-01-08 22:32:29 +08:00
ringabout
33263ef806 fixes tests 2025-01-08 21:45:26 +08:00
ringabout
ce20f1b31a use nodecl 2025-01-08 19:53:43 +08:00
ringabout
c1f99aa362 fixes macos 2025-01-08 19:50:25 +08:00
ringabout
67d80c4971 oops 2025-01-08 19:32:40 +08:00
ringabout
237669a1b2 fixes types with a header 2025-01-08 19:27:25 +08:00
ringabout
d39c76b8bd fixes #24604; importc fails to generate stub type 2025-01-08 18:44:28 +08:00
12 changed files with 30 additions and 19 deletions

View File

@@ -19,6 +19,8 @@ errors.
- With `-d:nimPreviewAsmSemSymbol`, backticked symbols are type checked in the `asm/emit` statements.
- `importc` no longer implies `nodecl` for imported types. Use `header` or `nodecl` pragmas so that it doesn't generate a declaration for the type symbol.
- The bare `except:` now panics on `Defect`. Use `except Exception:` or `except Defect:` to catch `Defect`. `--legacy:noPanicOnExcept` is provided for a transition period.
- With `-d:nimPreviewCStringComparisons`, comparsions (`<`, `>`, `<=`, `>=`) between cstrings switch from reference semantics to value semantics like `==` and `!=`.
@@ -27,6 +29,7 @@ errors.
- With `-d:nimPreviewDuplicateModuleError`, importing two modules that share the same name becomes a compile-time error. This includes importing the same module more than once. Use `import foo as foo1` (or other aliases) to avoid collisions.
## Standard library additions and changes
[//]: # "Additions:"

View File

@@ -238,6 +238,9 @@ proc mapReturnType(conf: ConfigRef; typ: PType): TCTypeKind =
proc isImportedType(t: PType): bool =
result = t.sym != nil and sfImportc in t.sym.flags
proc isNoDeclType(t: PType): bool =
result = t.sym != nil and {lfNoDecl, lfHeader} * t.sym.loc.flags != {}
proc isImportedCppType(t: PType): bool =
let x = t.skipTypes(irrelevantForBackend)
result = (t.sym != nil and sfInfixCall in t.sym.flags) or
@@ -390,7 +393,7 @@ proc getTypeForward(m: BModule; typ: PType; sig: SigHash): Rope =
of tySequence, tyTuple, tyObject:
result = getTypeName(m, typ, sig)
m.forwTypeCache[sig] = result
if not isImportedType(concrete):
if not isNoDeclType(concrete):
addForwardStructFormat(m, structOrUnion(typ), result)
else:
pushType(m, concrete)
@@ -1045,14 +1048,14 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes
if result == "":
result = getTypeName(m, origTyp, sig)
m.forwTypeCache[sig] = result
if not isImportedType(t):
if not isNoDeclType(t):
addForwardStructFormat(m, structOrUnion(t), result)
assert m.forwTypeCache[sig] == result
m.typeCache[sig] = result # always call for sideeffects:
if not incompleteType(t):
let recdesc = if t.kind != tyTuple: getRecordDesc(m, t, result, check)
else: getTupleDesc(m, t, result, check)
if not isImportedType(t):
if not isImportedType(t) and not isNoDeclType(t):
m.s[cfsTypes].add(recdesc)
elif tfIncompleteStruct notin t.flags:
discard # addAbiCheck(m, t, result) # already handled elsewhere

View File

@@ -238,7 +238,7 @@ elif defined(ios) or defined(macosx):
const errSecSuccess = 0 ## No error.
type
SecRandom {.importc: "struct __SecRandom".} = object
SecRandom {.importc: "struct __SecRandom", header: "<Security/SecRandom.h>".} = object
SecRandomRef = ptr SecRandom
## An abstract Core Foundation-type object containing information about a random number generator.

View File

@@ -113,13 +113,13 @@ elif defined(windows) or defined(dos):
#
when defined(cpp):
type
THINSTANCE {.importc: "HINSTANCE".} = object
THINSTANCE {.importc: "HINSTANCE", nodecl.} = object
x: pointer
proc getProcAddress(lib: THINSTANCE, name: cstring): ProcAddr {.
importcpp: "(void*)GetProcAddress(@)", header: "<windows.h>", stdcall.}
else:
type
THINSTANCE {.importc: "HINSTANCE".} = pointer
THINSTANCE {.importc: "HINSTANCE", nodecl.} = pointer
proc getProcAddress(lib: THINSTANCE, name: cstring): ProcAddr {.
importc: "GetProcAddress", header: "<windows.h>", stdcall.}

View File

@@ -30,11 +30,11 @@ var s = bork()
import tables
type
cdbl {.importc: "double".} = object
cdbl {.importc: "double", nodecl.} = object
MyObject = ref object of RootObj
y: Table[string, cdbl]
proc test =
var x = new(MyObject)

View File

@@ -140,7 +140,7 @@ block: # bug #9940
typedef struct { int base; } S;
""".}
type S {.importc: "S", completeStruct.} = object
type S {.importc: "S", nodecl, completeStruct.} = object
base: cint
proc init(x:ptr S) =
x.base = 1

View File

@@ -1,6 +1,6 @@
discard """
targets: "c cpp"
matrix: "--gc:refc; --gc:arc"
matrix: "--mm:refc; --mm:arc"
"""
# bug #7308
@@ -41,3 +41,8 @@ block: # bug #11797
proc foo3(): int32 = 2
foo(proc(): cint = foo1())
foo(proc(): int32 = foo3())
block: # bug #24604
type MyType {.importc, incompleteStruct.} = object
var v {.exportc.}: ptr MyType

View File

@@ -15,7 +15,7 @@ struct SystemManager {
""".}
type Input {.importcpp: "System::Input".} = object
type Input {.importcpp: "System::Input", nodecl.} = object
proc getSubsystem*[T](): ptr T {.
importcpp: "SystemManager::getSubsystem<'*0>()", nodecl.}

View File

@@ -26,7 +26,7 @@ template ensureCgen(T: typedesc) =
var a {.volatile.}: T
block:
type Foo1Alias{.importc: "struct Foo1", size: sizeof(cint).} = object
type Foo1Alias{.importc: "struct Foo1", nodecl, size: sizeof(cint).} = object
a: cint
ensureCgen Foo1Alias

View File

@@ -488,7 +488,7 @@ typedef struct{
""".}
type
Foo {.importc.} = object
Foo {.importc, nodecl.} = object
Bar = object
b: byte
@@ -549,7 +549,7 @@ doAssert alignof(MyCustomAlignObject) == 32
##########################################
type
imported_double {.importc: "double".} = object
imported_double {.importc: "double", nodecl.} = object
Pod = object
v* : imported_double

View File

@@ -1,11 +1,11 @@
{.passL: "-lsfml-graphics -lsfml-system -lsfml-window".}
type
VideoMode* {.importcpp: "sf::VideoMode".} = object
RenderWindowObj {.importcpp: "sf::RenderWindow".} = object
VideoMode* {.importcpp: "sf::VideoMode", nodecl.} = object
RenderWindowObj {.importcpp: "sf::RenderWindow", nodecl.} = object
RenderWindow* = ptr RenderWindowObj
Color* {.importcpp: "sf::Color".} = object
Event* {.importcpp: "sf::Event".} = object
Color* {.importcpp: "sf::Color", nodecl.} = object
Event* {.importcpp: "sf::Event", nodecl.} = object
{.push cdecl, header: "<SFML/Graphics.hpp>".}

View File

@@ -15,7 +15,7 @@ cimported set1_imported(double x) {
"""}
type vfloat{.importc: "cimported".} = object
type vfloat{.importc: "cimported", nodecl.} = object
proc set1(a: float): vfloat {.importc: "set1_imported".}