Skip to content

feat(generator): add support for []any and map[string]any#86

Merged
akonwi merged 1 commit intomainfrom
refactor/ffi-any-list-map
Apr 10, 2026
Merged

feat(generator): add support for []any and map[string]any#86
akonwi merged 1 commit intomainfrom
refactor/ffi-any-list-map

Conversation

@akonwi
Copy link
Copy Markdown
Owner

@akonwi akonwi commented Apr 10, 2026

Summary

Extends the FFI generator to support []any (slice of any) and map[string]any types, and converts two raw FFI functions to idiomatic.

Changes

Generator Extension

  • Extended GoType struct with IsAnySlice and IsAnyMap fields
  • Updated parseGoType to recognize []any and map[string]any
  • Updated code generation for both parameter unwrapping and return wrapping:

[]any parameter:

_sl0 := args[0].AsList()
arg0 := make([]any, len(_sl0))
for _i0, _e0 := range _sl0 {
    arg0[_i0] = _e0.Raw()
}

[]any return:

_items := make([]*runtime.Object, len(result))
for _i, _v := range result {
    _items[_i] = runtime.MakeDynamic(_v)
}
return runtime.MakeList(checker.Dynamic, _items...)

map[string]any parameter:

_rawMap0 := args[0].AsMap()
arg0 := make(map[string]any, len(_rawMap0))
for _k0, _v0 := range _rawMap0 {
    arg0[_k0] = _v0.Raw()
}

map[string]any return:

_map := runtime.MakeMap(checker.Str, checker.Dynamic)
for _k, _v := range result {
    _map.Map_Set(runtime.MakeStr(_k), runtime.MakeDynamic(_v))
}
return _map

Function Conversions

Function Before After
ListToDynamic Raw FFI ([]*runtime.Object) Idiomatic ([]any) any
MapToDynamic Raw FFI ([]*runtime.Object) Idiomatic (map[string]any) any

Stats

  • Raw FFI: 14 → 12
  • Idiomatic FFI: 59 → 61

Testing

  • All unit tests pass
  • Verified generated code for []any and map[string]any

- Extend GoType with IsAnySlice and IsAnyMap fields
- Update parseGoType to recognize []any and map[string]any
- Update code generation for unwrapping/wrapping:
  - []any: iterate .AsList(), extract .Raw()
  - map[string]any: iterate .AsMap(), extract .Raw()
- Convert ListToDynamic and MapToDynamic from raw to idiomatic:
  - ListToDynamic(items []any) any
  - MapToDynamic(m map[string]any) any
- Reduce raw FFI count from 14 to 12

These new types enable simpler FFI signatures for functions that
work with dynamic data.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ard-lang-dev Ready Ready Preview, Comment Apr 10, 2026 8:46pm

@akonwi akonwi merged commit f3a8d29 into main Apr 10, 2026
4 checks passed
@akonwi akonwi deleted the refactor/ffi-any-list-map branch April 10, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant