KonLang Tiếng Việt

Tools

One command does everything, and programs it builds need nothing of Kon to run.

One file

kon.exe holds the compiler, the library and the parts of Clang it needs. Nothing else has to be installed, and no environment variables have to be set. The first run unpacks about 310 MB to %LOCALAPPDATA%\Kon, which takes 10 to 15 seconds; after that a small program builds and runs in about 0.2 seconds.

To remove it, delete kon.exe and that folder.

Commands

CommandWhat it does
kon run game.konBuild, run, clean up
kon run game.kon --release -- a "b c"With optimization and program arguments
kon build game.kon --releaseMake game.exe, which needs no Kon to run
kon check game.konReport errors and make nothing
kon testBuild and run every *_test.kon under this folder
kon fmtTidy every .kon file under this folder
kon new gameMake a new project
kon licenseWho made it, the terms, and where the full texts are
--link bridge.c -lgdi32Add your own C files or system libraries to any build

Projects

A project is a folder with kon.toml and src/main.kon. Inside one, kon run, kon build and kon test need no file name, and the program goes to build/.

kon new game           make game/ with kon.toml, src/main.kon and tests/main_test.kon
kon add ../mathlib     use another project on this machine
kon remove mathlib
kon deps               show the dependency tree
kon sync               refresh build/deps and kon.lock
kon sync --locked      refuse if anything differs from kon.lock
kon clean              remove build/

Commands run in the folder holding kon.toml. Code imports a dependency from where it is copied, as import "../build/deps/mathlib/math.kon" as math from src/. A dependency imports another as import "../other/other.kon".

Dependencies are folders on your machine only: there is no registry and nothing is downloaded. kon.lock holds a hash of each one, which shows that it changed, not that it can be trusted.

kon fmt

It changes only spacing, indentation, blank lines and line endings. It formats only files that parse, and it reads its result back before writing: if the tokens are not the same, the file is left alone. Across all the Kon files in the project when it was added, 659 of them, formatting twice changed nothing, and 59 test programs behaved the same after being formatted.

kon fmt                    tidy this folder
kon fmt --check            write nothing; exit 1 if anything would change
kon fmt --stdout game.kon  print the result

It works on tokens so far, so it does not yet split several statements off one line or wrap long lines.

kon test

A test is a program that exits 0. There is no framework to learn.

func add(a: i32, b: i32): i32 {
    return a + b
}

func main(): i32 {
    if add(2, 2) != 4 { return 1 }
    return 0
}
ok    .\math_test.kon
FAIL  .\text_test.kon (exit 3)
2 tests, 1 failed

Errors

Errors name the file, line and column. Where two places are involved, the second is named too.

K2-OWN-001: value was moved or is not initialized at game.kon:4:11
K2-RELATED: related ownership location at game.kon:3:17

VS Code

The extension in editors/vscode adds a run button and F5, marks errors on their line when you open or save a file, including errors in imported files, formats on save, and has highlighting, snippets, hover help and an outline.

It looks for kon.exe in the konlang.compilerPath setting, then at %LOCALAPPDATA%\Kon\kon.exe, then on PATH.

node editors/vscode/package_vsix.js .
code --install-extension konlang-2.0.4.vsix

Building kon.exe

There is no public download yet. From a checkout of the source, with llvm-mingw:

node v2/compiler/build.js <seed compiler> <llvm-mingw>/bin/clang.exe
node v2/dist/build.js target/v2-current <llvm-mingw> kon.exe
node v2/dist/test.js kon.exe

Limits

  • Windows x64 only. The library's C code also runs on Linux, but there is no Linux kon yet.
  • No building for other systems yet.
  • It still contains Clang, which is most of its 67 MB. A backend of Kon's own would remove that from debug builds.
  • It carries LLVM and mingw-w64 under their own terms; kon license shows where their texts are.
  • The file is not signed, so Windows SmartScreen or antivirus software may warn about it.
  • Syntax and type errors are short, a code and one word, because the compiler gives no more so far. The error list explains them.