From b1a477ea99969ca7c8a7c0500683f4c5d510f245 Mon Sep 17 00:00:00 2001 From: psf Date: Fri, 25 Mar 2022 23:30:18 -0700 Subject: [PATCH] ret with nothing on the return stack should exit --- frustration.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frustration.rs b/frustration.rs index 5c05b69..792ebda 100644 --- a/frustration.rs +++ b/frustration.rs @@ -1,6 +1,6 @@ use std::cmp; use std::io; -//use std::convert::TryFrom; +use std::process; use std::convert::TryInto; //const CORE_SIZE: usize = 65280 @@ -48,7 +48,7 @@ struct TableEntry { // NOTE: lazy_static or SyncLazy would allow nicer init const PRIMITIVES: [TableEntry; 8] = [ - TableEntry {f: ret , name: ShortName {bytes: ['r' as u8, 'e' as u8, 't' as u8], length: 1}}, + TableEntry {f: ret , name: ShortName {bytes: ['r' as u8, 'e' as u8, 't' as u8], length: 3}}, TableEntry {f: dot , name: ShortName {bytes: ['.' as u8, 32, 32], length: 1}}, TableEntry {f: store, name: ShortName {bytes: ['!' as u8, 32, 32], length: 1}}, TableEntry {f: load , name: ShortName {bytes: ['@' as u8, 32, 32], length: 1}}, @@ -148,6 +148,9 @@ fn inner(c: &mut Core) { } fn ret(c: &mut Core) { + if c.trs == 0 { + std::process::exit(0); + } c.ip = from_r(c); }