HyphaeVM Cons instruction prototype
All checks were successful
per-push tests / build (push) Successful in 49s
per-push tests / test-frontend (push) Successful in 33s
per-push tests / test-utility (push) Successful in 35s
per-push tests / test-backend (push) Successful in 29s
per-push tests / timed-decomposer-parse (push) Successful in 34s
All checks were successful
per-push tests / build (push) Successful in 49s
per-push tests / test-frontend (push) Successful in 33s
per-push tests / test-utility (push) Successful in 35s
per-push tests / test-backend (push) Successful in 29s
per-push tests / timed-decomposer-parse (push) Successful in 34s
This commit implements the Cons instruction with desired behavior. Tests are yet to be implemented for any instruction, but are coming soon. Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
cf626b2bfc
commit
524f79733c
2 changed files with 28 additions and 6 deletions
|
|
@ -41,7 +41,7 @@ use organelle::Number;
|
||||||
|
|
||||||
/* Gc
|
/* Gc
|
||||||
* This is a heap allocated Rc passed around such that it fits into
|
* This is a heap allocated Rc passed around such that it fits into
|
||||||
* a physical register. The pointer is to a Box<Rc<T>>, but custom
|
* a physical register. The pointer is to a Box<Rc<T>>, but custom
|
||||||
* deref implementation will ensure that deref always points to the
|
* deref implementation will ensure that deref always points to the
|
||||||
* encapsulated T
|
* encapsulated T
|
||||||
*/
|
*/
|
||||||
|
|
@ -201,6 +201,22 @@ impl Cons {
|
||||||
|
|
||||||
1 + next.len()
|
1 + next.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn append(&mut self, arg: Gc<Datum>) {
|
||||||
|
let Some(_) = self.0 else {
|
||||||
|
self.0 = Some(arg);
|
||||||
|
return
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(next) = &mut self.1 {
|
||||||
|
if let Datum::Cons(next) = next.deref_mut() {
|
||||||
|
next.append(arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.1 = Some(Datum::Cons(Cons(Some(arg), None)).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,10 @@ use crate::hmap::QuickMap;
|
||||||
use crate::stackstack::StackStack;
|
use crate::stackstack::StackStack;
|
||||||
use crate::instr as i;
|
use crate::instr as i;
|
||||||
use crate::util::{Operand, Program, Address};
|
use crate::util::{Operand, Program, Address};
|
||||||
use crate::heap::{Gc, Datum};
|
use crate::heap::{Gc, Datum, Cons};
|
||||||
|
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
use core::ops::DerefMut;
|
||||||
|
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
@ -475,10 +476,15 @@ impl VM {
|
||||||
},
|
},
|
||||||
|
|
||||||
i::CONS => {
|
i::CONS => {
|
||||||
/* CONS BEHAVIOR
|
let mut l = access!(&instr.1[0]).clone();
|
||||||
* L Datum is not list means create a new standard form list
|
if let Datum::Cons(l) = l.deref_mut() {
|
||||||
* L Datum is list then append the second element to the first
|
l.append(access!(&instr.1[1]).clone());
|
||||||
*/
|
} else {
|
||||||
|
access!(&instr.1[0], Datum::Cons(Cons(
|
||||||
|
Some(l),
|
||||||
|
Some(access!(&instr.1[1]).clone())
|
||||||
|
)).into());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue