Add Brainfuck frontend (bfcas) to CIR#2
Draft
Copilot wants to merge 4 commits into
Draft
Conversation
Co-authored-by: zhrexx <134622710+zhrexx@users.noreply.github.com>
Co-authored-by: zhrexx <134622710+zhrexx@users.noreply.github.com>
Co-authored-by: zhrexx <134622710+zhrexx@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor code to brainfuck implementation
Add Brainfuck frontend (Mar 20, 2026
bfcas) to CIR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Brainfuck-to-CIR compiler and
bfcasrunner tool, enabling Brainfuck programs to execute on the CIR VM.VM bug fixes (prerequisite)
Two bugs in
core/cir.hprevented arithmetic from working at all:WordFlag::Registerwas cleared whenever a value was assigned to a register (viaoperator=), causing subsequentexpect_flag(Register)guards onAdd,Sub,Load, etc. to always throw. Fixed by havingmove()re-set the flag after assignment, and routing all register-writing ops throughmove().Inc/Decno-op:operator++/operator--return a newWordby value; the results were silently discarded. Fixed by assigning the return value back viamove().New stdlib functions (
core/std.h)std.putchar— writesr0as a characterstd.getchar— reads one byte intor0Brainfuck compiler (
core/bf.h)BrainfuckCompilerdirectly emitsProgramobjects (no assembly text round-trip). Jump targets for[/]are resolved via a two-pass stack approach:[emits ajewith a placeholder, patched when the matching]is encountered.Register layout:
r0r1r2r3CLI tool (
tools/bf/main.cpp)New
bfcasbinary — compile and run.bffiles directly:bfcas examples/bf/hello.bf # Hello World!Example
examples/bf/hello.bf— Hello World in Brainfuck.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.