Skip to content

Commit e48c9f9

Browse files
remove ffiType macro because it is duplicated by ffi macro (#22)
1 parent 6d31fa3 commit e48c9f9

4 files changed

Lines changed: 17 additions & 58 deletions

File tree

ffi/serial.nim

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import std/[json, macros, options]
1+
import std/[json, options]
22
import results
33
import ./codegen/meta
44

@@ -119,38 +119,3 @@ proc ffiDeserialize*[T: object](s: cstring, _: typedesc[T]): Result[T, string] =
119119
ok(parseJson($s).to(T))
120120
except Exception as e:
121121
err(e.msg)
122-
123-
macro ffiType*(body: untyped): untyped =
124-
## Statement macro applied to a type declaration block.
125-
## Registers the type in ffiTypeRegistry for binding generation.
126-
## Serialization is handled by the generic ffiSerialize/ffiDeserialize overloads.
127-
## Usage:
128-
## ffiType:
129-
## type Foo = object
130-
## field: int
131-
let typeSection = body[0]
132-
let typeDef = typeSection[0]
133-
let typeName =
134-
if typeDef[0].kind == nnkPostfix:
135-
typeDef[0][1]
136-
else:
137-
typeDef[0]
138-
139-
let typeNameStr = $typeName
140-
var fieldMetas: seq[FFIFieldMeta] = @[]
141-
let objTy = typeDef[2]
142-
if objTy.kind == nnkObjectTy and objTy.len >= 3:
143-
let recList = objTy[2]
144-
if recList.kind == nnkRecList:
145-
for identDef in recList:
146-
if identDef.kind == nnkIdentDefs:
147-
let fieldType = identDef[^2]
148-
let fieldTypeName =
149-
if fieldType.kind == nnkIdent: $fieldType
150-
elif fieldType.kind == nnkPtrTy: "ptr " & $fieldType[0]
151-
else: fieldType.repr
152-
for i in 0 ..< identDef.len - 2:
153-
fieldMetas.add(FFIFieldMeta(name: $identDef[i], typeName: fieldTypeName))
154-
155-
ffiTypeRegistry.add(FFITypeMeta(name: typeNameStr, fields: fieldMetas))
156-
result = body

tests/test_ctx_validation.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import ../ffi
55

66
type TestLib = object
77

8-
ffiType:
9-
type CtxValidationConfig = object
10-
initialValue: int
8+
type CtxValidationConfig {.ffi.} = object
9+
initialValue: int
1110

1211
proc ctxval_create*(
1312
config: CtxValidationConfig

tests/test_ffi_context.nim

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,8 @@ suite "sendRequestToFFIThread":
412412
type SimpleLib = object
413413
value: int
414414

415-
ffiType:
416-
type SimpleConfig = object
417-
initialValue: int
415+
type SimpleConfig {.ffi.} = object
416+
initialValue: int
418417

419418
proc testlib_create*(
420419
config: SimpleConfig
@@ -454,9 +453,8 @@ suite "ffiCtor macro":
454453
# Simplified .ffi. macro integration test
455454
# ---------------------------------------------------------------------------
456455

457-
ffiType:
458-
type SendConfig = object
459-
message: string
456+
type SendConfig {.ffi.} = object
457+
message: string
460458

461459
proc testlib_send*(
462460
lib: SimpleLib, cfg: SendConfig
@@ -558,9 +556,8 @@ suite "async/sync detection in .ffi.":
558556
type Handle = object
559557
data: string
560558

561-
ffiType:
562-
type NameParam = object
563-
name: string
559+
type NameParam {.ffi.} = object
560+
name: string
564561

565562
proc testlib_alloc_handle*(
566563
lib: SimpleLib, np: NameParam

tests/test_serial.nim

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import unittest
22
import results
3-
import ../ffi/serial
3+
import ../ffi
44

5-
ffiType:
6-
type Point = object
7-
x: int
8-
y: int
5+
type Point {.ffi.} = object
6+
x: int
7+
y: int
98

10-
ffiType:
11-
type Nested = object
12-
label: string
13-
point: Point
9+
type Nested {.ffi.} = object
10+
label: string
11+
point: Point
1412

1513
suite "ffiSerialize / ffiDeserialize primitives":
1614
test "string round-trip":
@@ -81,7 +79,7 @@ suite "pointer serialization":
8179
let serialized = ffiSerialize(p)
8280
check serialized == "0"
8381

84-
suite "ffiType macro — object round-trip":
82+
suite "{.ffi.} on type — object round-trip":
8583
test "Point round-trip":
8684
let pt = Point(x: 10, y: 20)
8785
let serialized = ffiSerialize(pt)

0 commit comments

Comments
 (0)