Skip to content

Commit

Permalink
fix readback of partially applied ops (#356)
Browse files Browse the repository at this point in the history
Fix Readback of Partially Applied Ops
  • Loading branch information
enricozb authored May 29, 2024
2 parents c8f85a3 + 73dd755 commit 465f7a6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
12 changes: 6 additions & 6 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'i> CoreParser<'i> {
input.parse::<u64>().map_err(|err| format!("{err:?}"))
}
}

pub fn parse_numb(&mut self) -> Result<Numb, String> {
self.skip_trivia();

Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'i> CoreParser<'i> {
}
Ok(Net { root, rbag })
}

pub fn parse_book(&mut self) -> Result<Book, String> {
let mut defs = BTreeMap::new();
while !self.is_eof() {
Expand Down Expand Up @@ -270,9 +270,9 @@ impl Numb {
_ => {
let typ = numb.get_typ();
let val = numb.get_u24();
format!("[{}{:07X}]", match typ {
format!("[{}0x{:07X}]", match typ {
hvm::OP_ADD => "+",
hvm::OP_SUB => "-",
hvm::OP_SUB => "-",
hvm::FP_SUB => ":-",
hvm::OP_MUL => "*",
hvm::OP_DIV => "/",
Expand Down Expand Up @@ -362,7 +362,7 @@ impl Tree {
return Some(Tree::Era);
}
hvm::NUM => {
return Some(Tree::Num { val: Numb(port.get_val()) });
return Some(Tree::Num { val: Numb(port.get_val()) });
}
hvm::CON => {
let pair = net.node_load(port.get_val() as usize);
Expand All @@ -386,7 +386,7 @@ impl Tree {
let pair = net.node_load(port.get_val() as usize);
let fst = Tree::readback(net, pair.get_fst(), fids)?;
let snd = Tree::readback(net, pair.get_snd(), fids)?;
return Some(Tree::Swi { fst: Box::new(fst), snd: Box::new(snd) });
return Some(Tree::Swi { fst: Box::new(fst), snd: Box::new(snd) });
}
_ => {
unreachable!()
Expand Down
40 changes: 20 additions & 20 deletions src/hvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,26 +1782,26 @@ void pretty_print_numb(Numb word) {
}
default: {
switch (get_typ(word)) {
case OP_ADD: printf("[+%07X]", get_u24(word)); break;
case OP_SUB: printf("[-%07X]", get_u24(word)); break;
case FP_SUB: printf("[:-%07X]", get_u24(word)); break;
case OP_MUL: printf("[*%07X]", get_u24(word)); break;
case OP_DIV: printf("[/%07X]", get_u24(word)); break;
case FP_DIV: printf("[:/%07X]", get_u24(word)); break;
case OP_REM: printf("[%%%07X]", get_u24(word)); break;
case FP_REM: printf("[:%%%07X]", get_u24(word)); break;
case OP_EQ: printf("[=%07X]", get_u24(word)); break;
case OP_NEQ: printf("[!%07X]", get_u24(word)); break;
case OP_LT: printf("[<%07X]", get_u24(word)); break;
case OP_GT: printf("[>%07X]", get_u24(word)); break;
case OP_AND: printf("[&%07X]", get_u24(word)); break;
case OP_OR: printf("[|%07X]", get_u24(word)); break;
case OP_XOR: printf("[^%07X]", get_u24(word)); break;
case OP_SHL: printf("[<<%07X]", get_u24(word)); break;
case FP_SHL: printf("[:<<%07X]", get_u24(word)); break;
case OP_SHR: printf("[>>%07X]", get_u24(word)); break;
case FP_SHR: printf("[:>>%07X]", get_u24(word)); break;
default: printf("[?%07X]", get_u24(word)); break;
case OP_ADD: printf("[+0x%07X]", get_u24(word)); break;
case OP_SUB: printf("[-0x%07X]", get_u24(word)); break;
case FP_SUB: printf("[:-0x%07X]", get_u24(word)); break;
case OP_MUL: printf("[*0x%07X]", get_u24(word)); break;
case OP_DIV: printf("[/0x%07X]", get_u24(word)); break;
case FP_DIV: printf("[:/0x%07X]", get_u24(word)); break;
case OP_REM: printf("[%%0x%07X]", get_u24(word)); break;
case FP_REM: printf("[:%%0x%07X]", get_u24(word)); break;
case OP_EQ: printf("[=0x%07X]", get_u24(word)); break;
case OP_NEQ: printf("[!0x%07X]", get_u24(word)); break;
case OP_LT: printf("[<0x%07X]", get_u24(word)); break;
case OP_GT: printf("[>0x%07X]", get_u24(word)); break;
case OP_AND: printf("[&0x%07X]", get_u24(word)); break;
case OP_OR: printf("[|0x%07X]", get_u24(word)); break;
case OP_XOR: printf("[^0x%07X]", get_u24(word)); break;
case OP_SHL: printf("[<<0x%07X]", get_u24(word)); break;
case FP_SHL: printf("[:<<0x%07X]", get_u24(word)); break;
case OP_SHR: printf("[>>0x%07X]", get_u24(word)); break;
case FP_SHR: printf("[:>>0x%07X]", get_u24(word)); break;
default: printf("[?0x%07X]", get_u24(word)); break;
}
break;
}
Expand Down
40 changes: 20 additions & 20 deletions src/hvm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2232,26 +2232,26 @@ __device__ void pretty_print_numb(Numb word) {
}
default: {
switch (get_typ(word)) {
case OP_ADD: printf("[+%07X]", get_u24(word)); break;
case OP_SUB: printf("[-%07X]", get_u24(word)); break;
case FP_SUB: printf("[:-%07X]", get_u24(word)); break;
case OP_MUL: printf("[*%07X]", get_u24(word)); break;
case OP_DIV: printf("[/%07X]", get_u24(word)); break;
case FP_DIV: printf("[:/%07X]", get_u24(word)); break;
case OP_REM: printf("[%%%07X]", get_u24(word)); break;
case FP_REM: printf("[:%%%07X]", get_u24(word)); break;
case OP_EQ: printf("[=%07X]", get_u24(word)); break;
case OP_NEQ: printf("[!%07X]", get_u24(word)); break;
case OP_LT: printf("[<%07X]", get_u24(word)); break;
case OP_GT: printf("[>%07X]", get_u24(word)); break;
case OP_AND: printf("[&%07X]", get_u24(word)); break;
case OP_OR: printf("[|%07X]", get_u24(word)); break;
case OP_XOR: printf("[^%07X]", get_u24(word)); break;
case OP_SHL: printf("[<<%07X]", get_u24(word)); break;
case FP_SHL: printf("[:<<%07X]", get_u24(word)); break;
case OP_SHR: printf("[>>%07X]", get_u24(word)); break;
case FP_SHR: printf("[:>>%07X]", get_u24(word)); break;
default: printf("[?%07X]", get_u24(word)); break;
case OP_ADD: printf("[+0x%07X]", get_u24(word)); break;
case OP_SUB: printf("[-0x%07X]", get_u24(word)); break;
case FP_SUB: printf("[:-0x%07X]", get_u24(word)); break;
case OP_MUL: printf("[*0x%07X]", get_u24(word)); break;
case OP_DIV: printf("[/0x%07X]", get_u24(word)); break;
case FP_DIV: printf("[:/0x%07X]", get_u24(word)); break;
case OP_REM: printf("[%%0x%07X]", get_u24(word)); break;
case FP_REM: printf("[:%%0x%07X]", get_u24(word)); break;
case OP_EQ: printf("[=0x%07X]", get_u24(word)); break;
case OP_NEQ: printf("[!0x%07X]", get_u24(word)); break;
case OP_LT: printf("[<0x%07X]", get_u24(word)); break;
case OP_GT: printf("[>0x%07X]", get_u24(word)); break;
case OP_AND: printf("[&0x%07X]", get_u24(word)); break;
case OP_OR: printf("[|0x%07X]", get_u24(word)); break;
case OP_XOR: printf("[^0x%07X]", get_u24(word)); break;
case OP_SHL: printf("[<<0x%07X]", get_u24(word)); break;
case FP_SHL: printf("[:<<0x%07X]", get_u24(word)); break;
case OP_SHR: printf("[>>0x%07X]", get_u24(word)); break;
case FP_SHR: printf("[:>>0x%07X]", get_u24(word)); break;
default: printf("[?0x%07X]", get_u24(word)); break;
}
break;
}
Expand Down
30 changes: 15 additions & 15 deletions src/hvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Numb {
}

// U24: unsigned 24-bit integer

pub fn new_u24(val: u32) -> Self {
Numb((val << 5) as Val | (TY_U24 as Val))
}
Expand All @@ -249,7 +249,7 @@ impl Numb {
}

// F24: 24-bit float

pub fn new_f24(val: f32) -> Self {
let bits = val.to_bits();
let mut shifted_bits = bits >> 8;
Expand Down Expand Up @@ -320,7 +320,7 @@ impl Numb {
OP_XOR => Numb::new_u24(av ^ bv),
OP_SHL => Numb::new_u24(av << (bv & 31)),
OP_SHR => Numb::new_u24(av >> (bv & 31)),
FP_SHL => Numb::new_u24(bv << (av & 31)),
FP_SHL => Numb::new_u24(bv << (av & 31)),
FP_SHR => Numb::new_u24(bv >> (av & 31)),
_ => unreachable!(),
}
Expand Down Expand Up @@ -442,7 +442,7 @@ impl<'a> GNet<'a> {
pub fn vars_store(&self, var: usize, val: Port) {
self.vars[var].0.store(val.0, Ordering::Relaxed);
}

pub fn node_exchange(&self, loc: usize, val: Pair) -> Pair {
Pair(self.node[loc].0.swap(val.0, Ordering::Relaxed))
}
Expand Down Expand Up @@ -512,7 +512,7 @@ impl TMem {
rbag: RBag::new(),
}
}

pub fn node_alloc(&mut self, net: &GNet, num: usize) -> usize {
let mut got = 0;
for _ in 0..net.nlen {
Expand Down Expand Up @@ -603,7 +603,7 @@ impl TMem {

// Links.
self.link_pair(net, Pair::new(a, b));

true
}

Expand Down Expand Up @@ -649,7 +649,7 @@ impl TMem {
self.link_pair(net, pair.adjust_pair(self));
}
self.link_pair(net, Pair::new(def.root.adjust_port(self), b));

true
}

Expand Down Expand Up @@ -678,7 +678,7 @@ impl TMem {
// Links.
self.link_pair(net, Pair::new(a, b1));
self.link_pair(net, Pair::new(a, b2));

true
}

Expand Down Expand Up @@ -728,7 +728,7 @@ impl TMem {
let b_ = net.node_take(b.get_val() as usize);
let b1 = b_.get_fst();
let b2 = b_.get_snd();

// Stores new vars.
net.vars_create(self.vloc[0], NONE);
net.vars_create(self.vloc[1], NONE);
Expand All @@ -746,7 +746,7 @@ impl TMem {
self.link_pair(net, Pair::new(Port::new(b.get_tag(), self.nloc[1] as u32), a2));
self.link_pair(net, Pair::new(Port::new(a.get_tag(), self.nloc[2] as u32), b1));
self.link_pair(net, Pair::new(Port::new(a.get_tag(), self.nloc[3] as u32), b2));

true
}

Expand All @@ -768,7 +768,7 @@ impl TMem {
let b_ = net.node_take(b.get_val() as usize);
let b1 = b_.get_fst();
let b2 = net.enter(b_.get_snd());

// Performs operation.
if b1.get_tag() == NUM {
let bv = b1.get_val();
Expand All @@ -788,7 +788,7 @@ impl TMem {
if !self.get_resources(net, 1, 2, 0) {
return false;
}

// Checks availability
if net.node_load(b.get_val() as usize).0 == 0 {
return false;
Expand All @@ -799,7 +799,7 @@ impl TMem {
let b_ = net.node_take(b.get_val() as usize);
let b1 = b_.get_fst();
let b2 = b_.get_snd();

// Stores new nodes.
if av == 0 {
net.node_create(self.nloc[0], Pair::new(b2, Port::new(ERA,0)));
Expand Down Expand Up @@ -936,13 +936,13 @@ impl Book {

// Writes the rbag length
buf.extend_from_slice(&(def.rbag.len() as u32).to_ne_bytes());

// Writes the node length
buf.extend_from_slice(&(def.node.len() as u32).to_ne_bytes());

// Writes the vars length
buf.extend_from_slice(&(def.vars as u32).to_ne_bytes());

// Writes the root
buf.extend_from_slice(&def.root.0.to_ne_bytes());

Expand Down

0 comments on commit 465f7a6

Please sign in to comment.