Skip to content

Adding commands to the compiler. - #14

Merged
FernandoTheDev merged 2 commits into
masterfrom
dev
Jul 21, 2026
Merged

Adding commands to the compiler.#14
FernandoTheDev merged 2 commits into
masterfrom
dev

Conversation

@FernandoTheDev

Copy link
Copy Markdown
Owner

This commit adds a command system to the Cx compiler (cx <command>) and makes several other changes. Summary:

New CLI commands

  • cx build — scaffolds a new Cx project (generates src/main.cx and cx.json), implemented in the new src/builder.d.
  • cx compile — compiles an existing Cx project by reading its cx.json.
  • cx run — compiles and then runs the project.
  • Major refactor of main.d: the compilation logic was extracted into a reusable compile() function that takes a CXArgs struct (previously everything lived inline in main), allowing compile/run/direct .cx file usage to share the same code path.
  • New --gcc flag to force GCC as the C compiler, and the auto-detection order for the C compiler now prefers tccgcccc.

Language/compiler (codegen & parser)

  • Enums now generate a _ids array in the emitted C code (Foo_ids[]) mapping each variant to its name as a string, and support was added for enum.id syntax to get the enum variant's name at runtime (used to replace manual functions like opCodeToStr).
  • Arrow functions (=> expr) now require a trailing ; (fixed across several examples and the standard library where the semicolon was missing).
  • Small indentation fix in a generated foreach loop.
  • Type resolver now propagates the left-hand side's type as a "reference" type when resolving the right-hand side of binary expressions.
  • In the VM example, a return was changed to continue in the "Print" opcode case.

New examples

  • examples/kernel/: a small bare-metal x86 kernel written in Cx (assembly bootloader, entry trampoline, linker script, Makefile, and a kernel.cx that draws a text-mode VGA interface).
  • examples/windows/langtoy.cx: a toy language interpreter (lexer + parser + expression evaluator supporting let, print, assignments) written in Cx.
  • examples/windows/main.cx: a simple example with addition and pointers.
  • examples/enum2.cx and examples/dot_anon4.cx: new examples testing enums and nested anonymous initializers.

Other

  • .gitignore now ignores *.o, *.bin, *.img (build artifacts from the kernel example).
  • Compiler version bumped from 0.2.1 to 0.2.2.
  • The unit test runner (tests/unit.d) now wraps to!int in try/catch instead of letting the exception propagate.

@FernandoTheDev
FernandoTheDev merged commit c7c2f31 into master Jul 21, 2026
4 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