User Tools

Site Tools


cs330_f2016:lab16shell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs330_f2016:lab16shell [2018/04/10 12:34]
morse
cs330_f2016:lab16shell [2018/12/04 23:30] (current)
morse
Line 5: Line 5:
  
 module CITypes # based on the CI3 interpreter module CITypes # based on the CI3 interpreter
 +
 +push!(LOAD_PATH,​ pwd())
  
 using Error using Error
Line 19: Line 21:
  
 # <​expr>​ ::= <​number>​ # <​expr>​ ::= <​number>​
-type NumNode <: AE+struct ​NumNode <: AE
   n::Real   n::Real
 end end
Line 25: Line 27:
 # <​expr>​ ::= true # <​expr>​ ::= true
 # <​expr>​ ::= false # <​expr>​ ::= false
-type BooleanNode <: AE+struct ​BooleanNode <: AE
   v::Bool   v::Bool
 end end
  
 # <​expr>​ ::= (+ <​expr>​ <​expr>​) # <​expr>​ ::= (+ <​expr>​ <​expr>​)
-type PlusNode <: AE+struct ​PlusNode <: AE
     lhs::AE     lhs::AE
     rhs::AE     rhs::AE
Line 36: Line 38:
  
 # <​expr>​ ::= (- <​expr>​ <​expr>​) # <​expr>​ ::= (- <​expr>​ <​expr>​)
-type MinusNode <: AE+struct ​MinusNode <: AE
     lhs::AE     lhs::AE
     rhs::AE     rhs::AE
Line 42: Line 44:
  
 # <​expr>​ ::= (iszero <​expr>​) # <​expr>​ ::= (iszero <​expr>​)
-type IsZeroNode <: AE+struct ​IsZeroNode <: AE
   arg::AE   arg::AE
 end end
  
 # <​expr>​ ::= (ifb <​expr>​ <​expr>​ <​expr>​) # <​expr>​ ::= (ifb <​expr>​ <​expr>​ <​expr>​)
-type IfBNode <: AE+struct ​IfBNode <: AE
     cond::AE     cond::AE
     zerobranch::​AE     zerobranch::​AE
Line 54: Line 56:
  
 # <​expr>​ ::= (with <id> <​expr>​ <​expr>​) # <​expr>​ ::= (with <id> <​expr>​ <​expr>​)
-type WithNode <: AE+struct ​WithNode <: AE
     sym::Symbol     sym::Symbol
     binding_expr::​AE     binding_expr::​AE
Line 61: Line 63:
  
 # <​expr>​ ::= <id> # <​expr>​ ::= <id>
-type VarRefNode <: AE+struct ​VarRefNode <: AE
     sym::Symbol     sym::Symbol
 end end
  
 # <​expr>​ ::= (lambda <id> : <​type>​ <​expr>​) # <​expr>​ ::= (lambda <id> : <​type>​ <​expr>​)
-type FuncDefNode <: AE+struct ​FuncDefNode <: AE
   formal_parameter::​Symbol   formal_parameter::​Symbol
   formal_type::​TypeVal   formal_type::​TypeVal
Line 73: Line 75:
  
 # <​expr>​ ::= (<​expr>​ <​expr>​) # <​expr>​ ::= (<​expr>​ <​expr>​)
-type FuncAppNode <: AE+struct ​FuncAppNode <: AE
     fun_expr::​AE     fun_expr::​AE
     arg_expr::​AE     arg_expr::​AE
Line 79: Line 81:
  
 # <​expr>​ ::= nempty # <​expr>​ ::= nempty
-type NEmptyNode <: AE+struct ​NEmptyNode <: AE
 end end
  
 # <​expr>​ ::= (nisempty <​expr>​) # <​expr>​ ::= (nisempty <​expr>​)
-type NIsEmptyNode <: AE+struct ​NIsEmptyNode <: AE
   list::AE   list::AE
 end end
  
 # <​expr>​ ::= (ncons <​expr>​ <​expr>​) # <​expr>​ ::= (ncons <​expr>​ <​expr>​)
-type NConsNode <: AE+struct ​NConsNode <: AE
   f::AE   f::AE
   r::AE   r::AE
Line 94: Line 96:
  
 # <​expr>​ ::= (nfirst <​expr>​) # <​expr>​ ::= (nfirst <​expr>​)
-type NFirstNode <: AE+struct ​NFirstNode <: AE
   list::AE   list::AE
 end end
  
 # <​expr>​ ::= (nrest <​expr>​) # <​expr>​ ::= (nrest <​expr>​)
-type NRestNode <: AE+struct ​NRestNode <: AE
   list::AE   list::AE
 end end
Line 106: Line 108:
  
 # <​type>​ ::= number # <​type>​ ::= number
-type NumType <: TypeVal+struct ​NumType <: TypeVal
 end end
  
 # <​type>​ ::= boolean # <​type>​ ::= boolean
-type BoolType <: TypeVal+struct ​BoolType <: TypeVal
 end end
  
 # <​type>​ ::= (<​type>​ : <​type>​) # <​type>​ ::= (<​type>​ : <​type>​)
-type FuncType <: TypeVal+struct ​FuncType <: TypeVal
   arg_type::​TypeVal   arg_type::​TypeVal
   result_type::​TypeVal   result_type::​TypeVal
Line 120: Line 122:
  
 # <​type>​ ::= nlist # <​type>​ ::= nlist
-type NListType <: TypeVal+struct ​NListType <: TypeVal
 end end
  
Line 128: Line 130:
 end end
  
-type EmptyTypeEnv <: TypeEnvironment+struct ​EmptyTypeEnv <: TypeEnvironment
 end end
  
-type ExtendedTypeEnv <: TypeEnvironment+struct ​ExtendedTypeEnv <: TypeEnvironment
     sym::Symbol     sym::Symbol
     val::​TypeVal     val::​TypeVal
Line 237: Line 239:
 function parse_type( t :: Array{Any} ) function parse_type( t :: Array{Any} )
   return FuncType( parse_type(t[1]),​   return FuncType( parse_type(t[1]),​
-                   parse_type(t[3]))+                  ​parse_type(t[3]))
 end end
  
Line 282: Line 284:
   && same_type( t1.result_type,​ t2.result_type ))   && same_type( t1.result_type,​ t2.result_type ))
  
-same_type{ T <: TypeVal }( t1::T, t2::T ) = true+same_type( t1::T, t2::T ) where {T <: TypeVal} ​= true
  
 same_type( t1::​TypeVal,​ t2::TypeVal ) = false same_type( t1::​TypeVal,​ t2::TypeVal ) = false
cs330_f2016/lab16shell.1523388857.txt.gz ยท Last modified: 2018/04/10 12:34 by morse