BSL is a statically-typed bytecode interpreted scripting language I am currently working on. It features a familiar C-like syntax.
Hello world example in BSL:
int main() {
print("Hello world!");
return 0;
}
Unlike C/C++, Bsl doesn't have pointers. Memory is managed automatically by the VM. It uses a mark-sweep garbage collection algorithm to manage memory.
Memory allocation is very similar to C-sharp. whenever the user allocates an object using the 'new' operator it gets allocated in a managed heap.
struct Entity {
int id = 0;
}
int main() {
Entity e = new Entity();
e.id = 1024;
print(e.id);
return 0;
}
Currently I am experimenting with letting the user manually call whenever the garbage- collector get triggered to prevent unpredictable hitches in performance.
I intentionally try and keep the syntax of BSL very, very simple. only featuring the minimal syntax in order to script games. Below you can see a little demo of the syntax features.
int main() {
int x = 10;
float y = 15.8;
print(x);
print(y);
if x == 10 then print("X is 10!");
for x {
print("wow!");
}
return 0;
}
The implementation of this scripting language is fully done in C++17. For this i wrote my own syntax parser, type checker, bytecode generator and bytecode interpreter.
These are the 'phases' of the compiler that source code passes through:
-> Parser, Generates an abstract syntax tree from tokens provided by the lexer.
-> Polymorphism, we apply inhertitance to structs that have been inherited from other structs.
-> Type checking, we check wether or not values are assigned to the correct variables.
-> Code generation, we generate bytecode instructions from the abstract syntax tree.
-> Run, we run the generated bytecode instructions in a virtual machine. The virtual machine is a stack based vm (meaning it does not use virtual registers)