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.

Methods

Attributes

env  [R]  Environment containing local variables
functions  [R]  Function table
genv  [R]  The global environment contains global variables and constants.

Public Class methods

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.

Public Instance methods

Runs the bootstrap stage, which runs over +$bootstrap+ and converts each entry into a full fledged method signature registered in the type checker. This is where the basic knowledge for lower level types (in C) comes from.

Logical and unifies its two arguments, then returns a bool sexp.

Arg list stuff

Args list adds each variable to the local variable table with unknown types, then returns an untyped args list of name/type pairs.

Array processes each item in the array, then returns an untyped sexp.

Attrasgn processes its rhs and lhs, then returns an untyped sexp.

Begin processes the body, then returns an untyped sexp.

Block processes each sexp in the block, then returns an unknown-typed sexp.

Block arg is currently unsupported. Returns an unmentionably-typed sexp.

Block pass is currently unsupported. Returns a typed sexp.

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.

Colon 2 returns a zclass-typed sexp

Colon 3 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.

Class variables are currently unsupported. Returns an unknown-typed sexp.

Class variable assignment

Dynamic variable assignment adds the unknown type to the local environment then returns an unknown-typed sexp.

Defined? processes the body, then returns a bool-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 string processes all the elements of the body and returns a string-typed sexp.

Dynamic variable lookup looks up the variable in the local environment and returns a sexp of that type.

Ensure processes the res and the ensure, and returns an untyped sexp.

False returns a bool-typed sexp.

Global variable assignment gets stored in the global assignment.

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.

Hash (inline hashes) are not supported. Returns an unmentionably-typed sexp.

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.

Instance variables are currently unsupported. Returns an unknown-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.

Literal values return a sexp typed to match the literal expression.

Local variables get looked up in the local environment and a sexp of that type is returned.

Nil returns a value-typed sexp.

Not unifies the type of its expression against bool, then returns a bool-typed sexp.

||= operator is currently unsupported. Returns an untyped sexp.

Or unifies the left and right hand sides with bool, then returns a bool-typed sexp.

Rescue body returns an unknown-typed sexp.

Rescue unifies the begin, rescue and ensure types, and returns an untyped sexp.

Return returns a void typed sexp.

Scope returns a void-typed sexp.

Self is currently unsupported. Returns an unknown-typed sexp.

Splat is currently unsupported. Returns an unknown-typed sexp.

String literal returns a string-typed sexp.

Super is currently unsupported. Returns an unknown-typed sexp.

True returns a bool-typed sexp.

While unifies the condition with bool, then returns an untyped sexp.

Yield is currently unsupported. Returns a unmentionably-typed sexp.

[Validate]