Hello, look at me making another script engine, again, for the 123870123th time. This time with object support! Finally! You'd think after so many attempts I'd have bothered finishing one with object support by now but no, I haven't.
Currently have the parser and sort-of-compiler done, writing the actual sort-of-virtual-machine bit now. I doubt this will be particularly efficient as I'm making "good" use of strings... clearly not the best solution... but I'm more interested in finishing it and learning and taking such considerations into account next time than getting it all perfect.
So, the syntax may not be to your tastes, but here is an example input script file:
Import comparison
Object Dog {
String colour;
String name;
Bool crazy;
Int age;
}
Function Bark(Dog d) Returns Nothing {
Int i = 2 * 4 - 15;
if(comparison.Between(5, 0, 10)) {
PrintLine("<" + d.name + ">: Woof!");
}
}
Function WhileTest(Int counter) Returns Nothing {
while(counter > 0) {
counter = counter - 1;
}
}
Function Main(List<String> Args) Returns Int {
Dog Rover;
Rover.colour = "Brown";
Rover.name = "Rover";
Rover.crazy = Rover.colour == "Brown";
Rover.age = 4;
Bark(Rover);
Return 0;
}
So, yeah...
I'll attach a .zip (I don't have winrar installed on my new laptop yet) which contains the following files:
Source Code:
Bytecode.h /.cpp
CompileParsed.h /.cpp
Engine.h /.cpp <-- kinda empty/redundant right now, ignore it
ParseException.h /.cpp
ParseSource.h /.cpp
ParseText.h /.cpp
RuntimeException.h /.cpp
ScriptObject.h /.cpp
Data Files:
asm.txt <-- contains a mock-up of the bytecode i wanted my compiler to generate, redundant as the compiler is finished
comparison.txt <-- used for testing the import feature, is imported by test.txt and contains a single comparison function (Between)
test.txt <-- the main test source file (contains the code shown above)
I don't know if anybody will find this interesting/impressive/lame but you know, I love making script engines and getting slowly better at them haha, plus the Work in Progress and Finished Product categories are kinda slow ;)!