Skip to content

feat(flowc): stdlib import resolution, math.h, keyword let fix, new ported modules - #447

Merged
godofecht merged 11 commits into
mainfrom
work
Aug 12, 2026
Merged

godofecht merged 11 commits into
mainfrom
work

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Summary

  • Fix keyword let names in statement parser (inline let in flowc_parse_stmt now accepts TOK_KEYWORD like the standalone flowc_parse_let).
  • Strip stdlib/ prefix from string imports so "stdlib/tensor.flow" resolves to search_dir/tensor.flow instead of search_dir/stdlib/tensor.flow.
  • Add <math.h> to the C generator preamble for sqrt and other math externs.
  • Add forward declaration for str_starts_with in fir_analysis.flow.
  • Port LSP syntax token detection to lsp_syntax.flow.
  • Port LSP receiver/field detection to lsp_intel.flow.
  • Port geometry diagram helpers to geometry_diagram.flow.
  • Port proof document formatting to proof_document.flow.
  • Port dynamics DSL line helpers to dynamics_dsl.flow.
  • Port LSP utility helpers to lsp_utils.flow.
  • Port DSL detection to dsl_detect.flow.
  • Add guess_effect_for_name to fir_analysis.flow.
  • Add slug_label to proof_document.flow.

Test plan

  • ./flow run compiler/src/main.flow passes (flowc: PASS)
  • Three consecutive generation fixed-points pass (byte-identical)
  • Self-compile audit: all compiler/src modules pass (including new ports)
  • Roundtrip: all stage-a, bundle, self-emit, and fixed-point checks pass
  • bundle_tc_bad correctly fails (rc=1)

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

Generated with Devin

godofecht and others added 10 commits August 12, 2026 08:56
Port the multi-char operator detection and hover gloss from Python to
Flow. The Python original includes full markdown hover strings; the
Flow port exposes the token detection logic and a compact one-line
gloss. Full markdown hover stays in the Python LSP server.

Provides:
- flowc_is_multi_char_op: check if a string is a known operator
- flowc_syntax_token_at_position: find the operator covering a column
  in a line of text (checks 12 two-char operators)
- flowc_syntax_hover_gloss: compact one-line description

Operators covered: |>, ->, =>, ==, !=, <=, >=, &&, ||, .., <<, >>

Test: tests/lang/test_lsp_syntax.flow has 19 checks, all pass
under FLOW_HOST=python. Covers operator detection at first and
second character positions, empty lines, column clamping, and
hover glosses for known and unknown tokens.

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

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

Port the receiver_before_dot and field_access_at functions from
Python to Flow. The Python original uses regex; the Flow port does
manual character scanning with identifier boundary checks.

Provides:
- flowc_receiver_before_dot: find the identifier before a dot at the
  cursor position (for completion after "ident.")
- flowc_field_access_at: find (receiver, field) when the cursor is on
  "recv.field" (for field completion)

Both handle whitespace between the receiver and dot. Identifiers must
start with a letter or underscore. URI parsing, source parsing, and
type checking stay in the Python LSP server.

Test: tests/lang/test_lsp_intel.flow has 18 checks, all pass under
FLOW_HOST=python. Covers basic receiver detection, field access
extraction, whitespace handling, and failure cases (no dot, no
receiver, cursor on receiver, empty field, numeric receiver).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Port the SVG escape, vector math, and interpolation helpers from
Python to Flow. The Python original renders full SVG diagrams; the
Flow port exposes the pure math and string helpers.

Provides:
- flowc_svg_escape: escape & < > for XML/SVG output
- flowc_vec2_unit_x / flowc_vec2_unit_y: normalize a 2D vector
- flowc_vec2_length: hypot (vector magnitude)
- flowc_vec2_dot: 2D dot product
- flowc_point_distance: Euclidean distance between two points
- flowc_lerp: linear interpolation

Test: tests/lang/test_geometry_diagram.flow has 15 checks, all pass
under FLOW_HOST=python. Covers SVG escaping (all special chars,
no-op, empty), vector normalization (3-4-5 triangle, zero vector),
length, dot product, distance, and lerp at t=0, 0.5, 1.

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

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

Port the step label and cross-reference formatting functions from
Python to Flow. The Python original builds full proof documents; the
Flow port exposes the pure formatting helpers.

Provides:
- flowc_circled: Unicode circled number (1-20), fallback "(n)"
- flowc_step_label_latex: \textbf{N.} for LaTeX proof steps
- flowc_fmt_refs: "step N" / "step N and step M" / "step N, step M, and step K"
- flowc_from_refs: "From step N, " prefix
- flowc_under_refs: "Under the supposition in step N, " (singular/plural)

Test: tests/lang/test_proof_document.flow has 15 checks, all pass
under FLOW_HOST=python. Covers circled numbers (valid, out of range,
zero), LaTeX step labels, single/double/triple refs, empty refs,
and from/under prefix formatting.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Port the _strip_comments and _strip_dynamics_namespace functions from
Python to Flow. The Python original is a full DSL parser and expander;
the Flow port exposes the line-level helpers.

Provides:
- flowc_strip_comments: remove trailing # comment and strip whitespace
- flowc_strip_dynamics_namespace: strip dyn./dynamics. namespace prefix
  so namespaced forms (dyn.dsys, dynamics.horizon) work as bare aliases

Test: tests/lang/test_dynamics_dsl.flow has 11 checks, all pass
under FLOW_HOST=python. Covers comment stripping, whitespace-only
lines, both namespace prefixes, bare form passthrough, and comment
stripping combined with namespace removal.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Port the _guess_effect_for_name function from fir_graphify.py to
Flow. This classifies a function name into effect bits based on
known IO and allocation name sets.

Provides:
- flowc_guess_effect_for_name: returns effect bits for a function
  name and extern flag. Extern functions get FFI. IO names (print,
  printf, puts, read, write, fopen, fclose, flow_gfx_*, flow_audio_*)
  get IO. Allocation names (malloc, calloc, realloc, free, alloc,
  arena_alloc) get ALLOCATES and WRITES_MEMORY.

Test: added 9 checks to test_fir_analysis.flow (now 34 total), all
pass under FLOW_HOST=python. Covers extern FFI, IO names, alloc
names, prefix matching, pure functions, and combined extern+IO.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Port the identifier validation, word range, and completion prefix
helpers from the LSP server to Flow. The Python original is a full
JSON-RPC server; the Flow port exposes the pure string helpers.

Provides:
- flowc_is_valid_identifier: check ^[A-Za-z_][A-Za-z0-9_]*$
- flowc_word_range: range covering the word at a cursor position
- flowc_completion_prefix: word or dyn. prefix at cursor for filtering
  completions (includes dots and underscores)

Test: tests/lang/test_lsp_utils.flow has 18 checks, all pass under
FLOW_HOST=python. Covers valid/invalid identifiers, word range
extraction (on word, mid-word, space, beyond end), and completion
prefix (simple word, mid-word, dot prefix, partial dot, start of
line, after space).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Port the has_field_dsl, has_dynamics_dsl, and has_fill_shader_dsl
functions from Python to Flow. The Python originals use regex; the
Flow port does manual line-by-line scanning with word boundary checks.

Provides:
- flowc_has_field_dsl: detect field/boundary declarations
- flowc_has_dynamics_dsl: detect bare and namespaced (dyn./dynamics.)
  dynamics DSL markers (dsys, horizon, sense on, ga evolve, closed,
  analyze, wfc field)
- flowc_has_fill_shader_dsl: detect shader fill declarations with
  proper word boundary checking

Test: tests/lang/test_dsl_detect.flow has 16 checks, all pass under
FLOW_HOST=python. Covers field/boundary detection, indented forms,
multi-line sources, bare and namespaced dynamics forms, shader fill
detection, and negative cases (plain code, word boundary).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Compiler improvements from self-hosted rebuild:
- Emit #include <math.h> in generated C (for sqrt etc.)
- Parser: allow keyword as let variable name (TOK_KEYWORD check)
- Resolve: strip "stdlib/" prefix from string imports so
  "stdlib/tensor.flow" resolves to lib/stdlib/tensor.flow
- fir_analysis: forward declare str_starts_with

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Port the _slug_label function from proof_document.py to Flow.
Converts a claim path to a slug-safe label by replacing special
characters: / -> -, + -> plus, * -> star, | -> or, . -> -, = -> eq,
« and » -> removed, space -> -.

Test: added 6 checks to test_proof_document.flow (now 21 total),
all pass under FLOW_HOST=python. Covers simple paths, + and *,
= and |, spaces, empty string, and dot replacement.

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.

nn_autogen.flow uses import "lib/stdlib/nn.flow" which was not
resolved correctly. Now both "stdlib/foo.flow" and "lib/stdlib/foo.flow"
are stripped to resolve relative to search_dir.

All 67 stdlib modules now emit C (with typecheck disabled).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@godofecht
godofecht merged commit dfd8b97 into main Aug 12, 2026
13 of 16 checks passed
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