+32
-3
@@ -1,4 +1,5 @@
|
||||
use wasmtime::*;
|
||||
use crate::types;
|
||||
|
||||
pub fn immediate_p (store : impl AsContext, x : Rooted<EqRef>) -> bool {
|
||||
x.is_i31 (store).unwrap ()
|
||||
@@ -9,8 +10,13 @@ pub enum Immediate {
|
||||
Bool (bool),
|
||||
}
|
||||
|
||||
pub enum HeapObject {
|
||||
Procedure
|
||||
}
|
||||
|
||||
pub enum Scm {
|
||||
Immediate (Immediate),
|
||||
HeapObject (HeapObject),
|
||||
}
|
||||
|
||||
#[allow(nonstandard_style)]
|
||||
@@ -33,14 +39,34 @@ pub fn interpret_immediate (x : scm_bits) -> Option<Immediate> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn interpret (store : impl AsContext, x : Rooted<EqRef>) -> Option<Scm> {
|
||||
if let Some (imm) = x.as_i31 (store).unwrap () {
|
||||
Some (Scm::Immediate (interpret_immediate (imm.get_u32 ())?))
|
||||
pub fn interpret_heap_object (
|
||||
store : impl AsContext,
|
||||
x : Rooted<EqRef>
|
||||
) -> Result<Option<HeapObject>> {
|
||||
if x.matches_ty (&store, &types::closure (&store)?)? {
|
||||
Ok (Some (HeapObject::Procedure))
|
||||
} else {
|
||||
todo! ()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn interpret (
|
||||
store : impl AsContext,
|
||||
x : Rooted<EqRef>
|
||||
) -> Result<Option<Scm>> {
|
||||
if let Some (imm) = x.as_i31 (&store)? {
|
||||
Ok (
|
||||
interpret_immediate (imm.get_u32 ())
|
||||
.map (Scm::Immediate)
|
||||
)
|
||||
} else {
|
||||
Ok (
|
||||
interpret_heap_object (&store, x)?
|
||||
.map (Scm::HeapObject)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encode_immediate (
|
||||
store : impl AsContext,
|
||||
imm : Immediate
|
||||
@@ -60,6 +86,9 @@ pub fn encode (store : impl AsContextMut, x : Scm) -> Rooted<EqRef> {
|
||||
.unwrap ();
|
||||
EqRef::from_i31 (store, i31)
|
||||
}
|
||||
Scm::HeapObject (ho) => {
|
||||
todo! ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user