From 64257464b4f0f5b084c3be466dbb1316c321c9ef Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 6 Dec 2020 11:40:46 +0900 Subject: [PATCH] basic: ability to invoke with cmdline args --- assets/basic.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/assets/basic.js b/assets/basic.js index e86ef43..1b4781b 100644 --- a/assets/basic.js +++ b/assets/basic.js @@ -15,6 +15,13 @@ Test Programs: 20 GOTO 10 */ +if (exec_args[1] !== undefined && exec_args[1].startsWith("-?")) { + println("Usage: basic "); + println("When the optional basic program is set, the interpreter will run the program and then quit if successful, remain open if the program had an error."); + return 0; +} + + let INDEX_BASE = 0; let TRACEON = false; let DBGON = true; @@ -1971,10 +1978,8 @@ bF._interpretLine = function(lnum, cmd) { return execResult.troNextLine; } catch (e) { - serial.println(`ERROR on ${lnum} -- PARSE TREE:`); - serial.println(syntaxTree.toString()); - serial.println("ERROR CONTENTS:"); - println(e); + serial.printerr(`ERROR on ${lnum} -- PARSE TREE:\n${syntaxTree.toString()}\nERROR CONTENTS:\n${e}`); + throw e; } }; // end INTERPRETLINE bF._basicList = function(v, i, arr) { @@ -2079,6 +2084,12 @@ bF.save = function(args) { // SAVE function bF.load = function(args) { // LOAD function if (args[1] === undefined) throw lang.missingOperand; var fileOpened = fs.open(args[1], "R"); + if (!fileOpened) { + fileOpened = fs.open(args[1]+".BAS", "R"); + } + if (!fileOpened) { + fileOpened = fs.open(args[1]+".bas", "R"); + } if (!fileOpened) { throw lang.noSuchFile; return; @@ -2109,6 +2120,19 @@ bF.catalog = function(args) { // CATALOG function println(com.pullMessage(port)); }; Object.freeze(bF); + +if (exec_args[1] !== undefined) { + bF.load(["load", exec_args[1]]); + try { + bF.run(); + return 0; + } + catch (e) { + serial.printerr(e); + println(e); + } +} + while (!tbasexit) { var line = sys.read().trim();