Class | TypeChecker |
In: |
lib/type_checker.rb
|
Parent: | SexpProcessor |
TypeChecker inferences types for sexps using type unification.
TypeChecker expects sexps rewritten with Rewriter, and outputs TypedSexps.
Nodes marked as ‘unsupported’ do not do correct type-checking of all the pieces of the node. They generate possibly incorrect output, that is all.
env | [R] | Environment containing local variables |
functions | [R] | Function table |
genv | [R] | The global environment contains global variables and constants. |
Yet another utility method - this time the official one, although we don‘t like the implementation at this stage.
Utility method that translates a class and optional method name to a type checked sexp. Mostly used for testing.
Args list adds each variable to the local variable table with unknown types, then returns an untyped args list of name/type pairs.
Call unifies the actual function paramaters against the formal function paramaters, if a function type signature already exists in the function table. If no type signature for the function name exists, the function is added to the function list.
Returns a sexp returned to the type of the function return value, or unknown if it has not yet been determined.
Class adds the class name to the global environment, processes all of the methods in the class. Returns a zclass-typed sexp.
Const looks up the type of the const in the global environment, then returns a sexp of that type.
Const is partially unsupported.
Dynamic variable assignment adds the unknown type to the local environment then returns an unknown-typed sexp.
Defn adds the formal argument types to the local environment and attempts to unify itself against the function table. If no function exists in the function table, defn adds itself.
Defn returns a function-typed sexp.
Dynamic variable lookup looks up the variable in the local environment and returns a sexp of that type.
Global variables get looked up in the global environment. If they are found, a sexp of that type is returned, otherwise the unknown type is added to the global environment and an unknown-typed sexp is returned.
Instance variable assignment is currently unsupported. Does no unification and returns an untyped sexp
If unifies the condition against the bool type, then unifies the return types of the then and else expressions against each other. Returns a sexp typed the same as the then and else expressions.
Iter unifies the dynamic variables against the call args (dynamic variables are used in the iter body) and returns a void-typed sexp.
Local variable assignment unifies the variable type from the environment with the assignment expression, and returns a sexp of that type. If there is no local variable in the environment, one is added with the type of the assignment expression and a sexp of that type is returned.