X-Git-Url: http://git.hcoop.net/jackhill/mal.git/blobdiff_plain/09fb509eb44a93a0e18f41a0c676950f35230774..56be4ef0ee1b601b126f2db9c83b2ab1238f362a:/crystal/types.cr diff --git a/crystal/types.cr b/crystal/types.cr index 56203307..af61cb7f 100644 --- a/crystal/types.cr +++ b/crystal/types.cr @@ -20,6 +20,16 @@ module Mal class HashMap < Hash(String, Type) end + class Atom + property :val + def initialize(@val) + end + + def ==(rhs : Atom) + @val == rhs.val + end + end + class Closure property :ast, :params, :env, :fn def initialize(@ast, @params, @env, @fn) @@ -28,17 +38,22 @@ module Mal class Type alias Func = (Array(Type) -> Type) - alias ValueType = Nil | Bool | Int32 | String | Symbol | List | Vector | HashMap | Func | Closure + alias ValueType = Nil | Bool | Int32 | String | Symbol | List | Vector | HashMap | Func | Closure | Atom - property :is_macro + is_macro :: Bool + meta :: Type + + property :is_macro, :meta def initialize(@val : ValueType) @is_macro = false + @meta = nil end def initialize(other : Type) @val = other.unwrap - @is_macro = false + @is_macro = other.is_macro + @meta = other.meta end def unwrap @@ -53,6 +68,13 @@ module Mal pr_str(self) end + def dup + Type.new(@val).tap do |t| + t.is_macro = @is_macro + t.meta = @meta + end + end + def ==(other : Type) @val == other.unwrap end