Skip to content

Stage-A: a shared growable byte buffer for compiler/src modules #985

Closed

Description

@godofecht

Use case

Every DSL port in compiler/src/ builds its output text by hand. The Field DSL port (#956) has FxBuf, a fixed-capacity buffer that sets an error flag when it fills. The Shader DSL port (#683) has ShBuf, which grows with realloc. cgen.flow has its own writer. Each module also carries its own copy of the ASCII whitespace and word-character tests and a span compare.

Current workaround

Each module declares malloc / realloc / free / strlen as externs and defines a struct with buf, cap and len plus putc / puts / put_span helpers. The shader port alone spends about 60 lines on this.

Request

A leaf module (for example compiler/src/bytebuf.flow, or a Stage-A stdlib module the frontend can import) with a growable byte buffer: new(cap), putc, puts, put_span(src, s, e), cstr() (NUL-terminated view) and free, and the ASCII class helpers (is_space matching Python str.isspace, is_word, is_digit). It must be a leaf so the self-emit scripts can link it into flowc_frontend.o like fileio.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions