first stab at moms if
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# Virtual
|
||||
# Object Oriented
|
||||
# Langiage
|
||||
# Language
|
||||
#
|
||||
# VOOL is the abstraction of ruby, ruby minus some of the fluff
|
||||
# fluff is generally what makes ruby nice to use, like 3 ways to achieve the same thing
|
||||
@ -12,6 +12,7 @@
|
||||
#
|
||||
# This allows us to write compilers or passes of the compiler(s) as functions on the
|
||||
# classes.
|
||||
#
|
||||
module Vool
|
||||
|
||||
# Base class for all statements in the tree. Derived classes correspond to known language
|
||||
|
@ -2,13 +2,32 @@ module Vool
|
||||
class IfStatement < Statement
|
||||
attr_reader :condition , :if_true , :if_false
|
||||
|
||||
def initialize( cond , if_true , if_false = [])
|
||||
def initialize( cond , if_true , if_false = nil)
|
||||
@condition = cond
|
||||
@if_true = if_true
|
||||
@if_false = if_false
|
||||
simplify_condition
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
if_true = @if_true.to_mom( method )
|
||||
if_false = @if_false.to_mom( method )
|
||||
make_condition( if_true , if_false )
|
||||
end
|
||||
|
||||
# conditions in ruby are almost always method sends (as even comparisons are)
|
||||
# currently we just deal with straight up values which get tested
|
||||
# for the funny ruby logic (everything but false and nil is true)
|
||||
def make_condition( if_true , if_false )
|
||||
merge = Mom::Noop.new(:merge)
|
||||
if_true = [if_true] unless if_true.is_a?(Array)
|
||||
if_true << Mom::Jump.new(merge)
|
||||
if_false = [if_false] unless if_false.is_a?(Array)
|
||||
if_false << Mom::Jump.new(merge)
|
||||
check = Mom::TruthCheck.new( @condition , if_true , if_false , merge)
|
||||
[ check , if_true , if_false , merge ]
|
||||
end
|
||||
|
||||
def collect(arr)
|
||||
@if_true.collect(arr)
|
||||
@if_false.collect(arr)
|
||||
|
@ -2,7 +2,7 @@ require_relative "ruby_compiler"
|
||||
|
||||
module Vool
|
||||
class VoolCompiler
|
||||
|
||||
|
||||
def self.compile( ruby_source )
|
||||
statements = RubyCompiler.compile( ruby_source )
|
||||
statements.create_objects
|
||||
|
Reference in New Issue
Block a user