File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ pub use self::_divide_::*;
27
27
28
28
pub ( crate ) mod _multiply_;
29
29
pub use self :: _multiply_:: * ;
30
+
31
+ pub ( crate ) mod ns;
32
+ pub use self :: ns:: * ;
33
+
30
34
//
31
35
// This module will hold core function and macro primitives that aren't special cases
32
36
// (like the quote macro, or let), and can't be implemented in clojure itself
@@ -113,7 +117,7 @@ impl EvalFn {
113
117
EvalFn {
114
118
enclosing_environment,
115
119
}
116
- }
120
+ }
117
121
}
118
122
impl ToValue for EvalFn {
119
123
fn to_value ( & self ) -> Value {
Original file line number Diff line number Diff line change
1
+ use crate :: ifn:: IFn ;
2
+ use crate :: value:: { ToValue , Value } ;
3
+ use crate :: type_tag:: TypeTag ;
4
+ use crate :: environment:: Environment ;
5
+ use std:: rc:: Rc ;
6
+
7
+ use crate :: error_message;
8
+
9
+ #[ derive( Debug , Clone ) ]
10
+ pub struct NsMacro {
11
+ enclosing_environment : Rc < Environment >
12
+ }
13
+ impl NsMacro {
14
+ pub fn new ( enclosing_environment : Rc < Environment > ) -> NsMacro {
15
+ NsMacro {
16
+ enclosing_environment,
17
+ }
18
+ }
19
+ }
20
+ impl ToValue for NsMacro {
21
+ fn to_value ( & self ) -> Value {
22
+ Value :: Macro ( Rc :: new ( self . clone ( ) ) )
23
+ }
24
+ }
25
+ impl IFn for NsMacro {
26
+ fn invoke ( & self , args : Vec < Rc < Value > > ) -> Value {
27
+ if args. len ( ) != 1 {
28
+ return error_message:: wrong_arg_count ( 1 , args. len ( ) ) ;
29
+ }
30
+
31
+ let namespace = args. get ( 0 ) . unwrap ( ) ;
32
+ match & * * namespace {
33
+ Value :: Symbol ( sym) => {
34
+ self . enclosing_environment . change_namespace ( sym. clone ( ) ) ;
35
+ Value :: Nil
36
+ } ,
37
+ _ => error_message:: type_mismatch ( TypeTag :: Symbol , & * * namespace)
38
+ }
39
+
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments