wip: jet_stew

This commit is contained in:
Matthew LeVan 2023-12-07 22:24:56 -05:00
parent a44846a3fe
commit fd413bafe7
4 changed files with 185 additions and 76 deletions

View File

@ -12,9 +12,9 @@ edition = "2018"
# Please keep these alphabetized # Please keep these alphabetized
[dependencies] [dependencies]
ares_macros = { path = "../ares_macros" } ares_macros = { path = "../ares_macros" }
# assert_no_alloc = "1.1.2" assert_no_alloc = "1.1.2"
# use this when debugging requires allocation (e.g. eprintln) # use this when debugging requires allocation (e.g. eprintln)
assert_no_alloc = {version="1.1.2", features=["warn_debug"]} # assert_no_alloc = {version="1.1.2", features=["warn_debug"]}
bitvec = "1.0.0" bitvec = "1.0.0"
criterion = "0.4" criterion = "0.4"
either = "1.9.0" either = "1.9.0"
@ -40,7 +40,7 @@ name = "ares"
path = "src/main.rs" path = "src/main.rs"
[profile.dev] [profile.dev]
opt-level = 0 opt-level = 3
[profile.dev.package."*"] [profile.dev.package."*"]
opt-level = 3 opt-level = 3

View File

@ -440,6 +440,21 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[
jet_stag, jet_stag,
), ),
// //
// (
// &[
// K_139,
// Left(b"one"),
// Left(b"two"),
// Left(b"tri"),
// Left(b"qua"),
// Left(b"stir"),
// Left(b"fun"),
// ],
// 1,
// jet_stir,
// ),
//
//
( (
&[ &[
K_139, K_139,
@ -447,13 +462,12 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[
Left(b"two"), Left(b"two"),
Left(b"tri"), Left(b"tri"),
Left(b"qua"), Left(b"qua"),
Left(b"stir"), Left(b"stew"),
Left(b"fun"), Left(b"fun"),
], ],
1, 1,
jet_stir, jet_stew,
), ),
//
( (
&[ &[
K_139, K_139,

View File

@ -1,11 +1,14 @@
use std::result;
/** Parsing jets /** Parsing jets
*/ */
use crate::interpreter::Context; use crate::interpreter::{Context, Error};
use crate::jets::util::{kick, slam, slot}; use crate::jets::util::{kick, slam, slot};
use crate::jets::Result; use crate::jets::Result;
use crate::mem::with_frame;
use crate::noun::{Noun, D, T}; use crate::noun::{Noun, D, T};
use super::JetErr;
crate::gdb!(); crate::gdb!();
// //
@ -233,79 +236,171 @@ struct StirPair {
pub res: Noun, pub res: Noun,
} }
pub fn jet_stir(context: &mut Context, subject: Noun) -> Result { // pub fn jet_stir(context: &mut Context, subject: Noun) -> Result {
/** XX // XX
* jet should use with_frame // jet should use with_frame
* with_frame should require output to be Preserve and should unconditionally preserve output // with_frame should require output to be Preserve and should unconditionally preserve output
* JetErr, interpreter::Error, and Result need Preserve instances // JetErr, interpreter::Error, and Result need Preserve instances
* then jet simply calls with_frame and no need to preserve in jet // then jet simply calls with_frame and no need to preserve in jet
*/ // unsafe {
unsafe { // context.stack.with_frame(0, || {
with_frame(0, || { // let mut tub = slot(subject, 6)?;
let mut tub = slot(subject, 6)?; // let van = slot(subject, 7)?;
let van = slot(subject, 7)?; // let rud = slot(van, 12)?;
let rud = slot(van, 12)?; // let raq = slot(van, 26)?;
let raq = slot(van, 26)?; // let fel = slot(van, 27)?;
let fel = slot(van, 27)?;
// initial accumulator (deconstructed) // // initial accumulator (deconstructed)
let mut p_wag: Noun; // let mut p_wag: Noun;
let mut puq_wag: Noun; // let mut puq_wag: Noun;
let quq_wag: Noun; // let quq_wag: Noun;
// push incremental, succesful [fel] parse results onto stack // // push incremental, succesful [fel] parse results onto stack
{ // {
let mut vex = slam(context, fel, tub)?.as_cell()?; // let mut vex = slam(context, fel, tub)?.as_cell()?;
let mut p_vex = vex.head(); // let mut p_vex = vex.head();
let mut q_vex = vex.tail(); // let mut q_vex = vex.tail();
eprintln!("stir: got vex\r"); // eprintln!("stir: got vex\r");
let i = 0; // let i = 0;
while unsafe { !q_vex.raw_equals(D(0)) } { // while unsafe { !q_vex.raw_equals(D(0)) } {
eprintln!("stir: starting vex loop {}\r", i); // eprintln!("stir: starting vex loop {}\r", i);
let puq_vex = q_vex.as_cell()?.head(); // let puq_vex = q_vex.as_cell()?.head();
let quq_vex = q_vex.as_cell()?.tail(); // let quq_vex = q_vex.as_cell()?.tail();
unsafe { // unsafe {
*(context.stack.push::<StirPair>()) = StirPair { // *(context.stack.push::<StirPair>()) = StirPair {
har: p_vex, // har: p_vex,
res: puq_vex, // res: puq_vex,
}; // };
}; // };
tub = quq_vex; // tub = quq_vex;
let slam_vex = slam(context, fel, tub); // let slam_vex = slam(context, fel, tub);
if slam_vex.is_err() { // if slam_vex.is_err() {
eprintln!("stir: slam vex failed\r"); // eprintln!("stir: slam vex failed\r");
// }
// vex = slam_vex?.as_cell()?;
// p_vex = vex.head();
// q_vex = vex.tail();
// }
// eprintln!("stir: vex loop done\r");
// p_wag = p_vex;
// puq_wag = rud;
// quq_wag = tub;
// }
// // unwind the stack, folding parse results into [wag] by way of [raq]
// eprintln!("stir: unwinding stack\r");
// while !context.stack.stack_is_empty() {
// let par_u = unsafe { *(context.stack.top::<StirPair>()) };
// p_wag = util::last(par_u.har, p_wag)?;
// let sam = T(&mut context.stack, &[par_u.res, puq_wag]);
// puq_wag = slam(context, raq, sam)?;
// unsafe {
// context.stack.pop::<StirPair>();
// };
// }
// let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]);
// Ok(res)
// })
// }
// }
fn stew_wor(ort: Noun, wan: Noun) -> result::Result<bool, JetErr> {
if !ort.as_atom()?.is_direct() {
return Err(JetErr::Fail(Error::Deterministic(D(0))));
}
else {
if !wan.is_cell() {
if !wan.as_atom()?.is_direct() {
return Err(JetErr::Fail(Error::Deterministic(D(0))));
}
else {
let ort_dat = ort.as_direct()?.data();
let wan_dat = wan.as_direct()?.data();
return Ok(ort_dat < wan_dat);
}
}
else {
let h_wan = wan.as_cell()?.head();
if !h_wan.as_atom()?.is_direct() {
return Err(JetErr::Fail(Error::Deterministic(D(0))));
}
else {
let ort_dat = ort.as_direct()?.data();
let h_wan_dat = h_wan.as_direct()?.data();
return Ok(ort_dat < h_wan_dat);
}
}
}
}
pub fn jet_stew(context: &mut Context, subject: Noun) -> Result {
let tub = slot(subject, 6)?;
let con = slot(subject, 7)?;
let mut hel = slot(con, 2)?;
let p_tub = tub.as_cell()?.head();
let q_tub = tub.as_cell()?.tail();
match q_tub.as_cell() {
Ok(a) => {
let iq_tub = a.head();
if !iq_tub.as_atom()?.is_direct() {
return util::fail(context, p_tub);
}
else {
loop {
if !hel.is_cell() {
return util::fail(context, tub);
} }
else {
let n_hel = slot(hel, 2)?;
let l_hel = slot(hel, 6)?;
let r_hel = slot(hel, 7)?;
let pn_hel = n_hel.as_cell()?.head();
let qn_hel = n_hel.as_cell()?.tail();
let mut bit = false;
vex = slam_vex?.as_cell()?; if !pn_hel.is_cell() {
p_vex = vex.head(); bit = true;
q_vex = vex.tail(); }
else {
let hpn_hel = pn_hel.as_cell()?.head();
let tpn_hel = pn_hel.as_cell()?.tail();
if !hpn_hel.as_atom()?.is_direct() || !tpn_hel.as_atom()?.is_direct() {
return util::fail(context, tub);
}
else {
let iq_tub_dat = iq_tub.as_direct()?.data();
let hpn_hel_dat = hpn_hel.as_direct()?.data();
let tpn_hel_dat = tpn_hel.as_direct()?.data();
bit = (iq_tub_dat >= hpn_hel_dat) && (iq_tub_dat <= tpn_hel_dat);
}
}
if bit {
return slam(context, qn_hel, tub);
}
else {
if stew_wor(iq_tub, pn_hel)? {
hel = l_hel;
}
else {
hel = r_hel;
}
}
}
} }
eprintln!("stir: vex loop done\r");
p_wag = p_vex;
puq_wag = rud;
quq_wag = tub;
} }
}
// unwind the stack, folding parse results into [wag] by way of [raq] Err(e) => { return Err(JetErr::Fail(e.into())); }
eprintln!("stir: unwinding stack\r");
while !context.stack.stack_is_empty() {
let par_u = unsafe { *(context.stack.top::<StirPair>()) };
p_wag = util::last(par_u.har, p_wag)?;
let sam = T(&mut context.stack, &[par_u.res, puq_wag]);
puq_wag = slam(context, raq, sam)?;
unsafe {
context.stack.pop::<StirPair>();
};
}
let res = T(&mut context.stack, &[p_wag, D(0), puq_wag, quq_wag]);
Ok(res)
})
} }
} }

View File

@ -5,10 +5,10 @@ use std::io;
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
// debug // debug
eprintln!("serf: pid {}", std::process::id()); // eprintln!("serf: pid {}", std::process::id());
if unsafe { libc::kill(std::process::id() as i32, libc::SIGSTOP) } != 0 { // if unsafe { libc::kill(std::process::id() as i32, libc::SIGSTOP) } != 0 {
panic!("Could not stop ourselves."); // panic!("Could not stop ourselves.");
}; // };
let filename = env::args().nth(1).expect("Must provide input filename"); let filename = env::args().nth(1).expect("Must provide input filename");