Browse Source

tiny fixes

- argument of Crisp::Interpreter#initialize
- fix typo: Priter -> Printer
- fix Crisp::Printer#print
- add missing `extend self`
master
rhysd 9 years ago
parent
commit
7489d12d08
4 changed files with 9 additions and 7 deletions
  1. +1
    -1
      src/crisp/core.cr
  2. +2
    -0
      src/crisp/error.cr
  3. +1
    -1
      src/crisp/interpreter.cr
  4. +5
    -5
      src/crisp/printer.cr

+ 1
- 1
src/crisp/core.cr View File

@ -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)

+ 2
- 0
src/crisp/error.cr View File

@ -1,4 +1,6 @@
module Crisp
extend self
class ParseException < Exception
end

+ 1
- 1
src/crisp/interpreter.cr View File

@ -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))}

+ 5
- 5
src/crisp/printer.cr View File

@ -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| b">print(v) as String}.join(" ")})"
when Crisp::Vector then "[#{value.map{|v| b">print(v) as String}.join(" ")}]"
when Crisp::Symbol then value.str.to_s
when Crisp::Func then "<function>"
when Crisp::Closure then "<closure>"
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| "#{b">print(k)} #{b">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 #{b">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

Loading…
Cancel
Save