TokenVector

English | Tiếng Việt

.NET 10 version 1.0.15 tests 136/136 builtins 423 License: MIT

TokenVector (.tkv, .tv)

A statically-typed language that compiles to .NET CIL and links into a standalone .exe. Write in Python-like syntax; ship a native binary with no interpreter, no Python, no runtime bundle, no GIL.

The repository root holds the release build and this README. Everything else — compiler source, docs, tests, gates, examples — is inside Release/.


Quick start (Windows, 3 steps)

1. Get the release

git clone https://github.com/nguyenhungtran18/TokenVector.git
cd TokenVector

2. Write a program

Save this as hello.tkv (plain UTF-8, no BOM — see §Known gaps):

# -*- coding: utf-8 -*-
def mean(xs: "list[f64]") -> "f64":
    if len(xs) == 0:
        return 0.0
    total = 0.0
    for x in xs:
        total = total + x
    return total / len(xs)

def run() -> "i32":
    data = [1.0, 2.5, 4.0]
    print("mean = " + str(mean(data)))
    return 0

3. Compile and run

Release\dist\tkvc-tv.exe hello.tkv hello.exe run
.\hello.exe

Output:

mean = 2.5

The CLI is positional — tkvc-tv.exe <source.tkv> <output.exe> <entry>.

The resulting hello.exe is 9.5 KB (a bare print("hi") is 6 KB) and runs on any machine with .NET 10. Nothing else is installed alongside it.

Requirement: the compiler itself (tkvc-tv.exe) is a Windows PE and needs .NET 10 on the build machine. Programs it produces need the same framework on the run machine — that is the only dependency.


What you get

   
Output one standalone .exe (PE), 6 KB for a bare print, 9.5 KB for the example above
Types unboxed i32 / i64 / f32 / f64 / str, plus int and bool
Runtime .NET 10 — no interpreter, no GIL
Threads thread_spawn / thread_join, true multicore with no global lock
SIMD f32x4 → System.Numerics.Vector4; elementwise loops are auto-vectorised (P6); simd_gemm runs a native AVX2+FMA kernel for f32/f64 matmul
Interop any .NET/NuGet assembly, P/Invoke, and raw C FFI

Honest positioning — where it wins and where it does not

Measured 2026-11-12 against CPython 3.14.7 and NumPy 2.5.2. Full method and checksums: Release/benchmark/KETQUA.md.

Against CPython, TokenVector wins on every kernel in the harness:

kernel TokenVector CPython faster by
fib(32) 14.74 ms 1100.2 ms 74.6×
sort 1.370 ms 37749 ms 27554× (different algorithms; see note)
matmul32 (native) 3.1 µs 313.7 ms 101189×
add 0.580 ms 1540.6 ms 2657×
string 3.414 ms 285.8 ms 83.7×

Against NumPy the picture is mixed, and string is now bounded by join, not per-character allocation:

kernel TokenVector NumPy 2.5.2 faster by
matmul32 (simd_gemm, f64) 3.1 µs 5.3 µs TokenVector 1.71×
matmul32 (IL f32x4 path) 9.0 µs 5.3 µs NumPy 1.71×
add 0.580 ms 0.854 ms TokenVector 1.47×
sort 1.370 ms 3.932 ms TokenVector 2.87× (different algorithms; see note)
string 3.414 ms 2.271 ms NumPy 1.50×
string — SIMD scan row 3.326 ms 2.271 ms NumPy 1.46×

NumPy is native machine code (BLAS/ufuncs), not a managed runtime. The IL path cannot chase BLAS consistently; simd_gemm is the native route. The sort row uses a 16-bit counting kernel on this workload and falls back to merge for negative/out-of-range input, so its ratio measures a different algorithm, not a general-purpose comparison sort.

Is every number above checked?

Yes — the repository carries its own gates, and the table below is the output they actually print. If a gate is not green, the claim above does not hold.

Gate Command Result
Compiler acceptance powershell -File Release\tools\testkit_gate.ps1 136/136 pass, 44/44 negative cases correctly rejected
Self-host fixpoint Release\tools\vong.exe IL_IDENTICAL (133 files)
Performance powershell -File Release\tools\perf_gate.ps1 4 kernels, best-of-5, checksum is compared
Lint-rule self-test powershell -File Release\tools\lint_rules_gate.ps1 8/8 traps caught, 0 false positives
Registration Release\dist\tkvc-tv.exe Release\tools\dang_ky_gate.tkv Release\build\dk.exe run 0 violations

Builtins registered: 423.

The compiler itself is self-hosted: its source is 133 .tkv files under Release/compiler_bootstrap/. Release\tools\vong.exe concatenates them, compiles the result twice, and requires the two IL dumps to match byte-for-byte (IL_IDENTICAL).


Repository layout

TokenVector/
├── README.md            this file
├── README.vi.md         Vietnamese translation
├── LICENSE              MIT
└── Release/             the full release snapshot
    ├── compiler_bootstrap/   133 .tkv files — the compiler, written in TokenVector
    ├── compiler_src/         ds_gop.txt manifest used to concatenate them
    ├── dist/                 tkvc-tv.exe (the compiler) + il_features/
    ├── tests/                136 acceptance tests + 44 negative cases
    ├── tests_suite/          154 .ca data-driven cases + 203 input samples
    ├── tools/                gates + tkv_guide.tkv (the language guide)
    ├── projects/             19 real tools written in .tkv
    ├── examples/            sample programs + stdlib/
    ├── docs/                all documentation
    ├── packaging/           NuGet nuspec, MSBuild props/targets, pack.ps1
    └── assets/              diagrams, HTML demos, preview image

Clone the repo and the release is already there — nothing to download separately, nothing to build.


Documentation

Document What it is
Release/docs/REFERENCE.md The one reference. Syntax, behaviour, and every Python difference per builtin
Release/docs/HANDBOOK.md Bilingual orientation + the rules that bite most
Release/docs/HANDBOOK.vi.md Full 10-chapter handbook (Vietnamese)
Release/docs/TUTORIAL.md Programming guide, chapter by chapter
Release/docs/ARCHITECTURE.md Compiler pipeline and file registry
Release/docs/COMPARISON-PYTHON.md Where TokenVector differs from CPython
Release/docs/PLAN.md Gap list, ranked by difficulty
Release/docs/REPOSITORY-NOTES.md Engineering journal: every bug found, and how it was proven
Release/docs/ROADMAP.md Product roadmap
Release/docs/llms.txt Compact machine-readable summary

Ask the tool, not your memory

tkv_guide is written in TokenVector and is the single source of truth for language rules. Build it once, then query it:

powershell -File Release\tools\build_tkv_guide.ps1

Release\dist\bin\tkv_guide.exe rules               # the pitfalls that actually bite
Release\dist\bin\tkv_guide.exe find sorted         # exact syntax + how it differs from Python
Release\dist\bin\tkv_guide.exe names iter          # registered builtins, per module
Release\dist\bin\tkv_guide.exe lint my_file.tkv    # traps the compiler silently ignores
Release\dist\bin\tkv_guide.exe verify my_file.tkv  # prints the exact build+run commands

verify only prints the two commands — TokenVector cannot spawn a process yet, so the tool cannot build for you. Run both and read the output.

A green build is not a correct program. Bugs exist that compile cleanly and then return a wrong value. Always build and run.


Things that will surprise a Python programmer

All of these were probed, not assumed:

Known gaps

Verified by probe; the ranked list with difficulty is Release/docs/PLAN.md.

Interop

Rebuilding the compiler

Nothing needs rebuilding to use the release. To work on the compiler itself:

cd Release
tools\vong.exe

That concatenates compiler_bootstrap/, compiles it twice, and prints IL_IDENTICAL when the fixpoint holds. IL KHAC NHAU means the compiler upgraded itself — just run it again. Then:

powershell -File tools\testkit_gate.ps1

Editor support

Licence

MIT © 2026 TokenVector Project / Nguyen Hung Tran.


Roadmap: Release/docs/ROADMAP.md · Strategy: Release/docs/STRATEGY.md · Engineering history: Release/docs/REPOSITORY-NOTES.md