0
0

🎉 start working on runtime aka. runner aka. interpreter

This commit is contained in:
DrMaxNix 2022-09-16 18:19:23 +02:00
parent f7a9520f3f
commit f64f68a4e0
2 changed files with 75 additions and 1 deletions

View File

@ -109,6 +109,13 @@ class Juicescript {
Run previously parsed program
*/
run(){
/**/this.io.stderr.debug(this.program_tree);
// RUN //
// get runner
let runner = new Juicescript_runner(this.program_tree, {
io: this.io
});
// run the program
runner.run();
}
}

67
src/runner.js Normal file
View File

@ -0,0 +1,67 @@
class Juicescript_runner {
/*
CONSTRUCTOR: Return new juicescript runner for PROGRAM-TREE with OPTIONS
*/
constructor(program_tree, options){
// STORE ARGUMENTS //
// program tree
this.tree = program_tree;
// io adapter
this.io = options.io;
}
/*
MAIN: Do running
*/
run(){
/**/this.command = this.tree.root.command[0];
/**/this.debug(this.tree);
}
/*
HELPER: Automagically keep track of problems and add additional info to stderr
*/
debug(text, additional){
// add defaults
additional ??= {};
additional.line ??= this.command.line;
// forward
this.io.stderr.debug(text, additional);
}
info(text, additional){
// add defaults
additional ??= {};
additional.line ??= this.command.line;
// forward
this.io.stderr.info(text, additional);
}
warning(text, additional){
// KEEP TRACK OF PROBLEM //
this.warning_count++;
// PRINT MESSAGE //
// add defaults
additional ??= {};
additional.line ??= this.command.line;
// forward
this.io.stderr.warning(text, additional);
}
error(text, additional){
// KEEP TRACK OF PROBLEM //
this.error_count++;
// PRINT MESSAGE //
// add defaults
additional ??= {};
additional.line ??= this.command.line;
// forward
this.io.stderr.error(text, additional);
}
}