mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 07:14:04 +09:00
basic: ability to invoke with cmdline args
This commit is contained in:
@@ -15,6 +15,13 @@ Test Programs:
|
|||||||
20 GOTO 10
|
20 GOTO 10
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
if (exec_args[1] !== undefined && exec_args[1].startsWith("-?")) {
|
||||||
|
println("Usage: basic <optional path to basic program>");
|
||||||
|
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 INDEX_BASE = 0;
|
||||||
let TRACEON = false;
|
let TRACEON = false;
|
||||||
let DBGON = true;
|
let DBGON = true;
|
||||||
@@ -1971,10 +1978,8 @@ bF._interpretLine = function(lnum, cmd) {
|
|||||||
return execResult.troNextLine;
|
return execResult.troNextLine;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
serial.println(`ERROR on ${lnum} -- PARSE TREE:`);
|
serial.printerr(`ERROR on ${lnum} -- PARSE TREE:\n${syntaxTree.toString()}\nERROR CONTENTS:\n${e}`);
|
||||||
serial.println(syntaxTree.toString());
|
throw e;
|
||||||
serial.println("ERROR CONTENTS:");
|
|
||||||
println(e);
|
|
||||||
}
|
}
|
||||||
}; // end INTERPRETLINE
|
}; // end INTERPRETLINE
|
||||||
bF._basicList = function(v, i, arr) {
|
bF._basicList = function(v, i, arr) {
|
||||||
@@ -2079,6 +2084,12 @@ bF.save = function(args) { // SAVE function
|
|||||||
bF.load = function(args) { // LOAD function
|
bF.load = function(args) { // LOAD function
|
||||||
if (args[1] === undefined) throw lang.missingOperand;
|
if (args[1] === undefined) throw lang.missingOperand;
|
||||||
var fileOpened = fs.open(args[1], "R");
|
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) {
|
if (!fileOpened) {
|
||||||
throw lang.noSuchFile;
|
throw lang.noSuchFile;
|
||||||
return;
|
return;
|
||||||
@@ -2109,6 +2120,19 @@ bF.catalog = function(args) { // CATALOG function
|
|||||||
println(com.pullMessage(port));
|
println(com.pullMessage(port));
|
||||||
};
|
};
|
||||||
Object.freeze(bF);
|
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) {
|
while (!tbasexit) {
|
||||||
var line = sys.read().trim();
|
var line = sys.read().trim();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user