Przeglądaj źródła

Crystal 0.23.1

master^2
Vitalii Elenhaupt 7 lat temu
rodzic
commit
456610769b
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: 7558EF3A4056C706
5 zmienionych plików z 14 dodań i 12 usunięć
  1. +1
    -1
      README.md
  2. +2
    -2
      src/crisp/core.cr
  3. +5
    -5
      src/crisp/evaluator.cr
  4. +4
    -2
      src/crisp/expr.cr
  5. +2
    -2
      src/crisp/printer.cr

+ 1
- 1
README.md Wyświetl plik

@ -35,7 +35,7 @@ Please see [mal test cases](https://github.com/rhysd/Crisp/tree/master/spec/cris
## Development Environment
- OS X
- Crystal 0.7.1 ~ 0.7.3 or 0.7.7 ~ 0.11.0 or 0.17.4 or 0.18.4
- Crystal 0.23.1
## License

+ 2
- 2
src/crisp/core.cr Wyświetl plik

@ -34,7 +34,7 @@ module Crisp
a = args.first.unwrap
case a
when Array
a.size as Int32
a.size.as Int32
when Nil
0
else
@ -77,7 +77,7 @@ module Crisp
end
def cons(args)
head, tail = args[0] as Crisp::Expr, args[1].unwrap
head, tail = args[0].as Crisp::Expr, args[1].unwrap
Crisp.eval_error "2nd arg of cons must be list" unless tail.is_a? Array
([head] + tail).to_crisp_value
end

+ 5
- 5
src/crisp/evaluator.cr Wyświetl plik

@ -15,11 +15,11 @@ module Crisp
-> (args : Array(Crisp::Expr)) {
new_env = Crisp::Env.new(env, binds, args)
eval(body, new_env)
} as Crisp::Func
}.as Crisp::Func
end
def eval_ast(ast, env)
return ast.map{|n| eval(n, env) as Crisp::Expr} if ast.is_a? Array
return ast.map{|n| eval(n, env).as Crisp::Expr} if ast.is_a? Array
val = ast.unwrap
@ -94,8 +94,8 @@ module Crisp
while macro_call?(ast, env)
# Already checked in macro_call?
list = ast.unwrap as Crisp::List
func_sym = list[0].unwrap as Crisp::Symbol
list = ast.unwrap.as Crisp::List
func_sym = list[0].unwrap.as Crisp::Symbol
func = env.get(func_sym.str).unwrap
case func
@ -113,7 +113,7 @@ module Crisp
macro invoke_list(l, env)
f = eval({{l}}.first, {{env}}).unwrap
args = eval_ast({{l}}[1..-1], {{env}}) as Array
args = eval_ast({{l}}[1..-1], {{env}}).as Array
case f
when Crisp::Closure

+ 4
- 2
src/crisp/expr.cr Wyświetl plik

@ -13,6 +13,8 @@ module Crisp
end
end
class Expr; end
class List < Array(Expr)
end
@ -34,7 +36,7 @@ module Crisp
class Closure
property :ast, :params, :env, :fn
def initialize(@ast : Expr, @params : ">List | Vector, @env : Env, @fn : Func)
def initialize(@ast : Expr, @params : b">Array(Crisp::Expr), @env : Env, @fn : Func)
end
end
@ -46,7 +48,7 @@ module Crisp
def initialize(@val : Type)
@is_macro = false
@meta = nil as Expr?
@meta = nil.as Expr?
end
def initialize(other : Expr)

+ 2
- 2
src/crisp/printer.cr Wyświetl plik

@ -10,8 +10,8 @@ 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| print(v) as String}.join(" ")})"
when Crisp::Vector then "[#{value.map{|v| print(v) 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 "<function>"
when Crisp::Closure then "<closure>"

Ładowanie…
Anuluj
Zapisz