From f64f68a4e0bfede260916e3728a01b85dedb99a3 Mon Sep 17 00:00:00 2001 From: DrMaxNix Date: Fri, 16 Sep 2022 18:19:23 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20start=20working=20on=20runtime?= =?UTF-8?q?=20aka.=20runner=20aka.=20interpreter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 9 ++++++- src/runner.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/runner.js diff --git a/src/main.js b/src/main.js index ea0af12..6142675 100644 --- a/src/main.js +++ b/src/main.js @@ -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(); } } diff --git a/src/runner.js b/src/runner.js new file mode 100644 index 0000000..dbc0dab --- /dev/null +++ b/src/runner.js @@ -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); + } +}