Skip to content

Add new numeric constants for octal and binary to chialisp - #402

Merged
prozacchiwawa merged 19 commits into
mainfrom
20260311-bit-constants
Mar 24, 2026
Merged

prozacchiwawa merged 19 commits into
mainfrom
20260311-bit-constants

Conversation

@prozacchiwawa

@prozacchiwawa prozacchiwawa commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

This will add new octal and binary constants to chialisp compilation. Since the data representation of clvm values uses virtually every string as some kind of valid value, a new *bitconst* include is provided to enable interpretation as octal and binary.

The rule for these bit constants is that if a completely unnecessary zero is used as left padding that appears in a new byte, then the constant has that left zero byte.

In modern, it's enabled by the sigil *standard-cl-nc25* , in classic by *bitconst* (this is the first sigil affecting classic).

Since the first 0 is required, 0o0 and 0b0 are () not 0x00.
0b00 and 0o00 are 0x00.

Consider the octal constant 0o377, which is 0b11111111, this is -1 or 0xff.
If you add a zero to 0o377, 0o0377, then this is 0x00ff. 0b011111111 is also 0x00ff.


Note

Medium Risk
Touches core parsing/printing paths for both classic IR and the modern compiler, so subtle parsing or round-tripping regressions are possible even though the feature is gated behind dialect/include flags.

Overview
Adds opt-in binary (0b...) and octal (0o...) numeric literals that compile to byte-atoms with defined left-padding semantics.

This introduces a NEW_BIT_CONSTANTS language flag and threads it through classic tooling (read_ir/IRReader, assemble/disassemble, and stage-2 operators) and the modern compiler parser (parse_sexp_flags) so dialect detection can re-parse with the correct numeric rules. New dialect sigils *standard-cl-nc25* (modern) and *bitconst* (classic) enable the behavior, and a dedicated test suite (tests/classic/bitconst.rs) validates parsing, disassembly round-trips, and fuzzes padding edge-cases.

Written by Cursor Bugbot for commit e04b8c9. This will update automatically on new commits. Configure here.

@prozacchiwawa
prozacchiwawa marked this pull request as ready for review March 18, 2026 19:14
Comment thread src/classic/clvm_tools/ir/writer.rs Outdated
Comment thread src/classic/clvm_tools/stages/stage_2/operators.rs Outdated
…ensure bytes are scanned right to left when regenerating bit constants
Comment thread src/classic/clvm_tools/ir/reader.rs
Comment thread src/classic/clvm_tools/ir/writer.rs Outdated
Comment thread src/classic/clvm_tools/clvmc.rs
Comment thread src/classic/clvm_tools/ir/writer.rs
Comment thread src/classic/clvm_tools/ir/writer.rs Outdated
Comment thread src/compiler/sexp.rs
…xed that. ensured tests are exercised on precisely comparable amounts of padding
Comment thread src/classic/clvm_tools/ir/writer.rs
…prefix 0s for decimal constants so modern mirrors the way classic allows multiply padded decimal constants

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread src/classic/clvm_tools/ir/writer.rs

@Quexington Quexington left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't pretend to understand the semantics of this change but I approve it conceptually.

@prozacchiwawa
prozacchiwawa merged commit 1972d48 into main Mar 24, 2026
35 checks passed
@prozacchiwawa
prozacchiwawa deleted the 20260311-bit-constants branch March 24, 2026 10: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.

3 participants