Key features
ArkScript is
- small (less than 10'000 lines of idiomatic C++20)
- a scripting language
- portable, compile once, run your bytecode anywhere
- functional, every argument is passed by copy
- homoiconic, you can manipulate code with macros
- extensible, through C++ plugins
More features
async
/await
on any function- no hidden references
- tail call and unused variable optimization
- a REPL with autocompletion and coloration
- a standard library in ArkScript and C++
- only need to learn 9 keywords
- docker images: stable, nightly
Fibonacci suite
(let fibo (fun (n)
(if (< n 2)
n
(+ (fibo (- n 1)) (fibo (- n 2))))))
(print (fibo 28)) # display 317811
Error messages to help you
CompilationError: Unbound variable error "fib" (did you mean "fibo"?)
In file fibonacci.ark
On line 7:12, got `(Symbol) fib'
4 | n
5 | (+ (fibo (- n 1)) (fibo (- n 2))))))
6 | (while continue {
7 | (print (fib 28))
| ^^^
8 | (if (< (/ (random) 32768) 0.1)
9 | (set continue false))
Bytecode explorer
Version: 4.0.0
Timestamp: 1716661603
SHA256: dac188c0b6e985817da6b61f2df6f95603b3b8fbdb7f4bdd6862534f1a3e52
Symbols table (length: 3)
0) foo
1) a
2) b
Constants table (length: 2)
0) (PageAddr) 1
1) (Number) 3.000000
Code segment 0 (length: 8)
0 00 02 00 00 LOAD_CONST (PageAddr) 1
1 00 05 00 00 LET foo
2 00 02 00 01 LOAD_CONST (Number) 3.000000
3 00 01 00 00 LOAD_SYMBOL foo
4 00 0a 00 01 CALL (1)
5 00 0c 00 09 BUILTIN print
6 00 0a 00 01 CALL (1)
7 00 09 00 00 HALT
Code segment 1 (length: 5)
0 00 0d 00 01 MUT a
1 00 0d 00 02 MUT b
2 00 0c 00 02 BUILTIN nil
3 00 08 00 00 RET
4 00 09 00 00 HALT
Straightforward embedding
#include <Ark/Ark.hpp>
int main()
{
// A state can be shared by multiple VM ; they can't overwrite it
Ark::State state;
// This will compile the code, but you can also give a file with state.doFile()
state.doString("(let foo (fun (x y) (+ x y 2)))");
// You can register C++ function (only before calling vm.run())
state.loadFunction("cpp_foo", [](std::vector<Ark::Value>& args, Ark::VM* vm) {
return Ark::Value(static_cast<int>(args.size()));
});
Ark::VM vm(state);
vm.run();
auto value = vm.call("foo", 5, 6.0);
// displays 13
std::cout << value << "\n";
return 0;
}
Sponsors & donors
- TheCountVEVO
- llexto
- COUR Eloïse
- AKPINAR Dylan
- Ryan C. Gordon through the 2022 Microgrant
Found a bug, need help with the language?
We have a bug tracker where you can report bugs and feature requests.
Head to the forum if your problem / suggestion doesn't fit or if you need help with the language!