mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
more graal stuffs
This commit is contained in:
@@ -313,6 +313,9 @@ load = undefined;
|
||||
loadWithNewGlobal = undefined;
|
||||
exit = undefined;
|
||||
quit = undefined;
|
||||
printErr = undefined;
|
||||
readbuffer = undefined;
|
||||
readline = undefined;
|
||||
/*var eval = function(s) { // this impl is flawed; it does not return any, and cannot alter Global which may not you actually want
|
||||
return Function('"use strict";return(function(){'+s+'}())')();
|
||||
}*/
|
||||
@@ -422,3 +425,7 @@ system.halt = function() {
|
||||
};
|
||||
Object.freeze(system);
|
||||
// some utilities functions
|
||||
|
||||
if (Graal !== undefined && !Graal.isGraalRuntime()) {
|
||||
printerrln("GraalVM compiler is not running, expect low performance");
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ Object.freeze(fs);
|
||||
let getUsedMemSize = function() {
|
||||
var varsMemSize = 0;
|
||||
|
||||
Object.entries(bStatus.vars).forEach(function(pair,i) {
|
||||
Object.entries(bStatus.vars).forEach((pair, i) => {
|
||||
var object = pair[1];
|
||||
|
||||
if (Array.isArray(object)) {
|
||||
@@ -465,7 +465,7 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
||||
if (rsvArg1 === undefined) throw lang.refError(lnum, rsvArg1);
|
||||
if (isNaN(rsvArg1)) throw lang.illegalType(lnum, rsvArg1);
|
||||
var a = []; var stepcnt = 0;
|
||||
rsvArg0.forEach(function(v,i) {
|
||||
rsvArg0.forEach((v,i) => {
|
||||
if (stepcnt == 0) a.push(v);
|
||||
stepcnt = (stepcnt + 1) % rsvArg1;
|
||||
});
|
||||
@@ -548,7 +548,7 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
||||
"AND" : function(lnum, args) {
|
||||
if (args.length != 2) throw lang.syntaxfehler(lnum, args.length+lang.aG);
|
||||
var rsvArg = args.map(function(it) { return resolve(it); });
|
||||
rsvArg.forEach(function(v) {
|
||||
rsvArg.forEach((v) => {
|
||||
if (v === undefined) throw lang.refError(lnum, v);
|
||||
if (typeof v !== "boolean") throw lang.illegalType(lnum, v);
|
||||
});
|
||||
@@ -561,7 +561,7 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
||||
"OR" : function(lnum, args) {
|
||||
if (args.length != 2) throw lang.syntaxfehler(lnum, args.length+lang.aG);
|
||||
var rsvArg = args.map(function(it) { return resolve(it); });
|
||||
rsvArg.forEach(function(v) {
|
||||
rsvArg.forEach((v) => {
|
||||
if (v === undefined) throw lang.refError(lnum, v.value);
|
||||
if (typeof v !== "boolean") throw lang.illegalType(lnum, v);
|
||||
});
|
||||
@@ -1490,7 +1490,7 @@ bF._parseTokens = function(lnum, tokens, states, recDepth) {
|
||||
|
||||
leaves.push(bF._parseTokens(lnum, subtkn, substa, recDepth + 1));
|
||||
}
|
||||
separators.slice(1, separators.length - 1).forEach(function(v) { if (v !== undefined) seps.push(tokens[v]); });
|
||||
separators.slice(1, separators.length - 1).forEach((v) => { if (v !== undefined) seps.push(tokens[v]) });
|
||||
}
|
||||
else throw lang.syntaxfehler(lnum, lang.badFunctionCallFormat);
|
||||
treeHead.astLeaves = leaves;//.filter(function(__v) { return __v !== undefined; });
|
||||
@@ -1712,9 +1712,9 @@ bF.renum = function(args) { // RENUM function
|
||||
|
||||
// recalculate memory footprint
|
||||
cmdbufMemFootPrint = 0;
|
||||
cmdbuf.forEach(function(v, i, arr) {
|
||||
cmdbufMemFootPrint += ("" + i).length + 1 + v.length;
|
||||
});
|
||||
cmdbuf.forEach((v, i, arr) =>
|
||||
cmdbufMemFootPrint += ("" + i).length + 1 + v.length
|
||||
);
|
||||
};
|
||||
bF.fre = function(args) {
|
||||
println(vmemsize - getUsedMemSize());
|
||||
@@ -1742,7 +1742,7 @@ bF.save = function(args) { // SAVE function
|
||||
if (args[1] === undefined) throw lang.missingOperand;
|
||||
fs.open(args[1], "W");
|
||||
var sb = "";
|
||||
cmdbuf.forEach(function(v,i) { sb += i+" "+v+"\n"; });
|
||||
cmdbuf.forEach((v, i) => sb += i+" "+v+"\n");
|
||||
fs.write(sb);
|
||||
};
|
||||
bF.load = function(args) { // LOAD function
|
||||
@@ -1759,7 +1759,7 @@ bF.load = function(args) { // LOAD function
|
||||
bStatus.vars = initBvars();
|
||||
|
||||
// read the source
|
||||
prg.split('\n').forEach(function(line) {
|
||||
prg.split('\n').forEach((line) => {
|
||||
var i = line.indexOf(" ");
|
||||
var lnum = line.slice(0, i);
|
||||
if (isNaN(lnum)) throw lang.illegalType();
|
||||
|
||||
@@ -26,7 +26,7 @@ Object.freeze(_TVDOS);
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var filesystem = {};
|
||||
filesystem._toPorts = function(driveLetter) {
|
||||
filesystem._toPorts = (driveLetter) => {
|
||||
if (driveLetter.toUpperCase === undefined) {
|
||||
throw Error("'"+driveLetter+"' (type: "+typeof driveLetter+") is not a valid drive letter");
|
||||
}
|
||||
@@ -36,10 +36,10 @@ filesystem._toPorts = function(driveLetter) {
|
||||
}
|
||||
return port
|
||||
};
|
||||
filesystem._close = function(portNo) {
|
||||
filesystem._close = (portNo) => {
|
||||
com.sendMessage(portNo, "CLOSE");
|
||||
};
|
||||
filesystem._flush = function(portNo) {
|
||||
filesystem._flush = (portNo) => {
|
||||
com.sendMessage(portNo, "FLUSH");
|
||||
};
|
||||
// @return true if operation committed successfully, false if:
|
||||
@@ -47,7 +47,7 @@ filesystem._flush = function(portNo) {
|
||||
// throws if:
|
||||
// - java.lang.NullPointerException if path is null
|
||||
// - Error if operation mode is not "R", "W" nor "A"
|
||||
filesystem.open = function(driveLetter, path, operationMode) {
|
||||
filesystem.open = (driveLetter, path, operationMode) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
|
||||
filesystem._flush(port[0]); filesystem._close(port[0]);
|
||||
@@ -62,7 +62,7 @@ filesystem.open = function(driveLetter, path, operationMode) {
|
||||
return (response == 0);
|
||||
};
|
||||
// @return the entire contents of the file in String
|
||||
filesystem.readAll = function(driveLetter) {
|
||||
filesystem.readAll = (driveLetter) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
com.sendMessage(port[0], "READ");
|
||||
var response = com.getStatusCode(port[0]);
|
||||
@@ -74,7 +74,7 @@ filesystem.readAll = function(driveLetter) {
|
||||
}
|
||||
return com.pullMessage(port[0]);
|
||||
};
|
||||
filesystem.write = function(driveLetter, string) {
|
||||
filesystem.write = (driveLetter, string) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
com.sendMessage(port[0], "WRITE"+string.length);
|
||||
var response = com.getStatusCode(port[0]);
|
||||
@@ -87,13 +87,13 @@ filesystem.write = function(driveLetter, string) {
|
||||
com.sendMessage(port[0], string);
|
||||
filesystem._flush(port[0]); filesystem._close(port[0]);
|
||||
};
|
||||
filesystem.isDirectory = function(driveLetter) {
|
||||
filesystem.isDirectory = (driveLetter) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
com.sendMessage(port[0], "LISTFILES");
|
||||
var response = com.getStatusCode(port[0]);
|
||||
return (response === 0);
|
||||
};
|
||||
filesystem.mkDir = function(driveLetter) {
|
||||
filesystem.mkDir = (driveLetter) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
com.sendMessage(port[0], "MKDIR");
|
||||
var response = com.getStatusCode(port[0]);
|
||||
@@ -104,13 +104,13 @@ filesystem.mkDir = function(driveLetter) {
|
||||
}
|
||||
return (response === 0); // possible status codes: 0 (success), 1 (fail)
|
||||
};
|
||||
filesystem.touch = function(driveLetter) {
|
||||
filesystem.touch = (driveLetter) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
com.sendMessage(port[0], "TOUCH");
|
||||
var response = com.getStatusCode(port[0]);
|
||||
return (response === 0);
|
||||
};
|
||||
filesystem.mkFile = function(driveLetter) {
|
||||
filesystem.mkFile = (driveLetter) => {
|
||||
var port = filesystem._toPorts(driveLetter);
|
||||
com.sendMessage(port[0], "MKFILE");
|
||||
var response = com.getStatusCode(port[0]);
|
||||
@@ -127,7 +127,7 @@ var GL = eval(filesystem.readAll("A"));
|
||||
// @param cmdsrc JS source code
|
||||
// @param args arguments for the program, must be Array, and args[0] is always the name of the program, e.g.
|
||||
// for command line 'echo foo bar', args[0] must be 'echo'
|
||||
var execApp = function(cmdsrc, args) {
|
||||
var execApp = (cmdsrc, args) => {
|
||||
var execAppPrg = eval("var _appStub=function(exec_args){"+cmdsrc+"};_appStub;"); // making 'exec_args' a app-level global
|
||||
return execAppPrg(args);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ object VMRunnerFactory {
|
||||
init {
|
||||
// see https://github.com/graalvm/graaljs/blob/master/docs/user/ScriptEngine.md
|
||||
bind.put("polyglot.js.allowHostAccess", true)
|
||||
bind.put("js.console", false)
|
||||
|
||||
bind.put("sys", VMJSR223Delegate(vm)) // TODO use delegator class to access peripheral (do not expose VM itself)
|
||||
bind.put("graphics", GraphicsJSR223Delegate(vm))
|
||||
|
||||
Reference in New Issue
Block a user