Skip to content

Commit

Permalink
moar cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthz committed Dec 18, 2023
1 parent 936dcb0 commit f652aed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hashbrown = "0.14"
werbolg-core = { path = "werbolg-core" }
werbolg-exec = { path = "werbolg-exec" }
werbolg-compile = { path = "werbolg-compile" }
werbolg-interpret = { path = "werbolg-interpret" }
# werbolg-interpret = { path = "werbolg-interpret" }
werbolg-lang-common = { path = "werbolg-lang-common" }
werbolg-lang-rusty = { path = "werbolg-lang-rusty", optional = true }
werbolg-lang-lispy = { path = "werbolg-lang-lispy", optional = true }
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod lang;
mod value;

use hashbrown::HashMap;
use value::Value;
use value::{Value, HASHMAP_KIND};
use werbolg_compile::{code_dump, compile, symbols::IdVec, CompilationError, Environment};
use werbolg_core::{Ident, Literal, NifId};
use werbolg_exec::{
Expand Down Expand Up @@ -56,8 +56,8 @@ fn nif_hashtable(_args: &[Value]) -> Result<Value, ExecutionError> {
fn nif_hashtable_get(args: &[Value]) -> Result<Value, ExecutionError> {
let Value::HashMap(h) = &args[0] else {
return Err(ExecutionError::ValueKindUnexpected {
value_expected: Value::Integral(0).descriptor(),
value_got: Value::Integral(0).descriptor(),
value_expected: HASHMAP_KIND,
value_got: args[0].descriptor(),
});
};
let index_bignum = args[1].int()?;
Expand Down Expand Up @@ -156,15 +156,15 @@ fn main() -> Result<(), ()> {
pub struct Env<'m, L, T, V> {
environment: Environment,
nifs: IdVec<NifId, NIF<'m, L, T, V>>,
nifs_binds: werbolg_interpret::Bindings<NifId>,
//nifs_binds: werbolg_interpret::Bindings<NifId>,
}

impl<'m, L, T, V: Valuable> Env<'m, L, T, V> {
pub fn new() -> Self {
Self {
environment: Environment::new(),
nifs: IdVec::new(),
nifs_binds: werbolg_interpret::Bindings::new(),
//nifs_binds: werbolg_interpret::Bindings::new(),
}
}
pub fn add_native_call(&mut self, ident: &'static str, f: NIFCall<'m, L, T, V>) {
Expand All @@ -173,7 +173,7 @@ fn main() -> Result<(), ()> {
name: ident,
call: f,
});
self.nifs_binds.add(werbolg_core::Ident::from(ident), id);
//self.nifs_binds.add(werbolg_core::Ident::from(ident), id);
assert_eq!(id, id2)
}

Expand Down
18 changes: 12 additions & 6 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ pub enum Value {
impl Value {
fn desc(&self) -> ValueKind {
match self {
Value::Unit => b" unit",
Value::Bool(_) => b" bool",
Value::HashMap(_) => b" hashmap",
Value::Integral(_) => b" int",
Value::Fun(_) => b" fun",
Value::Unit => UNIT_KIND,
Value::Bool(_) => BOOL_KIND,
Value::HashMap(_) => HASHMAP_KIND,
Value::Integral(_) => INT_KIND,
Value::Fun(_) => FUN_KIND,
}
}
}

pub const UNIT_KIND: ValueKind = b" unit";
pub const BOOL_KIND: ValueKind = b" bool";
pub const HASHMAP_KIND: ValueKind = b" hashmap";
pub const INT_KIND: ValueKind = b" int";
pub const FUN_KIND: ValueKind = b" fun";

impl Valuable for Value {
fn descriptor(&self) -> werbolg_exec::ValueKind {
self.desc()
Expand Down Expand Up @@ -64,7 +70,7 @@ impl Value {
match self {
Value::Integral(o) => Ok(*o),
_ => Err(ExecutionError::ValueKindUnexpected {
value_expected: Value::Integral(0).descriptor(),
value_expected: INT_KIND,
value_got: self.descriptor(),
}),
}
Expand Down

0 comments on commit f652aed

Please sign in to comment.