Key features
ArkScript is
- small (less than 10'000 lines of idiomatic C++17)
- 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 10 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: 3.3.0
Timestamp: 1656877870
SHA256: 75614d8475c826d88f4a9f11aeaf5f9d3a296fbf544c2b4eca2d0834f1fec
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: 16)
0 LOAD_CONST (PageAddr) 1
3 LET foo
6 LOAD_CONST (Number) 3.000000
9 BUILTIN print
12 CALL (1)
15 HALT
Code segment 1 (length: 11)
0 MUT a
3 MUT b
6 BUILTIN nil
9 RET
10 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 & donators
- 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 discussions if your problem / suggestion doesn't fit or if you need help with the language! We also have a Discord server.
Head to the discussions if your problem / suggestion doesn't fit or if you need help with the language! We also have a Discord server.