Skip to content

feat(dsp): pipeline stdlib with map/filter/reduce/scan + |> chaining - #398

Merged
godofecht merged 1 commit into
mainfrom
feat/dsp-pipeline-w1
Aug 10, 2026
Merged

godofecht merged 1 commit into
mainfrom
feat/dsp-pipeline-w1

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Summary

  • lib/stdlib/dsp.flow: functional DSP primitives (map, filter, reduce, scan, zip_with, scale, offset, clip, sum, dot) for f32 and f64, all composable with |>
  • examples/dsp/pipeline.flow: buf |> scale |> offset |> clip |> sum demo
  • tests/unit/test_dsp_pipeline.py: 11 tests covering map, pipe chaining, reduce, scan, filter, zip_with, C codegen, f64, named function args

Two compiler fixes:

  1. Type checker: function-type parameters now match named functions and lambdas. _is_compatible compares signatures (param types + return type) instead of requiring synthetic name equality (fn_i32__i32 vs '').

  2. C generator: lambdas passed as function arguments are wrapped in fat-pointer structs via _wrap_lambda_as_fn_type. Previously this only happened for return values and variable declarations.

Test plan

  • 1260 unit tests pass locally
  • examples/dsp/pipeline.flow compiles and runs (sum = 55, PASS)
  • test_named_function_as_arg confirms named functions work as HOF args
  • CI passes

Generated with Devin

Add lib/stdlib/dsp.flow with functional DSP primitives that compose with
the |> operator: map_f32/f64, filter_f32, reduce_f32/f64, scan_f32/f64,
zip_with_f32/f64, scale_f32/f64, offset_f32, clip_f32, sum_f32/f64,
dot_f32/f64.

Two compiler fixes were needed to make this work:

1. Function type compatibility in the type checker. Named functions and
   lambdas have SemanticType with name='' while declared parameters have
   name='fn_...'. The __eq__ check failed on name mismatch. Added a
   function-to-function branch in _is_compatible that compares signatures
   (param types + return type) without requiring name equality.

2. Lambda-as-argument wrapping in the C generator. When a lambda is
   passed directly as a function argument and the parameter type is a
   function type (fn_...), the generator now wraps it in a fat-pointer
   struct via _wrap_lambda_as_fn_type. Previously this wrapping only
   happened for return values and variable declarations.

Add examples/dsp/pipeline.flow demonstrating
buf |> scale |> offset |> clip |> sum.

Add tests/unit/test_dsp_pipeline.py (11 tests): map, pipe, chained pipe,
reduce, scan, filter, zip_with, scale/offset/clip pipe, C codegen, f64
primitives, named function as argument.

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

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

cursor Bot commented Aug 10, 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 8ae04c2 into main Aug 10, 2026
17 checks passed
@godofecht
godofecht deleted the feat/dsp-pipeline-w1 branch August 10, 2026 14:26
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