Skip to content

feat(flowc): function pointer types, unit declarations - #440

Merged
godofecht merged 1 commit into
mainfrom
work
Aug 12, 2026
Merged

godofecht merged 1 commit into
mainfrom
work

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Summary

  • Function pointer types (A, B) -> R are now parsed and emitted as R (*)(A, B) in C output. Parameter declarations emit R (*name)(A, B).
  • unit Name declarations are now skipped (used by units_si.flow for SI unit definitions).

Context

dsp.flow uses function pointer parameters like f: (f32) -> f32 for element-wise mapping. units_si.flow uses unit Second, unit Meter, etc. for dimensional analysis. Neither was handled by the self-hosted compiler.

Test plan

  • ./flow run compiler/src/main.flow passes (flowc: PASS)
  • Three consecutive generation fixed-points pass (byte-identical)
  • lib/stdlib/dsp.flow compiles to valid C with zero clang errors
  • lib/stdlib/units_si.flow compiles to valid C with zero clang errors
  • Function pointer test: function apply(f: (i32) -> i32, x: i32) -> i32 { return f(x) } produces correct C

This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.

Generated with Devin

compiler/src/parser.flow: parse function pointer types
(A, B) -> R in flowc_parse_type. Stored as AST_TYPE with ival=-1,
a=param chain, b=return type. Also skip unit Name declarations
(KW_UNIT).

compiler/src/cgen.flow: emit function pointer types as
R (*)(A, B) in flowc_cgen_emit_type, and R (*name)(A, B) in
flowc_cgen_emit_param.

compiler/src/token.flow: add KW_UNIT (27).
compiler/src/lexer.flow: add "unit" keyword.

lib/stdlib/dsp.flow and lib/stdlib/units_si.flow now compile to
valid C with zero errors.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cursor

cursor Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@godofecht
godofecht merged commit a0be2b3 into main Aug 12, 2026
12 of 13 checks passed
@godofecht
godofecht deleted the work branch August 12, 2026 02:01
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