No description
  • C++ 97%
  • CMake 1.9%
  • C 1.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-04-02 16:16:20 +03:00
.github/workflows Implement constexpr compiler with basic features & rework VM opcodes (#6) 2026-03-08 19:45:16 +03:00
3party/frozen Lexing 2026-01-29 01:49:43 +03:00
cmake Use CPM for dependencies & use Catch amalgamated version 2026-02-24 13:37:35 +03:00
include/korka Implement bindings (#12) 2026-04-02 16:16:20 +03:00
src/vm Basic VM runtime & function calling (#11) 2026-03-20 10:56:47 +03:00
test Implement constexpr compiler with basic features & rework VM opcodes (#6) 2026-03-08 19:45:16 +03:00
.gitignore Lexing 2026-01-29 01:49:43 +03:00
CMakeLists.txt Implement bindings (#12) 2026-04-02 16:16:20 +03:00
icon.svg Add README.md 2026-02-11 21:24:30 +03:00
lang_grammar.md Create basic parser (#3) 2026-02-24 10:32:44 +03:00
LICENSE.md Rename LICENSE to LICENSE.md 2026-02-12 16:07:25 +03:00
main.cpp Implement bindings (#12) 2026-04-02 16:16:20 +03:00
README.md Update README.md 2026-03-20 10:57:12 +03:00

KorkaVM icon

KorkaVM

A Virtual Machine where lexing and compilation happen entirely at compile-time.


What is this

KorkaVM is a project where I'm trying to create a tool that allows to embed logic without runtime overhead of parsing or loading external files. You write C-like code right inside C++, and the compiler transforms it into internal bytecode before your program even starts.

Status

Component Stage Execution context
Lexer Done constexpr
Bytecode builder Done constexpr
Parser Done constexpr
Compiler Partially done constexpr
VM runner Partially done runtime

What's done:

constexpr char code[] = R"(
int main() {
  int a = 2;
  if (a) {
    return a;
  } else {
    return 5 + a;
  }
}

int foo(int a, int b) {
  return a + b;
}
)";

constexpr auto compile_result = korka::compile<code>();

// Extracting function types from code
// It returns a pointer, bc you can't return a type ._.
auto main_func = compile_result.function<"main">();
static_assert(std::is_same_v<decltype(main_func), long (*)()>);

auto foo_func = compile_result.function<"foo">();
static_assert(std::is_same_v<decltype(foo_func), long (*)(long, long)>);

Example context


auto foo(int a) -> int {
  return a * 2 + 5;
}

constexpr auto bindings = korka::make_bindings(
  "foo", &foo
);

constexpr auto my_script = korka::compile(bindings, R"(
    int calculate(int x) {
        if (x <= 0) return 0;

        return foo(x) / 3;
    }
)");

// Simple usage
int main() {
  korka::runtime vm;
  int result = vm.execute(my_script)
}

// Not so simple usage
int main() {
  korka::runtime vm;
  
  // Byte code gets inserted right into the native instruction flow
  // and executed by vm right there
  korka::run_embed<my_script>(vm);
}