Class: TypeChecker

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

bootstrap process process_and process_arglist process_args process_array process_attrasgn process_begin process_block process_block_arg process_block_pass process_call process_class process_colon2 process_colon3 process_const process_cvar process_cvasgn process_dasgn_curr process_defined process_defn process_dstr process_dvar process_ensure process_false process_gasgn process_gvar process_hash process_iasgn process_if process_iter process_ivar process_lasgn process_lit process_lvar process_nil process_not process_op_asgn_or process_or process_resbody process_rescue process_return process_scope process_self process_splat process_str process_super process_true process_while process_yield translate translate

### Attributes

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

### Public Class methods

process(klass, method=nil)

Yet another utility method - this time the official one, although we don‘t like the implementation at this stage.

translate(klass, method = nil)

Utility method that translates a class and optional method name to a type checked sexp. Mostly used for testing.

### Public Instance methods

bootstrap()

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.

process_and(exp)

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

process_arglist(exp)

Arg list stuff

process_args(exp)

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

process_array(exp)

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

process_attrasgn(exp)

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

process_begin(exp)

Begin processes the body, then returns an untyped sexp.

process_block(exp)

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

process_block_arg(exp)

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

process_block_pass(exp)

Block pass is currently unsupported. Returns a typed sexp.

process_call(exp)

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.

process_class(exp)

Class adds the class name to the global environment, processes all of the methods in the class. Returns a zclass-typed sexp.

process_colon2(exp)

Colon 2 returns a zclass-typed sexp

process_colon3(exp)

Colon 3 returns a zclass-typed sexp

process_const(exp)

Const looks up the type of the const in the global environment, then returns a sexp of that type.

Const is partially unsupported.

process_cvar(exp)

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

process_cvasgn(exp)

Class variable assignment

process_dasgn_curr(exp)

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

process_defined(exp)

Defined? processes the body, then returns a bool-typed sexp.

process_defn(exp)

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.

process_dstr(exp)

Dynamic string processes all the elements of the body and returns a string-typed sexp.

process_dvar(exp)

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

process_ensure(exp)

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

process_false(exp)

False returns a bool-typed sexp.

process_gasgn(exp)

Global variable assignment gets stored in the global assignment.

process_gvar(exp)

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.

process_hash(exp)

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

process_iasgn(exp)

Instance variable assignment is currently unsupported. Does no unification and returns an untyped sexp

process_if(exp)

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.

process_iter(exp)

Iter unifies the dynamic variables against the call args (dynamic variables are used in the iter body) and returns a void-typed sexp.

process_ivar(exp)

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

process_lasgn(exp)

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.

process_lit(exp)

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

process_lvar(exp)

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

process_nil(exp)

Nil returns a value-typed sexp.

process_not(exp)

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

process_op_asgn_or(exp)

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

process_or(exp)

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

process_resbody(exp)

Rescue body returns an unknown-typed sexp.

process_rescue(exp)

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

process_return(exp)

Return returns a void typed sexp.

process_scope(exp)

Scope returns a void-typed sexp.

process_self(exp)

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

process_splat(exp)

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

process_str(exp)

String literal returns a string-typed sexp.

process_super(exp)

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

process_true(exp)

True returns a bool-typed sexp.

process_while(exp)

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

process_yield(exp)

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

translate(klass, method = nil)

[Validate]