treeform / genny

Generate a shared library and bindings for many languages.
MIT License
224 stars 9 forks source link

Add support for generics #43

Closed mratsim closed 2 years ago

mratsim commented 2 years ago

This fails with "Node is not a symbol" in sym.getImpl

import genny

type
  Foo[T] = object
    val: T

proc sum[T](r: var Foo[T], a, b: Foo[T]) =
  r.val = a.val + b.val

exportObject Foo[int]:
  procs:
    sum(Foo[int], Foo[int], Foo[int])

writeFiles("bindings/generated", "test")
include generated/internal

https://github.com/treeform/genny/blob/33f0e5a3e6d370c63f11ac0572f6396af684a314/src/genny/languages/nim.nim#L127-L137

treeform commented 2 years ago

Genny can't export many of the advanced features of Nim like generics simply because other languages don't support them. There needs to be a tiny simplification layer in your bindings to define concreate functions and concrete types that you do want to export.

type FooInt = Foo[int]
proc sum(r: FooInt, a, b: FooInt) 

And export that instead.

mratsim commented 2 years ago

OK, then we run into https://github.com/treeform/genny/issues/44 to handle type aliases