From 712f90e62c8d2c9740aeeec75f714c94431f031d Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Mon, 4 Dec 2023 18:29:15 -0600 Subject: [PATCH 1/2] main: just be a serf, panic if not a serf --- rust/ares/src/main.rs | 72 ++----------------------------------------- 1 file changed, 2 insertions(+), 70 deletions(-) diff --git a/rust/ares/src/main.rs b/rust/ares/src/main.rs index c91c89a..11aa079 100644 --- a/rust/ares/src/main.rs +++ b/rust/ares/src/main.rs @@ -1,22 +1,6 @@ -use ares::hamt::Hamt; -use ares::interpreter::{interpret, Context}; -use ares::jets::cold::Cold; -use ares::jets::hot::Hot; -use ares::jets::warm::Warm; -use ares::mem::NockStack; -use ares::newt::Newt; -use ares::noun::{IndirectAtom, Noun, D}; use ares::serf::serf; -use ares::serialization::{cue, jam}; -use memmap::Mmap; -use memmap::MmapMut; use std::env; -use std::fs::File; -use std::fs::OpenOptions; use std::io; -use std::mem; -use std::ptr::copy_nonoverlapping; -use std::ptr::write_bytes; fn main() -> io::Result<()> { // debug @@ -50,58 +34,6 @@ fn main() -> io::Result<()> { return serf(); } - let output_filename = format!("{}.out", filename); - let f = File::open(filename)?; - let in_len = f.metadata()?.len(); - let mut stack = NockStack::new(8 << 10 << 10, 0); - let jammed_input = unsafe { - let in_map = Mmap::map(&f)?; - let word_len = (in_len + 7) >> 3; - let (mut atom, dest) = IndirectAtom::new_raw_mut(&mut stack, word_len as usize); - write_bytes(dest.add(word_len as usize - 1), 0, 1); - copy_nonoverlapping(in_map.as_ptr(), dest as *mut u8, in_len as usize); - mem::drop(in_map); - atom.normalize_as_atom() - }; - let input = cue(&mut stack, jammed_input); - let input_cell = input - .as_cell() - .expect("Input must be jam of subject/formula pair"); - let newt = Newt::new_mock(); - let cache = Hamt::::new(); - let cold = Cold::new(&mut stack); - let warm = Warm::new(); - let hot = Hot::init(&mut stack); - let mut context = Context { - stack, - newt, - cache, - cold, - warm, - hot, - scry_stack: D(0), - trace_info: None, - }; - let result = - interpret(&mut context, input_cell.head(), input_cell.tail()).expect("nock failed"); - if let Ok(atom) = result.as_atom() { - println!("Result: {}", atom); - } - let jammed_result = jam(&mut context.stack, result); - let f_out = OpenOptions::new() - .read(true) - .write(true) - .create(true) - .open(output_filename)?; - f_out.set_len((jammed_result.size() << 3) as u64)?; - unsafe { - let mut out_map = MmapMut::map_mut(&f_out)?; - copy_nonoverlapping( - jammed_result.data_pointer() as *mut u8, - out_map.as_mut_ptr(), - jammed_result.size() << 3, - ); - out_map.flush()?; - }; - Ok(()) + panic!("Ares can only run as a serf!"); + } From f2e9aa1e94e3cead3313a240bbcd28896fec31a4 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Wed, 6 Dec 2023 08:24:13 -0600 Subject: [PATCH 2/2] main: format --- rust/ares/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/ares/src/main.rs b/rust/ares/src/main.rs index 11aa079..deeb6c3 100644 --- a/rust/ares/src/main.rs +++ b/rust/ares/src/main.rs @@ -35,5 +35,4 @@ fn main() -> io::Result<()> { } panic!("Ares can only run as a serf!"); - }