Class: RubyToAnsiC

Class | RubyToAnsiC
In: | lib/ruby_to_ansi_c.rb
Parent: | SexpProcessor

The whole point of this project! RubyToC is an actually very simple SexpProcessor that does the final conversion from Sexp to C code. This class has more unsupported nodes than any other (on purpose—we‘d like TypeChecker and friends to be as generally useful as possible), and as a result, supports a very small subset of ruby.

NOT SUPPORTED: (keep in sync w/ initialize)

:begin, :block_arg, :case, :dstr, :rescue, :self, :super, :when

### Methods

c_type preamble process_and process_arglist process_args process_array process_block process_call process_class process_const process_cvar process_dasgn_curr process_defn process_dummy process_dvar process_error process_false 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_return process_scope process_str process_true process_while translate translate_all_of translator

### Constants

VERSION | = | '1.0.0-beta-5'
METHOD_MAP | = | { :| => "or", :& => "and", :^ => "xor", } |  | Function definition

### Attributes

env | [R] | Provides access to the variable scope.
prototypes | [R] | Provides access to the method signature prototypes that are needed at the top of the C file.

### Public Class methods

c_type(typ)

Returns a textual version of a C type that corresponds to a sexp type.

translate(klass, method=nil)

Front-end utility method for translating an entire class or a specific method from that class.

translate_all_of(klass)

(Primary) Front-end utility method for translating an entire class. Has special error handlers that convert errors into C++ comments (//…).

translator()

Lazy initializer for the composite RubytoC translator chain.

### Public Instance methods

preamble()

Provides a (rather bogus) preamble. Put your includes and defines here. It really should be made to be much more clean and extendable.

process_and(exp)

Logical And. Nothing exciting here

process_arglist(exp)

Arglist is used by call arg lists.

process_args(exp)

Argument List including variable types.

process_array(exp)

Array is used as call arg lists and as initializers for variables.

process_block(exp)

Block doesn‘t have an analog in C, except maybe as a functions‘s outer braces.

process_call(exp)

Call, both unary and binary operators and regular function calls.

TODO: This needs a lot of work. We‘ve cheated with the case statement below. We need a real function signature lookup like we have in R2CRewriter.

process_class(exp)

DOC

process_const(exp)
process_cvar(exp)

Constants, must be defined in the global env.

TODO: This will cause a lot of errors with the built in classes until we add them to the bootstrap phase. HACK: what is going on here??? We have NO tests for this node

process_dasgn_curr(exp)

Iterator variables.

TODO: check to see if this is the least bit relevant anymore. We might have rewritten them all.

process_defn(exp)
process_dummy(exp)

Generic handler. Ignore me, I‘m not here.

TODO: nuke dummy nodes by using new SexpProcessor rewrite rules.

process_dvar(exp)

Dynamic variables, should be the same as lvar at this stage.

TODO: remove / rewrite?

process_error(exp)

DOC

process_false(exp)

False. Pretty straightforward.

process_gvar(exp)

Global variables, evil but necessary.

TODO: get the case statement out by using proper bootstrap in genv.

process_hash(exp)

Hash values, currently unsupported, but plans are in the works.

process_iasgn(exp)

Instance Variable Assignment

process_if(exp)

Conditional statements

TODO: implementation is ugly as hell… PLEASE try to clean

process_iter(exp)

Iterators for loops. After rewriter nearly all iter nodes should be able to be interpreted as a for loop. If not, then you are doing something not supported by C in the first place.

process_ivar(exp)

Instance Variable Access

process_lasgn(exp)

Assignment to a local variable.

TODO: figure out array issues and clean up.

process_lit(exp)

Literals, numbers for the most part. Will probably cause compilation errors if you try to translate bignums and other values that don‘t have analogs in the C world. Sensing a pattern?

process_lvar(exp)

Local variable

process_nil(exp)

Nil, currently ruby nil, not C NULL (0).

process_not(exp)

Nil, currently ruby nil, not C NULL (0).

process_op_asgn_or(exp)

Or assignment (||=), currently unsupported, but only because of laziness.

process_or(exp)

Logical or. Nothing exciting here

process_return(exp)

Return statement. Nothing exciting here

process_scope(exp)

Scope has no real equivalent in C-land, except that like process_block above. We put variable declarations here before the body and use this as our opportunity to open a variable scope. Crafty, no?

process_str(exp)

Strings. woot.

process_true(exp)

Truth… what is truth?

process_while(exp)

While block. Nothing exciting here.

[Validate]