SIGTERM simulation by hitting SHIFT-CTRL-T-R

This commit is contained in:
minjaesong
2021-04-23 21:57:02 +09:00
parent 1626c5f5e2
commit dbfda580a7
6 changed files with 42 additions and 31 deletions

4
assets/disk0/infinite.js Normal file
View File

@@ -0,0 +1,4 @@
while (true) {
print(((Math.random() * 2)|0) ? '\\' : '/');
sys.spin();
}

View File

@@ -1 +1 @@
throw new InterruptedException("lol");
throw new InterruptedException();

View File

@@ -163,7 +163,7 @@ let injectIntChk = (s, n) => {
let k = s
.replace(/while *\([^\n]+\) *{/, "$& "+n+"();")
.replace(/for *\([^\n]+\) *{/, "$& "+n+"();");
serial.println(k);
//serial.println(k);
return k;
}
@@ -178,22 +178,7 @@ var execApp = (cmdsrc, args) => {
`var _appStub=function(exec_args){${injectIntChk(cmdsrc, intchkFunName)}\n};` +
`_appStub`); // making 'exec_args' a app-level global
var status = 0;
try {
status = execAppPrg(args);
return status;
}
catch (e) {
serial.printerr(`app execution interrupted -- ${e}\n${e.stack || "(stack trace unavailable)"}`);
//serial.printerr(Object.entries(e));
if (e instanceof InterruptedException)
return SIGTERM;
else if (e instanceof IllegalAccessException || `${e}`.startsWith("net.torvald.tsvm.ErrorIllegalAccess"))
return SIGSEGV;
else
return (undefined == status) ? 0 : status;
}
return execAppPrg(args);
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -447,7 +447,8 @@ if (goInteractive) {
var cmdbuf = "";
while (true) {
var key = con.getch();
let key = con.getch();
let gotError = false;
// printable chars
if (key >= 32 && key <= 126) {
@@ -466,22 +467,27 @@ if (goInteractive) {
try {
errorlevel = 0; // reset the number
errorlevel = shell.execute(cmdbuf);
let rawE = errorlevel;
if (errorlevel instanceof SIG)
errorlevel = errorlevel.name;
else if (errorlevel == undefined || (typeof errorlevel.trim == "function" && errorlevel.trim().length == 0) || isNaN(errorlevel))
errorlevel = 0;
serial.printerr(`errorlevel: ${errorlevel} (raw: ${rawE})`);
}
catch (e) {
printerrln("\n"+(e.stack || e));
//if (errorlevel === 0 || isNaN(errorlevel)) {
// errorlevel = 1; // generic failure
//}
gotError = true;
serial.printerr(`[command.js] program quit with ${e}:\n${e.stack || '(stack trace unavailable)'}`);
if (`${e}`.startsWith("InterruptedException"))
errorlevel = SIGTERM.name;
else if (e instanceof IllegalAccessException || `${e}`.startsWith("net.torvald.tsvm.ErrorIllegalAccess"))
errorlevel = SIGSEGV.name;
// exception catched means something went wrong, so if errorlevel is found to be zero, force set to 1.
else
errorlevel = 1;
}
finally {
// sometimes no-error program may return nothing as the errorlevel; force set to 0 then.
if (!gotError && (errorlevel == undefined || (typeof errorlevel.trim == "function" && errorlevel.trim().length == 0) || isNaN(errorlevel)))
errorlevel = 0;
serial.printerr(`errorlevel: ${errorlevel}`);
if (cmdbuf.trim().length > 0)
cmdHistory.push(cmdbuf);

View File

@@ -70,6 +70,8 @@ class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
}
}
fun currentTimeInMills(): Long {
vm.poke(-69, -1)
var r = 0L

View File

@@ -252,6 +252,20 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
RTClatched = false
rtc = vm.worldInterface.currentTimeInMills()
}
// SIGTERM key combination: Ctrl+Shift+T+R
vm.stopDown = Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.T) &&
Gdx.input.isKeyPressed(Input.Keys.R)
if (vm.stopDown) println("[VM-${vm.id}] SIGTERM requested")
// RESET key combination: Ctrl+Shift+R+S
vm.resetDown = Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.R) &&
Gdx.input.isKeyPressed(Input.Keys.S)
if (vm.resetDown) println("[VM-${vm.id}] RESET requested")
}
override fun touchUp(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {