Skip to main content

The Generic Programming Language

This is the main source code repository for Generic. It contains the interpreter, the bundled standard library, and the documentation.

Documentation

  • Language guide - syntax, types, classes, exceptions, modules, the standard library, and the built-in unit-test framework, for people writing generic programs.
  • Plugin authoring guide - write native modules (Rust, C, C++, Zig) loaded with a plain import. API reference: generic-lang-api on docs.rs.
  • Architecture - internals for contributors: the scanner → compiler → bytecode → VM pipeline, the value/heap/GC model, the exception model, and the load-bearing invariants.

The workspace is three crates: generic-lang (the generic binary), generic-lang-lib (the interpreter as a library), and generic-lang-api (the plugin ABI/authoring API).

Influence

Generic is based on the Lox programming language created by Bob Nystrom for his excellent book Crafting Interpreters.

This implementation is written in Rust and very closely based on clox-rs. The walkthrough of the book alongside clox-rs can be found in the previous repo.

Syntax highlighting

A rudimentary vscode extension exists in the form of generic-lang-vscode.

Building

The interpreter can be built like this:

cargo build --release

Installation

I recommend installing Generic by building from the source code as follows:

# Download the source code
git clone https://github.com/JanEricNitschke/generic-lang
cd generic-lang

# Install 'generic'
cargo install --path .

Or more simply:

cargo install generic-lang

Or install with uv (recommended), pip, or pipx:

# With uv.
uv tool install generic-lang  # Install generic globally

# With pip.
pip install generic-lang

# With pipx.
pipx install generic-lang

Now to use generic, in your terminal, run:

generic

Testing

Generic supports two types of testing:

Unit Testing (Built-in)

The language includes built-in unit testing support. Write test functions (starting with test_) and run them with:

generic --test your_file.gen

This will discover and run all test functions in isolation, providing detailed reporting. See the Testing chapter of the language guide for complete documentation.

Integration Testing

A comprehensive integration test suite and driver can be found in test and tool respectively. The driver is written in Dart and taken directly from the book repo of Crafting Interpreters. The suite is an extension of the one that can be found in the same repository.

To run the full integration test suite:

make test

Native plugins

Generic programs can load native modules - shared libraries (.so/.dylib/.dll) - with a normal import:

import "demo";
print(demo.add(19, 23));   # 42

Plugins are written in Rust against the generic-lang-api crate, or in any C-ABI language against the generated crates/generic-lang-api/include/generic.h. Worked examples in Rust, C, C++, and Zig live in plugin-examples/. See the plugin authoring guide.

Benchmark

Benchmarking Generic against the official c and java lox implementations as well as, to a limited degree, python and ruby is also possible. The reference programs for that can be found in benchmark.

The benchmarking setup is driven by hyperfine which has to be installed and added to the path separately. This also holds for ruby and python.

However, the main benchmarking is against the lox implementations. For those runs to be possible the two versions have to be install from the book repo and placed into the (relative) path

{generic-lang}/reference/craftinginterpreters.

Running the benchmark on linux is done via:

make benchmark-ci

To run the benchmarking on windows a jlox.bat with the following content:

@echo off

set "script_dir=%~dp0"
java -cp "%script_dir%\build\java" com.craftinginterpreters.lox.Lox %*

first has to be placed in the craftinginterpreters directory.

The benchmarking is then run via:

make benchmark

Metadata

Release files for generic-lang 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generic-lang 3.1.0
File Size Uploaded Provenance
generic_lang-3.1.0.tar.gz 273.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for generic-lang 3.1.0
File
generic_lang-3.1.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
generic_lang-3.1.0-py3-none-win32.whl Python 3 none Windows x86-32 Details
generic_lang-3.1.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details
generic_lang-3.1.0-py3-none-musllinux_1_2_i686.whl Python 3 none Linux musl 1.2+ x86-32 Details
generic_lang-3.1.0-py3-none-musllinux_1_2_armv7l.whl Python 3 none Linux musl 1.2+ ARMv7l Details
generic_lang-3.1.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details
generic_lang-3.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
generic_lang-3.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl Python 3 none Linux glibc 2.17+ IBM System/390x Details
generic_lang-3.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl Python 3 none Linux glibc 2.17+ PowerPC 64-le Details
generic_lang-3.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl Python 3 none Linux glibc 2.17+ x86-32 Details
generic_lang-3.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl Python 3 none Linux glibc 2.17+ ARMv7l Details
generic_lang-3.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
generic_lang-3.1.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 23.2 MB

Release files / generic_lang-3.1.0.tar.gz

Download URL generic_lang-3.1.0.tar.gz
Size 273.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b1c5ef7dd06b7e84d9d404d261e428b55802ad9bb7bd0fa06496f60ed5fed1b1
BLAKE2b-256 checksum
How to use checksums
6aa7fd0587f166d86e2f3ecf9aee0f5b0f3fe5461b19b9f021c85d179aaf523d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-win_amd64.whl

Download URL generic_lang-3.1.0-py3-none-win_amd64.whl
Size 1.6 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ff9dd32a2c6fbec241a01e4a16af2920ec3a555f13e402ef61cda7f3d5c70fcb
BLAKE2b-256 checksum
How to use checksums
cbd730f2837b54405e75324eafaef0cc451a142debed0ab7e18d9bc4f6e7b3c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-win32.whl

Download URL generic_lang-3.1.0-py3-none-win32.whl
Size 1.4 MB
Tags Python 3 Windows x86-32
SHA-256 checksum
How to use checksums
82fdab30f9ac46f35049ae3ac48519e8013ab035143e4bcfab7cb70e433b93a1
BLAKE2b-256 checksum
How to use checksums
1cc22897619176faeab5967a58bf9438a683bc0595b2d4cbd1e2f66be116e7d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-musllinux_1_2_x86_64.whl

Download URL generic_lang-3.1.0-py3-none-musllinux_1_2_x86_64.whl
Size 1.9 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
12d6b79940c40cfce05574e94f362e8086e4f805d2224c84e35f180c40efefff
BLAKE2b-256 checksum
How to use checksums
7f28d5646caec6dd560a28bdb2f90c687ac32239d9c3513293a406d78d373901
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-musllinux_1_2_i686.whl

Download URL generic_lang-3.1.0-py3-none-musllinux_1_2_i686.whl
Size 1.8 MB
Tags Linux musl 1.2+ x86-32 Python 3
SHA-256 checksum
How to use checksums
28c87e02caeca185c398f2a0b8235ee1dc86562b95b28e05d646abf2cbb04169
BLAKE2b-256 checksum
How to use checksums
9ce2faf63f5a4bee8c3adca5d5cf80932b3a6c3b7ca1bb99232252230a3e7708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-musllinux_1_2_armv7l.whl

Download URL generic_lang-3.1.0-py3-none-musllinux_1_2_armv7l.whl
Size 1.7 MB
Tags Linux musl 1.2+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
d5aadc4ff87bfdd677e6df0ecb5e65006b0f2247d18913b2a80a9ad759c6d13a
BLAKE2b-256 checksum
How to use checksums
cac2048375f69f226db2807e56d65dc478d343c90a6861f21abf2804dea807ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-musllinux_1_2_aarch64.whl

Download URL generic_lang-3.1.0-py3-none-musllinux_1_2_aarch64.whl
Size 1.9 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
0d2d307879f14dfff26f3d94aa079a161da203b54f7f2b48c56f892e8570ea04
BLAKE2b-256 checksum
How to use checksums
d2aa234a33eef94c1456cdc4d50d95006df8f10806b9af68f0c255ffa9591c66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL generic_lang-3.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.9 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
75cd278ea1cd8233985c795c2081a1d86e43627afed6f7e48cedbf3d9339ea3d
BLAKE2b-256 checksum
How to use checksums
c65eb39fd2569622ea0d4654953b8d0794851c73a6ab68574a35f2e5b015d45d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL generic_lang-3.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 1.9 MB
Tags Linux glibc 2.17+ IBM System/390x Python 3
SHA-256 checksum
How to use checksums
aee0c753338781aa7842efe4e0e9475742279ed4630a8b436b194886fb0d9229
BLAKE2b-256 checksum
How to use checksums
1dfb86cd6089ccd7a2551955af1592c5cec202f94b6d99304ed6883633e7aace
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL generic_lang-3.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 2.0 MB
Tags Linux glibc 2.17+ PowerPC 64-le Python 3
SHA-256 checksum
How to use checksums
75bc16f8f84d7355d1c2ffe7ded7e33fcc3dccdd20df5407a9c122bd2c86c1b5
BLAKE2b-256 checksum
How to use checksums
dd9bdb7aad9194e606535571d8726d525a85c1f09dadd8945e193b9050af378a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL generic_lang-3.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Size 1.8 MB
Tags Linux glibc 2.17+ x86-32 Python 3
SHA-256 checksum
How to use checksums
feaff6bba5132181dcfd86c1b3a697c4ff6f04f6d8cae6402688c8afe3ee7c90
BLAKE2b-256 checksum
How to use checksums
5a44d26fe62502b8ef1c7cde3ac104153a39bc139ed9613608b022cdfe30ea6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL generic_lang-3.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 1.7 MB
Tags Linux glibc 2.17+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
109a9d230587b28d60653141c5632406e355d8453ab1a55ea1ca0193ff82011f
BLAKE2b-256 checksum
How to use checksums
cc54f16d4b339f2de76160b3287bbd1471e101a2f531f6a6f1c638baa1a56e81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL generic_lang-3.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.8 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
f37373c7d9dbec483a2fc9c6d5d4511437a9b062861d91480a2d476ad78a71b5
BLAKE2b-256 checksum
How to use checksums
e00a184a3c76ef7dcf53816fbd1b363c06d2b1284840a657eaa378bc2df505a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Release files / generic_lang-3.1.0-py3-none-macosx_11_0_arm64.whl

Download URL generic_lang-3.1.0-py3-none-macosx_11_0_arm64.whl
Size 1.7 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cc104a32a6fc597c6d5c13baf778ade53ee10cfe6316be96ef83e57306e83b94
BLAKE2b-256 checksum
How to use checksums
d0c980711d30466aa5361e04e874abf07a4d4ada79514147c6db45b1a5dc40e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.14.1

Security for generic-lang 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page