Skip to content

Commit

Permalink
further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthz committed Dec 18, 2023
1 parent 40b947a commit 669c5b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
7 changes: 0 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,14 @@ fn main() -> Result<(), ()> {
env.add_native_pure_fun("==", nif_eq);
env.add_native_pure_fun("table_new", nif_hashtable);
env.add_native_pure_fun("table_get", nif_hashtable_get);
//environment.add(ident);

let compilation_params = werbolg_compile::CompilationParams { literal_mapper };
let exec_module =
compile(&compilation_params, module, &mut env.environment).expect("no compilation error");

//exec_module.print();
code_dump(&exec_module.code, &exec_module.funs);

let ee = env.finalize();
//let mut em = ExecutionMachine::new(&exec_module, ee, ());

let entry_point = exec_module
.funs_tbl
Expand All @@ -231,10 +228,6 @@ fn main() -> Result<(), ()> {
let execution_params = ExecutionParams { literal_to_value };
let mut em = ExecutionMachine::new(&exec_module, ee, execution_params, ());

//let val = werbolg_exec::exec(&mut em, Ident::from("main"), &[]).expect("no execution error");

//println!("{:?}", val);

match werbolg_exec::exec(&mut em, entry_point, &[]) {
Err(e) => {
println!("error: {:?} at {}", e, em.ip);
Expand Down
11 changes: 0 additions & 11 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ use werbolg_exec::{ExecutionError, Valuable, ValueKind};
#[derive(Clone, Debug)]
pub enum Value {
Unit,
// Simple values
Bool(bool),
Integral(u64),
//Binary(Box<[u8]>),
HashMap(HashMap<u32, u64>),
// Composite
//List(Box<[Value]>),
//Struct(ConstrId, Box<[Value]>),
//Enum(u32, Box<[Value]>),
// Functions
Fun(ValueFun),
}

Expand All @@ -25,10 +18,6 @@ impl Value {
Value::Bool(_) => b" bool",
Value::HashMap(_) => b" hashmap",
Value::Integral(_) => b" int",
//Value::Binary(_) => b" binary",
//Value::List(_) => b" list",
//Value::Struct(_, _) => b" struct",
//Value::Enum(_, _) => b" enum",
Value::Fun(_) => b" fun",
}
}
Expand Down
24 changes: 16 additions & 8 deletions werbolg-exec/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ pub enum NIFCall<'m, L, T, V> {
Mut(fn(&mut ExecutionMachine<'m, L, T, V>, &[V]) -> Result<V, ExecutionError>),
}

/// Execute the module, calling function identified by FunId, with the arguments in parameters
/// Execute the module, calling function identified by FunId, with the arguments in parameters.
pub fn exec<'module, L, T, V: Valuable>(
em: &mut ExecutionMachine<'module, L, T, V>,
call: ir::FunId,
args: &[V],
) -> Result<V, ExecutionError> {
match initialize(em, call, args)? {
None => (),
Some(v) => return Ok(v),
};

exec_loop(em)
}

pub fn initialize<'module, L, T, V: Valuable>(
em: &mut ExecutionMachine<'module, L, T, V>,
call: ir::FunId,
args: &[V],
) -> Result<Option<V>, ExecutionError> {
let arity = args
.len()
.try_into()
Expand All @@ -39,14 +52,9 @@ pub fn exec<'module, L, T, V: Valuable>(
em.ip_set(ip);
em.sp_set(local);
}
CallResult::Value(value) => return Ok(value),
CallResult::Value(value) => return Ok(Some(value)),
};

//println!("===== initial =====");
//em.debug_state();
//println!("===================");

exec_loop(em)
Ok(None)
}

pub fn exec_continue<'m, L, T, V: Valuable>(
Expand Down
2 changes: 0 additions & 2 deletions werbolg-exec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ pub enum ExecutionError {
ArityOverflow {
got: usize,
},
//AccessingInexistentField(ir::Ident, ir::Ident),
//AccessingFieldNotAStruct(ir::Ident, ValueKind),
MissingBinding(ir::Ident),
InternalErrorFunc(ir::FunId),
StructMismatch {
Expand Down

0 comments on commit 669c5b5

Please sign in to comment.