use std::collections::HashMap;
use gc::Gc;
use context::InterpreterContext;
use symbol::Symbol;
use value::Value;
macro_rules! define_primitives {
($($(#[doc = $m:expr])* ($prim:ident : $name:expr))*) => {
#[derive(Clone, Debug)]
pub struct Primitives<C: 'static + InterpreterContext> {
$($(#[doc = $m])* pub $prim: C::BuiltinFunction,)*
}
impl<C: 'static + InterpreterContext> Into<HashMap<Symbol, Gc<Value<C>>>> for Primitives<C> {
fn into(self) -> HashMap<Symbol, Gc<Value<C>>> {
let fields = vec![
$(($name.into(), self.$prim),)*
];
fields.into_iter()
.map(|(k, v)| (k, Gc::new(Value::BuiltinFunction(k, v, C::ValueMeta::default()))))
.collect()
}
}
}
}
define_primitives! {
(apply: "apply")
(atomic_word_cas: "atomic-word.cas")
(atomic_word_load: "atomic-word.load")
(atomic_word_new: "atomic-word")
(atomic_word_store: "atomic-word.store")
(byte_of_fixnum: "byte<-fixnum")
(bytes_of_string: "bytes<-string")
(car: "car")
(cdr: "cdr")
(compare: "compare")
(concat_strings: "concat-strings")
(cons: "cons")
(debug: "debug")
(eq: "eq")
(exit_with: "exit-with")
(fixnum_of_byte: "fixnum<-byte")
(gensym: "gensym")
(is_byte: "byte?")
(is_cons: "cons?")
(is_fixnum: "fixnum?")
(is_nil: "nil?")
(is_object: "object?")
(is_string: "string?")
(is_symbol: "symbol?")
(is_vector: "vector?")
(list_of_vector: "list<-vector")
(make_vector: "make-vector")
(object_data_len: "object-data-len")
(object_get_data: "object-get-data")
(object_get_func: "object-get-func")
(object_has_func: "object-has-func?")
(object_seal: "object-seal")
(object_unseal: "object-unseal")
(op_add: "+/2")
(op_cmp: "<>")
(op_div: "//2")
(op_equ: "=")
(op_mod: "mod/2")
(op_mul: "*/2")
(op_sub: "-/2")
(panic: "panic")
(string_of_symbol: "string<-symbol")
(symbol_of_string: "symbol<-string")
(show_primitive: "show-primitive")
(unwind_protect: "unwind-protect")
(vector_of_list: "vector<-list")
(write_bytes: "write-bytes")
}