diff options
-rw-r--r-- | src/parse/parsetree.rs | 1 | ||||
-rw-r--r-- | src/sexp/display.rs | 2 | ||||
-rw-r--r-- | src/sexp/mod.rs | 2 | ||||
-rw-r--r-- | src/sexp/step.rs | 6 | ||||
-rw-r--r-- | src/type/check.rs | 1 |
5 files changed, 12 insertions, 0 deletions
diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs index 75758dc..28e5044 100644 --- a/src/parse/parsetree.rs +++ b/src/parse/parsetree.rs @@ -113,6 +113,7 @@ fn tokens_to_ast_inner( Some(Sym(s)) if s == "false" => Ok(Atom(False)), Some(Sym(s)) if s == "quote" => Ok(Atom(Quote)), Some(Sym(s)) if s == "vector" => Ok(Atom(Vector)), + Some(Sym(s)) if s == "print" => Ok(Atom(Print)), Some(Sym(s)) if s == "let" => Ok(Atom(Let)), Some(Sym(s)) => Ok(Atom(Var(s))), Some(ParClose) => break, diff --git a/src/sexp/display.rs b/src/sexp/display.rs index c3db144..a978f61 100644 --- a/src/sexp/display.rs +++ b/src/sexp/display.rs @@ -27,6 +27,7 @@ impl fmt::Display for SLeaf { Var(s) => s.to_string(), Quote => "quote".to_string(), Vector => "vector".to_string(), + Print => "print".to_string(), Let => "let".to_string(), Nil => "()".to_string(), }) @@ -40,6 +41,7 @@ impl fmt::Display for SExp { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Atom(leaf) => write!(f, "{}", leaf.to_string()), + SCons(a, b) if **b == Atom(Nil) => (*a).fmt(f), SCons(a, b) => write!( f, diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs index 7aa517b..296553f 100644 --- a/src/sexp/mod.rs +++ b/src/sexp/mod.rs @@ -33,6 +33,8 @@ pub enum SLeaf { Let, + Print, + Int(i32), True, False, diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 816582c..11df257 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -521,6 +521,12 @@ impl SExp { } }, + // Print + SCons(op, l) if *op == Atom(Print) => { + println!("{}", *l); + Ok(Atom(Nil)) + }, + // t is value // ---------- // t -> t diff --git a/src/type/check.rs b/src/type/check.rs index e536ce7..77420e3 100644 --- a/src/type/check.rs +++ b/src/type/check.rs @@ -194,6 +194,7 @@ impl SExp { List(vec![VecType, vecof(vt("T"))]) )), Atom(Let) => Ok(LetType), + Atom(Print) => Ok(arr(vt("_"), List(vec![]))), SCons(op, l) => { |