From c331af2cc4e6c724782a60f4007dc1f19b8c0dd1 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 1 Nov 2020 12:03:03 +0900 Subject: [PATCH] a way to run program with arguments --- assets/JS_INIT.js | 5 +++++ assets/tvdos/TVDOS.SYS | 8 ++++++- assets/tvdos/command.js | 14 +++++++++--- assets/zippytest.js | 25 ++++++++++------------ src/net/torvald/tsvm/Base64Delegate.kt | 2 +- src/net/torvald/tsvm/CompressorDelegate.kt | 3 ++- src/net/torvald/tsvm/VMGUI.kt | 15 +++++++++++-- src/net/torvald/tsvm/VMRunnerFactory.kt | 4 ++-- 8 files changed, 52 insertions(+), 24 deletions(-) diff --git a/assets/JS_INIT.js b/assets/JS_INIT.js index 2a617d1..101544c 100644 --- a/assets/JS_INIT.js +++ b/assets/JS_INIT.js @@ -84,6 +84,11 @@ if (!Array.prototype.filter){ return res; }; } +if (!String.prototype.padStart) { + String.prototype.padStart = function(l, c) { + return (this.length >= l) ? this : (c.repeat(l - this.length) + this); + }; +} // Production steps of ECMA-262, Edition 5, 15.4.4.19 // Reference: http://es5.github.io/#x15.4.4.19 if (!Array.prototype.map) { diff --git a/assets/tvdos/TVDOS.SYS b/assets/tvdos/TVDOS.SYS index 7a7893e..6d996b8 100644 --- a/assets/tvdos/TVDOS.SYS +++ b/assets/tvdos/TVDOS.SYS @@ -65,4 +65,10 @@ var GL = eval(filesystem.readAll("A")); // Boot script filesystem.open("A", "tvdos/command.js", "R"); -eval(filesystem.readAll("A")); +let cmdsrc = filesystem.readAll("A"); + +// app execution stub +let prg = eval("let _appStub=function(exec_args){"+cmdsrc+"};_appStub;"); // making 'exec_args' a app-level global +prg(undefined); +//let testtest = prg(42); +//println(testtest.test); diff --git a/assets/tvdos/command.js b/assets/tvdos/command.js index ffe6c70..fd6301a 100644 --- a/assets/tvdos/command.js +++ b/assets/tvdos/command.js @@ -1,4 +1,4 @@ -const PROMPT_TEXT = ">"; +let PROMPT_TEXT = ">"; let CURRENT_DRIVE = "A"; let shell_pwd = [""]; @@ -15,6 +15,11 @@ function greet() { } +let shell = {}; +shell.test = "command.js test string"; +if (exec_args !== undefined) return shell; + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// println("Starting TVDOS..."); @@ -47,9 +52,10 @@ while (true) { println(); try { println("You entered: " + cmdbuf); + } catch (e) { - println(e); + printerrln(e); } finally { if (cmdbuf.trim().length > 0) @@ -91,4 +97,6 @@ while (true) { } } } -} \ No newline at end of file +} + +return 0; \ No newline at end of file diff --git a/assets/zippytest.js b/assets/zippytest.js index 48418f7..9527c58 100644 --- a/assets/zippytest.js +++ b/assets/zippytest.js @@ -1,22 +1,19 @@ serial.println(typeof atob); const inputstr = -"//////////////////////////////////////////j//////////////"+ -"/////////////////j////////////////////////z8/P///j///+hoaGhof+hof////////Pz//////j//6Gh//////+hof////////Pz//////j//6"+ -"Gh//////+hoaGhof//8/Pz8/P///j///+hoaH///+hof//oaH///Pz//////j//////6Gh//+hof//oaH///Pz//////j///////+hof+hof//oaH///P"+ -"z//////j///////+hof+hof//oaH///Pz//////j//6GhoaGh//+hof//oaH///////////j///////////////////////////////j/////////////"+ -"////////////////////////////////////////" +'println("TERRAN Megatrends inc.");let p=0;let m=[[0,255,170,85,105,15,165,30,199,113,142,227,202,254,186,190],[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]];con.move(2,1),print("000 KB OK");try{for(;p<8<<20;){con.move(2,1);var x=""+(p+1>>10);print(x<10?"00"+x:x<100?"0"+x:x);for(var t=0;t