Pārlūkot izejas kodu

Crystal 0.23.1

master^2
Vitalii Elenhaupt pirms 7 gadiem
vecāks
revīzija
456610769b
Šim parakstam datu bāzē netika atrasta zināma atslēga GPG atslēgas ID: 7558EF3A4056C706
5 mainītis faili ar 14 papildinājumiem un 12 dzēšanām
  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 Parādīt failu

@ -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 Parādīt failu

@ -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 Parādīt failu

@ -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 Parādīt failu

@ -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 Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt