Skip to content

feat(generator): add support for map[string]bool/int/float64#85

Merged
akonwi merged 1 commit intomainfrom
refactor/ffi-map-scalar-values
Apr 10, 2026
Merged

feat(generator): add support for map[string]bool/int/float64#85
akonwi merged 1 commit intomainfrom
refactor/ffi-map-scalar-values

Conversation

@akonwi
Copy link
Copy Markdown
Owner

@akonwi akonwi commented Apr 10, 2026

Summary

Extends the FFI generator to support map[string]bool, map[string]int, and map[string]float64 (previously only map[string]string was supported).

Changes

Generator Extension

  • Extended GoType struct with MapValue field (replaces IsStringMap bool)
  • Updated parseGoType to recognize map[string]bool, map[string]int, map[string]float64
  • Updated code generation in generateParamUnwrap and generateReturnWrap

FS_ListDir Refactor

  • Converted from raw FFI to idiomatic FFI
  • Now returns map[string]bool (name → is_file) instead of constructing DirEntry structs in Go
  • Ard code builds DirEntry structs from the map
  • Eliminated getFSDirEntryType() type lookup entirely

Before/After

Before (Raw FFI)

func FS_ListDir(args []*runtime.Object) *runtime.Object {
    // ... type lookup for DirEntry
    dirEntryType := getFSDirEntryType()
    // ... manual struct construction
}

After (Idiomatic FFI)

func FS_ListDir(path string) (map[string]bool, error) {
    entries, err := os.ReadDir(path)
    // ... return simple map
}
// std_lib/fs.ard
private extern fn _list_dir_map(path: Str) [Str: Bool]!Str = "FS_ListDir"

fn list_dir(path: Str) [DirEntry]!Str {
  let entries_map = try _list_dir_map(path)
  mut entries: [DirEntry] = []
  for name, is_file in entries_map {
    entries.push(DirEntry{name: name, is_file: is_file})
  }
  Result::ok(entries)
}

Benefits

  • Reduced raw FFI count: 15 → 14
  • Eliminated one type lookup (GetStdType pattern)
  • Simpler Go code, more logic in Ard

Testing

  • All unit tests pass
  • map[string]bool correctly generates .AsBool() for unwrapping and MakeBool for wrapping
  • map[string]int correctly generates .AsInt() for unwrapping and MakeInt for wrapping

- Extend GoType to support MapValue field for map scalar values
- Update parseGoType to recognize map[string]bool, map[string]int, map[string]float64
- Update code generation to handle new map types
- Refactor FS_ListDir from raw FFI to idiomatic:
  - Returns map[string]bool instead of constructing DirEntry structs
  - Ard code builds DirEntry struct from map
  - Removes getFSDirEntryType() type lookup entirely
- Reduce raw FFI count from 15 to 14

This eliminates one type lookup (GetStdType pattern) by returning
simpler types and letting Ard construct the struct.
@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:35pm

@akonwi akonwi merged commit 7fefbb4 into main Apr 10, 2026
4 checks passed
@akonwi akonwi deleted the refactor/ffi-map-scalar-values branch April 10, 2026 20:38
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