Skip to content

CLI argument passing: support strings, floats, and typed dispatch #263

@aallan

Description

@aallan

Problem

Currently vera run file.vera --fn f -- 42 10 only supports integer arguments. Non-integer values produce an error:

$ vera run file.vera --fn greet -- Alice
Error: Invalid integer argument(s): Alice

This means functions like fn greet(@String -> @Unit) cannot be called from the CLI at all. Float-parameter functions like fn area(@Float64 -> @Float64) also cannot be invoked directly.

The only workaround for strings is IO.args(), which requires restructuring the function to use the IO effect and call IO.args() internally rather than receiving arguments as parameters.

Current behavior

In vera/cli.py:866-884, everything after -- is parsed strictly as integers:

fn_args = [int(a) for a in raw_args]  # line 873

The type annotation confirms: fn_args: list[int | float] | None (but float parsing is never attempted).

In vera/codegen/api.py:515-537, execute() validates that the argument count matches the WASM function parameter count, but has no type-aware dispatch.

Proposed solution

Use the compiled WASM function signature to determine argument types and parse CLI args accordingly:

  1. Inspect func_type.params from the WASM function to get the expected types (i64, f64, i32, i32 i32 for strings)
  2. Parse each CLI arg based on the expected WASM type:
    • i64 (Int/Nat) -> int(arg)
    • f64 (Float64) -> float(arg)
    • i32 (Bool) -> arg.lower() in ("true", "1")
    • i32 i32 (String) -> allocate in WASM memory, pass (ptr, len)
  3. String allocation requires access to the WASM store and memory before calling the function -- allocate the UTF-8 bytes and pass the (offset, length) pair as two i32 params

Scope

  • Float argument support (-- 3.14)
  • String argument support (-- hello "hello world")
  • Bool argument support (-- true false)
  • Type-mismatch error messages (e.g., "expected Int for parameter 1, got 'hello'")
  • Update spec Section 5.11 (Entry Point) to document CLI argument passing
  • Update SKILL.md and vera/README.md CLI usage sections

Related

  • IO.args() remains available as the string-based alternative (returns Array<String>)
  • The @Unit parameter convention (spec requires main(@Unit -> @Unit) but this is not enforced by the checker)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C8.5C8.5 — CompletenessenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions