diff --git a/src/crisp/core.cr b/src/crisp/core.cr index 5ad38a3..aaaa01c 100644 --- a/src/crisp/core.cr +++ b/src/crisp/core.cr @@ -43,7 +43,7 @@ module Crisp end def pr_str(args) - args.map{|a| Priter.new.print(a)}.join(" ") + args.map{|a| Printer.new.print(a)}.join(" ") end def str(args) diff --git a/src/crisp/error.cr b/src/crisp/error.cr index b9a2a49..5d02374 100644 --- a/src/crisp/error.cr +++ b/src/crisp/error.cr @@ -1,4 +1,6 @@ module Crisp + extend self + class ParseException < Exception end diff --git a/src/crisp/interpreter.cr b/src/crisp/interpreter.cr index c9ad86c..93931a6 100644 --- a/src/crisp/interpreter.cr +++ b/src/crisp/interpreter.cr @@ -14,7 +14,7 @@ require "./error" module Crisp class Interpreter - def initialize(args) + def initialize(args = nil) @env = Crisp::Env.new Crisp::NameSpace.each{|k,v| @curent_env.set(k, Crisp::Type.new(v))} diff --git a/src/crisp/printer.cr b/src/crisp/printer.cr index 237afea..1b0716e 100644 --- a/src/crisp/printer.cr +++ b/src/crisp/printer.cr @@ -10,14 +10,14 @@ module Crisp when Nil then "nil" when Bool then value.to_s when Int32 then value.to_s - when Crisp::List then "(#{value.map{|v| pr_str(v, @print_readably) as String}.join(" ")})" - when Crisp::Vector then "[#{value.map{|v| pr_str(v, @print_readably) as String}.join(" ")}]" + when Crisp::List then "(#{value.map{|v| print(v) as String}.join(" ")})" + when Crisp::Vector then "[#{value.map{|v| print(v) as String}.join(" ")}]" when Crisp::Symbol then value.str.to_s when Crisp::Func then "" when Crisp::Closure then "" when Crisp::HashMap # step1_read_print.cr requires specifying type - "{#{value.map{|k, v| "#{pr_str(k, @print_readably)} #{pr_str(v, @print_readably)}" as String}.join(" ")}}" + "{#{value.map{|k, v| "#{print(k)} #{print(v)}"}.join(" ")}}" when String case when value.empty?() @@ -28,14 +28,14 @@ module Crisp @print_readably ? value.inspect : value end when Crisp::Atom - "(atom #{pr_str(value.val, @print_readably)})" + "(atom #{print(value.val)})" else raise "invalid CrispType: #{value.to_s}" end end def print(t : Crisp::Type) - print(t.unwrap, @print_readably) + (t.macro? ? " (macro)" : "") + print(t.unwrap) + (t.macro? ? " (macro)" : "") end end end