Skip to content

Repository files navigation

YELLE / yellec

Yet Another Language Experimental Compiler — a small frontend that parses .yl sources, lowers them to C, and drives TinyCC as the backend for transpile, in-process JIT, and executable builds.

Author: Philipp Andrew Roa Redondo.

Licensing

  • Original compiler sources (main/, main.c, Makefile, build.bat, tests/*.yl, docs): MIT License — see LICENSE.
  • TinyCC (thirdparty/tinycc/): LGPL-2.1 — full text thirdparty/tinycc/COPYING.
  • libunicode / cutils (thirdparty/libunicode/): MIT — see copyright notices in each file.

Because yellec may statically link libtcc.c, redistributing binaries triggers LGPL 2.1 obligations for the TinyCC-linked portions (shared-library linking vs. relinking rules). Read LGPL_COMPLIANCE.md and NOTICE.

What’s in this repo

Area Role
main.c CLI, orchestration, TinyCC wiring (dump / run / compile / produce), diagnostics
main/ Lexer (tokenizer), parser, AST (ast), type tags (typetag), codegen (compiler), shared definitions (global), runtime state (state, context)
tests/ Example .yl programs (strings, lists, arrays, inline C, probes) — run manually with yellec
thirdparty/tinycc TinyCC submodule (headers, libtcc, Win32 runtime)
thirdparty/libunicode Unicode helpers used by the tokenizer (expects QuickJS cutils.c / cutils.h alongside, per build.bat)
build/ Build output directory when using build.bat (yellec.exe, synced TinyCC win32 tree)

The language surface is still evolving; main/keyword.h lists reserved words (mod, fn, var, let, control flow, numeric types, string, etc.). What is fully wired end-to-end depends on the current parser and compiler passes — use tests/ as living examples.

Building

Windows (build.bat)

Prerequisites:

  • GCC on PATH (gcc)
  • TinyCC sources under thirdparty\tinycc (submodule)
  • thirdparty\libunicode with libunicode.c and bundled cutils.c / cutils.h (the batch file checks for these)

From the repo root:

build.bat

This script:

  1. Verifies dependencies and generates thirdparty\tinycc\config.h if missing
  2. Copies the TinyCC Win32 runtime into build\win32 and runs TinyCC’s build-tcc.bat to populate runtime pieces
  3. Compiles main.c, main\*.c, libunicode, and libtcc.c into build\yellec.exe

Unix / macOS (Makefile)

From the repo root (requires gcc, populated thirdparty/tinycc, and thirdparty/libunicode with cutils.c / cutils.h):

make debug    # default; AddressSanitizer on non-Windows
make release

On non-Windows, --run uses libtcc in-memory JIT and adds common system include/library paths in main.c. You can also mirror the gcc line from build.bat if you prefer not to use Make.

Command-line interface

All modes require -f / --file pointing at a .yl source unless you only dump C (you can combine dump with run).

Option Meaning
-f, --file <path> Input .yl file
-d, --dump <out.c> Write generated C to disk
-r, --run Execute generated code (Win32: spawns build\win32\tcc.exe; else: libtcc JIT)
-c, --compile <exe> Emit an executable
-p, --produce <exe> Emit an executable with TinyCC options -O2 -DNDEBUG

Examples:

build\yellec.exe -f tests\test.yl -d out.c
build\yellec.exe -f tests\mini_test.yl -r
build\yellec.exe -f tests\string_concat.yl -c build\app.exe
build\yellec.exe -f tests\test.yl -p build\app-fast.exe

Dump-only (no run/compile): -f file.yl -d out.c satisfies the CLI without -r/-c/-p.

How compilation fits together

  1. Tokenizer (main/tokenizer.c) produces tokens from UTF-8 source.
  2. Parser (main/parser.c) builds an AST (main/ast.c, main/global.h).
  3. Compiler (main/compiler.c) walks the AST and emits C into per-context buffers, then file_linker (main/global.h) concatenates module/function chunks for TinyCC.
  4. TinyCC compiles that C either to memory (JIT), or to an .exe/ELF-style executable depending on platform and flags.

Embedded C snippets use the /***BEGINEND***/ regions (see tests/test.yl, tests/string_concat.yl).

Tests (tests/)

There is no root-level automated test runner; scripts under tests/ are sample programs to exercise the toolchain:

  • mini_test.yl — minimal mod + main + println-style usage
  • string_concat.yl — string literals and + concatenation (runtime helpers emit YL_string glue in generated C)
  • list_test.yl, list_min*.yl, expr_*, list_probe_* — list-oriented samples (push, peek, indexing, etc., as supported by the compiler)
  • lit_array_inline.yl — fixed-size array literal style {i32,n}{…}
  • lit_list_inline.yl, expr_inline_list_* — inline list forms

Use -r or -c/-p on individual files to validate behavior as the language grows.

Contributing / hacking

  • main/global.h — central enums (AstType, TokenType), Ast layout, State/Context, error reporting helpers
  • main/typetag.c — maps semantic types to C spellings and default values
  • After changing AST shapes or codegen, update main/compiler.c and add or adjust a sample under tests/

Third-party notice

See NOTICE. TinyCC is LGPL-2.1; binary redistribution with static libtcc is covered in LGPL_COMPLIANCE.md.

About

An experimental compiler that targets C

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages