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

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

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

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

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

Lazy initializer for the composite RubytoC translator chain.

Public Instance methods

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

Logical And. Nothing exciting here

Arglist is used by call arg lists.

Argument List including variable types.

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

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

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.

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

Iterator variables.

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

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

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

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

TODO: remove / rewrite?

False. Pretty straightforward.

Global variables, evil but necessary.

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

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

Instance Variable Assignment

Conditional statements

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

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.

Instance Variable Access

Assignment to a local variable.

TODO: figure out array issues and clean up.

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?

Local variable

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

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

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

Logical or. Nothing exciting here

Return statement. Nothing exciting here

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?

Strings. woot.

Truth… what is truth?

While block. Nothing exciting here.

[Validate]