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
VERSION | = | '1.0.0-beta-5' | ||
METHOD_MAP | = | { :| => "or", :& => "and", :^ => "xor", } | Function definition |
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. |
(Primary) Front-end utility method for translating an entire class. Has special error handlers that convert errors into C++ comments (//…).
Provides a (rather bogus) preamble. Put your includes and defines here. It really should be made to be much more clean and extendable.
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.
Global variables, evil but necessary.
TODO: get the case statement out by using proper bootstrap in genv.
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.
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?
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?