mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
basic:load function
This commit is contained in:
@@ -32,6 +32,7 @@ lang.badOperatorFormat = "Illegal operator format";
|
||||
lang.badFunctionCallFormat = "Illegal function call";
|
||||
lang.unmatchedBrackets = "Unmatched brackets";
|
||||
lang.missingOperand = "Missing operand";
|
||||
lang.noSuchFile = "No such file";
|
||||
lang.syntaxfehler = function(line, reason) {
|
||||
return "Syntax error" + ((line !== undefined) ? (" in "+line) : "") + ((reason !== undefined) ? (": "+reason) : "");
|
||||
};
|
||||
@@ -1447,6 +1448,23 @@ bF.save = function(args) { // SAVE function
|
||||
cmdbuf.forEach(function(v,i) { sb += i+" "+v+"\n"; });
|
||||
fs.write(sb);
|
||||
};
|
||||
bF.load = function(args) { // LOAD function
|
||||
if (args[1] === undefined) throw lang.missingOperand;
|
||||
let fileOpened = fs.open(args[1], "R");
|
||||
if (!fileOpened) {
|
||||
throw lang.noSuchFile;
|
||||
return;
|
||||
}
|
||||
let prg = fs.readAll();
|
||||
|
||||
cmdbuf = [];
|
||||
prg.split('\n').forEach(function(line) {
|
||||
let i = line.indexOf(" ");
|
||||
let lnum = line.slice(0, i);
|
||||
if (isNaN(lnum)) throw lang.illegalType();
|
||||
cmdbuf[lnum] = line.slice(i + 1, line.length);
|
||||
});
|
||||
};
|
||||
Object.freeze(bF);
|
||||
while (!tbasexit) {
|
||||
let line = sys.read().trim();
|
||||
|
||||
Reference in New Issue
Block a user