Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 45d9f27

Browse files
committed
ska: working nouncode rust interpreter with @uxor
1 parent 3ea4a6c commit 45d9f27

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed

hoon/codegen/sur/gene.hoon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@
148148
:: t - target block
149149
:: u - subject
150150
:: v - subject but registerized
151-
:: w - walt
152-
:: x - sans
153151
:: z - "zero" / true case
154152
::
155153
:: cases:

rust/ares/bin/cg.jam

-4.97 KB
Binary file not shown.

rust/ares/src/codegen.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::jets::seam::util::get_by;
55
use crate::jets::util::slot;
66
use crate::jets::{Jet, JetErr::*};
77
use crate::mem::{NockStack, Preserve};
8-
use crate::noun::{slot_pam, DirectAtom, Noun, D, NOUN_NONE, T};
8+
use crate::mug::mug_u32;
9+
use crate::noun::{slot_bar, slot_pam, DirectAtom, Noun, D, NOUN_NONE, T};
910
use crate::unifying_equality::unifying_equality;
1011
use ares_macros::tas;
1112
use either::{Left, Right};
@@ -82,14 +83,14 @@ pub struct Pile {
8283

8384
impl Pile {
8485
pub fn new(context: &mut Context, pile: Noun) -> Self {
85-
let well = slot(pile, slot_pam(5))
86+
let well = slot(pile, slot_pam(3))
8687
.unwrap()
8788
.as_atom()
8889
.unwrap()
8990
.as_u64()
9091
.unwrap() as usize;
9192
Self {
92-
sans: slot(pile, slot_pam(3))
93+
sans: slot(pile, slot_pam(1))
9394
.unwrap()
9495
.as_atom()
9596
.unwrap()
@@ -114,28 +115,20 @@ impl Preserve for Pile {
114115
}
115116
}
116117

117-
// +$ pile
118-
// $: =bell
119-
// walt=(list @uvre)
120-
// sans=$~(0v1 @uvre) :: 0v0 reserved for indirect
121-
// will=(map @uwoo blob)
122-
// well=$~(0w2 @uwoo) :: 0w0 indirect, 0w1 direct
123-
// ==
124-
// hill=(map @uxor pile)
125-
126118
#[derive(Copy, Clone)]
127119
pub struct Hill {
128120
pub lent: usize,
129121
pub data: *mut Pile,
130122
}
131123

132124
impl Hill {
133-
/// Transforms the $hill from the `CgContext` into a `Hill` structure and
125+
/// Transforms the $hill from the `CgContext.fuji` into a `Hill` structure and
134126
/// allocates it on the NockStack.
135127
fn new(context: &mut Context) -> Self {
136128
let stack = &mut context.stack;
137129
let fuji = context.cg_context.fuji;
138-
let well = slot(fuji, slot_pam(5)) // total number of blocks
130+
let mut hill = slot(fuji, slot_pam(2)).expect("Codegen fuji should have hill");
131+
let next = slot(fuji, slot_pam(3)) // total number of piles
139132
.expect("Codegen fuji should have next")
140133
.as_atom()
141134
.unwrap()
@@ -144,24 +137,23 @@ impl Hill {
144137
unsafe {
145138
let hill_p = stack.struct_alloc::<Hill>(1);
146139
*hill_p = Hill {
147-
data: stack.struct_alloc::<Pile>(well),
148-
lent: well,
140+
data: stack.struct_alloc::<Pile>(next),
141+
lent: next,
149142
};
150-
let piles: &mut [Pile] = from_raw_parts_mut((*hill_p).data, well);
151-
let mut hill = slot(fuji, slot_pam(2)).expect("Codegen fuji should have hill");
143+
let pils: &mut [Pile] = from_raw_parts_mut((*hill_p).data, next);
152144
let mut i = 0;
153-
while i < well {
145+
while i < next {
154146
// XX walk tree manually
155147
let piln = get_by(&mut context.stack, &mut hill, &mut D(i as u64))
156148
.unwrap()
157149
.unwrap();
158150
let pile = Pile::new(context, piln);
159-
piles[i] = pile;
151+
pils[i] = pile;
160152
i += 1;
161153
}
162154
Self {
163-
data: piles.as_mut_ptr(),
164-
lent: well,
155+
data: pils.as_mut_ptr(),
156+
lent: next,
165157
}
166158
}
167159
}
@@ -170,21 +162,26 @@ impl Hill {
170162
unsafe { from_raw_parts(self.data as *const Pile, self.lent) }
171163
}
172164

173-
fn _as_mut_slice<'a>(&mut self) -> &'a mut [Pile] {
165+
fn as_mut_slice<'a>(&mut self) -> &'a mut [Pile] {
174166
unsafe { from_raw_parts_mut(self.data as *mut Pile, self.lent) }
175167
}
176168
}
177169

178170
impl Preserve for Hill {
179171
unsafe fn preserve(&mut self, stack: &mut NockStack) {
172+
// if stack.is_in_frame(self as *const Hill) {
180173
let dest: *mut Hill = stack.struct_alloc_in_previous_frame(1);
181-
copy_nonoverlapping(self as *mut Hill, dest, 1);
174+
(*dest).data = stack.struct_alloc_in_previous_frame::<Pile>(self.lent);
175+
(*dest).lent = self.lent;
176+
copy_nonoverlapping::<Pile>(self.data, (*dest).data, self.lent);
182177
let mut i = 0;
183178
while i < self.lent {
184-
let pile = (self.data as *mut Pile).add(i).as_mut().unwrap();
179+
let pile = ((*dest).data as *mut Pile).add(i).as_mut().unwrap();
185180
stack.preserve(pile);
186181
i += 1;
187182
}
183+
(*self) = *dest;
184+
// }
188185
}
189186

190187
unsafe fn assert_in_stack(&self, stack: &NockStack) {
@@ -208,7 +205,7 @@ pub struct Blocks {
208205
}
209206

210207
impl Blocks {
211-
/// Transforms the $hill from the `CgContext` into a `Blocks` structure and
208+
/// Transforms the $will into a `Blocks` structure and
212209
/// allocates it on the NockStack.
213210
fn new(context: &mut Context, will: &mut Noun, well: usize) -> Self {
214211
let stack = &mut context.stack;
@@ -239,21 +236,26 @@ impl Blocks {
239236
unsafe { from_raw_parts(self.data as *const Noun, self.lent) }
240237
}
241238

242-
fn _as_mut_slice<'a>(&mut self) -> &'a mut [Noun] {
239+
fn as_mut_slice<'a>(&mut self) -> &'a mut [Noun] {
243240
unsafe { from_raw_parts_mut(self.data as *mut Noun, self.lent) }
244241
}
245242
}
246243

247244
impl Preserve for Blocks {
248245
unsafe fn preserve(&mut self, stack: &mut NockStack) {
246+
// if stack.is_in_frame(self as *const Blocks) {
249247
let dest: *mut Blocks = stack.struct_alloc_in_previous_frame(1);
250-
copy_nonoverlapping(self as *mut Blocks, dest, 1);
248+
(*dest).data = stack.struct_alloc_in_previous_frame::<Noun>(self.lent);
249+
(*dest).lent = self.lent;
250+
copy_nonoverlapping::<Noun>(self.data, (*dest).data, self.lent);
251251
let mut i = 0;
252252
while i < self.lent {
253-
let block = (self.data as *mut Noun).add(i).as_mut().unwrap();
254-
stack.preserve(block);
253+
let blob = ((*dest).data as *mut Noun).add(i).as_mut().unwrap();
254+
stack.preserve(blob);
255255
i += 1;
256256
}
257+
(*self) = *dest;
258+
// }
257259
}
258260

259261
unsafe fn assert_in_stack(&self, stack: &NockStack) {
@@ -779,7 +781,6 @@ pub fn cg_interpret_with_snapshot(
779781
}
780782
tas!(b"jmp") => {
781783
// [%jmp a=@uxor v=(list @uvre)]
782-
eprintln!("jmp : {}", inst_cell);
783784
let t_jmp = inst_cell.tail().as_cell().unwrap();
784785

785786
let jmp_a = t_jmp.head().as_atom().unwrap().as_u64().unwrap() as usize;

rust/ares/src/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::jets::util::slot;
22
use crate::mem::NockStack;
3+
use crate::mug::mug_u32;
34
use crate::noun::{Noun, D};
45
use crate::serialization::cue_bytes;
5-
use crate::mug::mug_u32;
66
use ares_macros::tas;
77
use std::include_bytes;
88

@@ -11,7 +11,7 @@ pub fn load_cg(stack: &mut NockStack) -> (Noun, Noun) {
1111
let cg_bytes = include_bytes!("../bin/cg.jam");
1212
let cg_noun = cue_bytes(stack, cg_bytes);
1313
let cg_mug = mug_u32(stack, cg_noun);
14-
eprintln!("codegen mug: {:x}", cg_mug);
14+
// eprintln!("codegen mug: {:x}", cg_mug);
1515
assert!(unsafe { slot(cg_noun, 2).unwrap().raw_equals(D(tas!(b"cg"))) });
1616
(slot(cg_noun, 6).unwrap(), slot(cg_noun, 7).unwrap())
1717
}

rust/ares/src/serf.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::codegen::{self, cg_interpret, Blocks, Hill, Pile};
1+
use crate::codegen::{self, cg_interpret, Hill, Pile};
22
use crate::hamt::Hamt;
33
use crate::interpreter::{inc, interpret, Error, Mote, WhichInterpreter};
44
use crate::jets::cold::Cold;
@@ -88,6 +88,8 @@ struct SnapshotMem {
8888
pub arvo: Noun,
8989
pub cold: Cold,
9090
pub line: Noun,
91+
pub fuji: Noun,
92+
pub hill: Hill,
9193
}
9294

9395
const PMA_CURRENT_SNAPSHOT_VERSION: u64 = 1;
@@ -132,6 +134,8 @@ impl Context {
132134
(*snapshot_mem_ptr).arvo = self.arvo;
133135
(*snapshot_mem_ptr).cold = self.nock_context.cold;
134136
(*snapshot_mem_ptr).line = self.nock_context.cg_context.line;
137+
// (*snapshot_mem_ptr).fuji = self.nock_context.cg_context.fuji;
138+
// (*snapshot_mem_ptr).hill = self.nock_context.cg_context.hill;
135139
snapshot_mem_ptr
136140
});
137141

@@ -142,6 +146,8 @@ impl Context {
142146
self.event_num = (*snapshot.0).event_num;
143147
self.nock_context.cold = (*snapshot.0).cold;
144148
self.nock_context.cg_context.line = (*snapshot.0).line;
149+
// self.nock_context.cg_context.fuji = (*snapshot.0).fuji;
150+
// self.nock_context.cg_context.hill = (*snapshot.0).hill;
145151

146152
handle
147153
};
@@ -247,6 +253,8 @@ impl Context {
247253
/// [event_update] and invocation of this function
248254
pub unsafe fn preserve_event_update_leftovers(&mut self) {
249255
let stack = &mut self.nock_context.stack;
256+
stack.preserve(&mut self.nock_context.cg_context.fuji);
257+
stack.preserve(&mut self.nock_context.cg_context.hill);
250258
stack.preserve(&mut self.nock_context.warm);
251259
stack.preserve(&mut self.nock_context.hot);
252260
stack.flip_top_frame(0);

0 commit comments

Comments
 (0)