Skip to content
/ cbc Public

C B Compiler, a working B compiler that is fully compliant with B, with nice warnings and errors, configurable via standard flags like -W/-Wno, and -F and -Fno to turn on/off warns/features. -std=B/-std=Bx for some extensions. Compatible with tsoding/b

License

ISC, Unknown licenses found

Licenses found

ISC
LICENSE
Unknown
LICENSE.RABRMS
Notifications You must be signed in to change notification settings

xplshn/cbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GBC - Go B Compiler - https://github.com/xplshn/gbc

A much more capable and self-contained B compiler, written using modernc.org/libqbe


(cbc) | The C B Compiler

This compiler is a project aiming to make a valid B compiler, with optional extensions for C interoperability, and a modules system like Go's

]~/Documents/TrulyMine/cbc@ ./cbc 

Copyright (c) 2025: xplshn and contributors
For more details refer to <https://github.com/xplshn/cbc>

  Synopsis
    ./cbc [options] <input.b> ...

  Description
    A compiler for the B programming language and its extensions.

  Options
    -o <file>              Place the output into <file>.
    -h, --help             Display this information.
    -std=<std>             Specify language standard (B, Bx). Default: Bx
    -pedantic              Issue all warnings demanded by the current B std.

  Warning Flags
    -Wall                  Enable most warnings.
    -Wno-all               Disable all warnings.
    -W<warning>            Enable a specific warning.
    -Wno-<warning>         Disable a specific warning.
    Available warnings:
      c-escapes              Using C-style '\' escapes instead of B's '*'                                [x]
      b-escapes              Using historical B-style '*' escapes instead of C's '\'                     [x]
      b-ops                  Using historical B assignment operators like '=+'                           [x]
      c-ops                  Using C-style assignment operators like '+=' in -std=B mode                 [x]
      unrecognized-escape    Using unrecognized escape sequences                                         [x]
      truncated-char         Character escape value is too large for a byte and has been truncated       [x]
      long-char-const        Multi-character constant is too long for a word                             [x]
      c-comments             Using non-standard C-style '//' comments                                    [-]
      overflow               Integer constant is out of range for its type                               [x]
      pedantic               Issues that violate the current strict -std=                                [-]
      unreachable-code       Unreachable code                                                            [x]
      extra                  Extra warnings (e.g., poor choices, unrecognized flags)                     [x]

  Feature Flags
    -F<feature>            Enable a specific feature.
    -Fno-<feature>         Disable a specific feature.
    Available features:
      extrn                  Allow the 'extrn' keyword                                                   [x]
      asm                    Allow the '__asm__' keyword and blocks                                      [x]
      b-escapes              Recognize B-style '*' character escapes                                     [x]
      c-escapes              Recognize C-style '\' character escapes                                     [x]
      b-compound-assign      Recognize B-style assignment operators like '=+'                            [x]

]~/Documents/TrulyMine/cbc@ 

The project is currently in its infancy, and the long-term goals are very ambitious. This is the current roadmap:

ROADMAP
(i) Tests
  • Make a script that takes the tests from tsoding/b, and filters the tests.json to only include the IR tests
  • Make a Go program that runs each test, displays the passing/failing ones
(ii) Compatibility with tsoding/b
  1. Support the "extrn" keyword, as well as inline assembly
  2. Use the same warning & error messages tsoding/b / our warnings n errors are much better
  3. Be able to pass the IR tests of tsoding/b
(iii) Packages / Modules inspired by Go
  • ¿.. Namespaces based on .mod file ..?
  • Implement a way to import/export symbols from different .B files, in different namespaces

Contributions are hyper-mega welcome

References
Not B-related, but I did find these helpful for learning how to write the compiler:
  • comp-bib: "Resources for Amateur Compiler Writers"
  • qcc: dead-simple C compiler
  • cproc: QBE-backed compiler written in C99, with support for some C23 & GNU C extensions
Cool stuff used by this project:
  • QBE: The QBE compiler backend

TODO: ...I should write a Limbo compiler when I finish this project...

About

C B Compiler, a working B compiler that is fully compliant with B, with nice warnings and errors, configurable via standard flags like -W/-Wno, and -F and -Fno to turn on/off warns/features. -std=B/-std=Bx for some extensions. Compatible with tsoding/b

Topics

Resources

License

ISC, Unknown licenses found

Licenses found

ISC
LICENSE
Unknown
LICENSE.RABRMS

Stars

Watchers

Forks

Releases

No releases published