8000 GitHub - gwf/x2c: compiler and runtime for the x2c programming language · GitHub
[go: up one dir, main page]

Skip to content
gwfPublic

About

compiler and runtime for the x2c programming language

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Latest commit

 

History

5,124 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

x2c

C with batteries, without bullshit.

x2c extends C with collections, dynamic values, pattern matching, scoped allocation, exceptions, threads, and compile-time Lisp. It compiles to C and uses ordinary C compilers and libraries. You can use the added features where they help and keep ordinary C elsewhere.

The compiler and runtime are written in x2c. You can read their source, change it, and rebuild the language itself.

A small example

Save this as hello.x:

int main(void) {
  Array names = ["Ada", "Grace", "Linus"];
  foreach (String name, names)
    printf("Hello, %s!\n", name);
  return 0;
}

Array literals and iteration work alongside ordinary C functions. The runtime is available without an explicit include. The language tour shows more: maps, matching, memory scopes, exceptions, and macros.

Build and run

From a checkout, you need a GCC- or Clang-compatible C compiler, ar, GNU Make, Python 3, and Bash. You do not need an existing x2c compiler: the checkout contains generated C for the bootstrap.

make build-safe
./x2c run hello.x

run compiles and executes the program. To keep an executable instead:

./x2c build hello.x --output hello
./hello

For a ready-made program, try ./x2c run examples/foreach.x. For installation outside the checkout, follow the installation guide. It covers release installation and building an installed compiler from source.

What to explore

  • Examples: small programs and larger applications you can run and modify.
  • The book: language guide, reference, standard library, and compiler internals. Start with values and idioms.
  • C libraries: optional packages for databases, graphics, networking, parsing, and other native libraries.
  • Command-line reference: compilation, projects, scripts, inspection, and build options. ./x2c --help lists commands.
  • Performance examples: programs, measurements, and comparison methods. Results depend on the workload and machine.

Status and compatibility

x2c is experimental and actively developed. APIs and language details can change. It aims to keep C useful inside a higher-level language, but it does not accept every C preprocessing pattern unchanged. Read the C compatibility notes when bringing existing C source into x2c.

The language reference documents supported behavior and limitations. The repository checks runtime behavior, compiler fixtures, and self-hosted builds; those checks do not imply compatibility with every platform or C library.

Reading the implementation

Start with the source guide. It explains the compiler's flow, files, and module directories. Each module directory has its own guide to the entry file and implementation members.

Directory What is there
src/ Compiler, driver, compile-time operations, and syntax lowering.
lib/ Runtime values, collections, memory, IO, concurrency, and Lisp.
commands/ External commands such as project creation, packages, and the REPL.
examples/ Executable language examples and applications.
packages/ Optional adapters for third-party C libraries.
unittest/ Runtime tests, compiler fixtures, and focused probes.
bootstrap/ Generated C used to build the first compiler.
builds/ Working compiler stages and generated build outputs.
docs/ The book's source.
site/ The public website.

Compiler architecture explains the phases. Building the compiler explains self-hosting and the available checks. Edit the .x sources; regenerate bootstrap C through the build targets.

Short glossary

Term Meaning in x2c
Module A source unit with one responsibility. It can be one file, or an entry file with members listed in a module { ... } block.
Member An implementation file listed in a module block. It compiles as part of the entry's unit. See the module visibility rules for which declarations other files can use.
Translation unit The source compiled together into one generated C source file. A module's entry and all its members form one translation unit.
Component Here, an independent source unit in src/components/ that implements a language feature, such as matching or exceptions. This is a repository term, not a language keyword.
Package A named directory with an entry source file and the sources it includes. Packages expose public names under a package prefix. The adapters in packages/ wrap third-party C libraries.
Include #include "foo/foo.x" makes a source unit's public declarations and compile-time definitions available. C headers use ordinary #include directives.
Import import "geo"; finds a package through configured package directories and binds an alias, so callers can write geo.Vec. as changes the alias; with exposes selected names directly.
Runtime The library code used by compiled programs: collections, Strings, memory management, IO, and other facilities in lib/.
Prelude Definitions made available automatically when compiling a source unit, including the standard runtime and shipped syntax rules.
Bootstrap The checked-in generated C used to build x2c without an existing x2c compiler. Later builds use x2c to compile its own source.

See the language reference for module blocks and packages and imports.

License and project policy

x2c is available under the Apache License 2.0. Forks are welcome. The project is not accepting external code contributions; see CONTRIBUTING.md. Development follows the author's priorities, without a promised roadmap, release schedule, or support commitment.

See THIRD_PARTY.md for dependency notices, SECURITY.md for vulnerability reporting, and SUPPORT.md for support policy. GOVERNANCE.md and TRADEMARKS.md describe project authority and use of the name. The project website is x2c-lang.dev.

About

compiler and runtime for the x2c programming language

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0