Move src/syn/word.rs to src/scope.rs; add BuiltinFn
* crate::scope instead of crate::syn::word, which makes more sense because scopes are not really used in syntax at all * Reference-counted BuiltinFn values are available for creation now Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -4,13 +4,11 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::syn::ast::SpExpr;
|
||||
use crate::{
|
||||
syn::{span::Span, words::Scope},
|
||||
vm::inst::Inst,
|
||||
};
|
||||
use crate::vm::machine::Machine;
|
||||
use crate::{scope::Scope, syn::span::Span, vm::inst::Inst};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fmt::{self, Display};
|
||||
use std::fmt::{self, Debug, Display};
|
||||
use std::rc::{Rc, Weak};
|
||||
|
||||
pub type Str = String;
|
||||
@@ -72,6 +70,7 @@ pub enum Value {
|
||||
Str(Str),
|
||||
Quote(Quote),
|
||||
ObjPtr(ObjPtr),
|
||||
BuiltinFn(BuiltinFn),
|
||||
}
|
||||
|
||||
impl Value {
|
||||
@@ -84,6 +83,7 @@ impl Value {
|
||||
Str(_) => "str",
|
||||
Quote(_) => "quote",
|
||||
ObjPtr(_) => "object",
|
||||
BuiltinFn(_) => "builtin function",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,10 +98,24 @@ impl Display for Value {
|
||||
Str(s) => write!(fmt, "{}", s),
|
||||
Quote(q) => write!(fmt, "[quoted value #{}]", q.index()),
|
||||
ObjPtr(o) => write!(fmt, "[object #{}]", o.slot()),
|
||||
BuiltinFn(b) => write!(fmt, "[{:?}]", b),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BuiltinFn(Rc<dyn FnMut(&mut Machine)>);
|
||||
|
||||
impl Debug for BuiltinFn {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
"builtin function at {:#x}",
|
||||
(&self.0 as *const _ as usize)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Obj
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user