mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
SIGTERM simulation by hitting SHIFT-CTRL-T-R
This commit is contained in:
4
assets/disk0/infinite.js
Normal file
4
assets/disk0/infinite.js
Normal file
@@ -0,0 +1,4 @@
|
||||
while (true) {
|
||||
print(((Math.random() * 2)|0) ? '\\' : '/');
|
||||
sys.spin();
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
throw new InterruptedException("lol");
|
||||
throw new InterruptedException();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun currentTimeInMills(): Long {
|
||||
vm.poke(-69, -1)
|
||||
var r = 0L
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user