From 116a5b2ed9826ffa0a1a2a93220145453d1ab8cd Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Wed, 2 Jul 2025 13:44:26 -0400 Subject: [PATCH] prevent rust panic on kill signal --- may_2025_thoughts.md | 32 ++++++++++++++++---------------- src/lib.rs | 7 ++++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/may_2025_thoughts.md b/may_2025_thoughts.md index 6e6c2b1..4a37c12 100644 --- a/may_2025_thoughts.md +++ b/may_2025_thoughts.md @@ -1122,28 +1122,28 @@ That leaves the following list: * [ ] Model after the p5 keyboard input API * [ ] ludus keyboard API: `key_down?(), key_pressed?(), key_released?()`, key code values (use a dict) * [a] Escape characters in strings: \n, \t, and \{, \}. -* [ ] `doc!` needs to print the patterns of a function. -* [ ] I need to return to the question of whether/how strings are ordered; do we use `at`, or do we want `char_at`? etc. +* [a] `doc!` needs to print the patterns of a function. +* [a] I need to return to the question of whether/how strings are ordered; do we use `at`, or do we want `char_at`? etc. - MNL and I decided: yes, stings are indexable - [ ] implement `slice` and `at` and others for strings * [x] Automate this build process * [ ] Start testing against the cases in `ludus-test` * [ ] Systematically debug prelude * [ ] Bring it in function by function, testing each in turn -* [ ] Animation hooked into the web frontend (Spacewar!) +* [x] Animation hooked into the web frontend (Spacewar!) * [ ] Text input (Spacewar!) * [ ] ~Makey makey for alternate input?~ -* [ ] Saving and loading data into Ludus (perceptrons, dissociated press) +* [x] Saving and loading data into Ludus (perceptrons, dissociated press) * [ ] Finding corpuses for Dissociated Press -* [ ] improve validator - - [ ] Tuples may not be longer than n members - - [ ] Loops may not have splatterns +* [a] improve validator + - [a] Tuples may not be longer than n members + - [a] Loops may not have splatterns - [ ] Identify others - - [ ] Splats in functions must be the same arity, and greater than any explicit arity -* [ ] actually good error messages - - [ ] parsing + - [a] Splats in functions must be the same arity, and greater than any explicit arity +* [a] actually good error messages + - [a] parsing - [ ] my memory is that validator messages are already good? - - [ ] panics, esp. no match panics + - [a] panics, esp. no match panics * [ ] panics should be able to refernce the line number where they fail * [ ] that suggests that we need a mapping from bytecodes to AST nodes * The way I had been planning on doing this is having a vec that moves in lockstep with bytecode that's just references to ast nodes, which are `'static`, so that shouldn't be too bad. But this is per-chunk, which means we need a reference to that vec in the VM. My sense is that what we want is actually a separate data structure that holds the AST nodes--we'll only need them in the sad path, which can be slow. @@ -1201,10 +1201,10 @@ After that: * [x] response: js->rust->ludus - [ ] `keyboard` * [ ] still working on how to represent this -* [ ] hook this up to `web.ludus.dev` -* [ ] do some integration testing +* [x] hook this up to `web.ludus.dev` +* [x] do some integration testing - [x] do synchronous programs still work? - - [ ] animations? - - [ ] read inputs? - - [ ] load url text? + - [x] animations? + - [x] read inputs? + - [x] load url text? diff --git a/src/lib.rs b/src/lib.rs index 64fe9f2..7ef08c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,11 +171,12 @@ pub async fn ludus(src: String) -> String { let mut world = World::new(vm_chunk, prelude.clone(), DEBUG_SCRIPT_RUN); world.run().await; - let result = world.result.clone().unwrap(); + let result = world.result.clone(); let output = match result { - Ok(val) => val.show(), - Err(panic) => format!("Ludus panicked! {panic}") + Some(Ok(val)) => val.show(), + Some(Err(panic)) => format!("Ludus panicked! {panic}"), + None => "Ludus run terminated by user".to_string() }; if DEBUG_SCRIPT_RUN { // vm.print_stack();