🎉 start working on runtime aka. runner aka. interpreter
This commit is contained in:
parent
f7a9520f3f
commit
f64f68a4e0
@ -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
67
src/runner.js
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user