From 456610769b4ddb1b185400f174d6ce915055c16f Mon Sep 17 00:00:00 2001 From: Vitalii Elenhaupt Date: Tue, 24 Oct 2017 17:41:53 +0300 Subject: [PATCH] Crystal 0.23.1 --- README.md | 2 +- src/crisp/core.cr | 4 ++-- src/crisp/evaluator.cr | 10 +++++----- src/crisp/expr.cr | 6 ++++-- src/crisp/printer.cr | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f07f9e6..9267eaa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/crisp/core.cr b/src/crisp/core.cr index e21b626..7e9dbf9 100644 --- a/src/crisp/core.cr +++ b/src/crisp/core.cr @@ -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 diff --git a/src/crisp/evaluator.cr b/src/crisp/evaluator.cr index c2aafb5..bcd1f68 100644 --- a/src/crisp/evaluator.cr +++ b/src/crisp/evaluator.cr @@ -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 diff --git a/src/crisp/expr.cr b/src/crisp/expr.cr index eccf59b..9be1dfb 100644 --- a/src/crisp/expr.cr +++ b/src/crisp/expr.cr @@ -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 : 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) diff --git a/src/crisp/printer.cr b/src/crisp/printer.cr index 15311d5..88ba11b 100644 --- a/src/crisp/printer.cr +++ b/src/crisp/printer.cr @@ -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 "" when Crisp::Closure then ""