Skip to content

Repository files navigation

Jik

A readable, statically typed language that compiles to C and manages memory with regions.

Jik logo

CI Website Discord Status Backend Memory

Open a ready-to-use Jik development environment.


What is Jik?

Jik is a statically typed programming language with a straightforward source-to-C compilation model. It avoids both garbage collection and manual heap allocation.

It provides type inference, optional type annotations, vectors, dictionaries, options, variants, exhaustive enum/variant tables, error handling, a standard library, and a growing package ecosystem. The result is concise source code and predictable generated C.

Jik's defining idea is its memory model: composite values are allocated into regions that determine their lifetime, while compiler checks prevent references across regions with incompatible lifetimes.

Examples

Hello, Regions!

Functions that return composite values let the caller choose the destination region:

func default_actions(r: Region) -> Vec[String]:
    return ["Open", "Save", "Quit"][r]
end

func main():
    actions := default_actions(_)
    println("first action: ", actions[0])
end

_ is the current function's local region. For a longer-lived result, pass an explicit Region or the region of another composite value.

Parsing a config
use "jik/string"

func main():
    text := "host = localhost\nport = 8080\nmode = dev\n"
    settings: Dict[String]

    for line in string::split(text, "\n", _):
        parts := string::split(line, "=", _)
        if len(parts) != 2:
            continue
        end
        key := string::trim(parts[0], _)
        value := string::trim(parts[1], _)
        settings[key] = value
    end

    host := settings["host"]
    port := settings["port"]
    if host is Some and port is Some:
        println("connecting to ", host?, ":", port?)
    end
end
Error handling
throws func safe_div(x, y):
    if y == 0.0:
        fail("division by zero")
    end
    return x / y
end

func show_div(x, y):
    try value := safe_div(x, y):
        println(x, " / ", y, " = ", value)
    except:
        println("cannot divide ", x, " by ", y, ": ", error_msg())
    end
end

func main():
    show_div(12.0, 3.0)
    show_div(7.0, 0.0)
end

Explore more

See the examples directory for variants, tables, more error handling, word count, Dijkstra, Newton's method, Game of Life, Forth, and C interop.

Packages

Jik packages provide reusable libraries and C bindings for writing larger programs.

Showcase

Quick start

To start programming in Jik:

  • download the latest release for your platform
  • extract the release archive
  • from the extracted directory, run jik help to confirm the executable works
  • (optional) add the extracted directory to PATH
  • if you plan to use jik run or jik build, either pass the compiler name with --cc or set JIK_CC, for example to gcc or clang
    • Windows: For a simple GCC setup, download from WinLibs, and add its bin directory to PATH
  • save a copy of the example as hello.jik
  • run it: jik run hello.jik
  • generate C output: jik tran hello.jik
  • build an executable: jik build hello.jik

Only gcc and clang host compilers were tested. MSVC was not tested.

Building Jik from source

To build Jik from source, you will need make and a C compiler:

  • download the Jik repository and navigate to the root
  • run make

Additionally, to run the Jik test suite:

  • run make test

Note that MSVC was not tested and is not the default build path in this repository

VS Code support

Download jik-language-tools-*.vsix from the latest release. In VS Code, open the Extensions view, select the ... menu, choose Install from VSIX..., and select the downloaded file.

The extension provides syntax highlighting, import-aware standard-library completion, and hover documentation and signatures.

Further reading