move vool statements into own directory

also tests for guard to work
This commit is contained in:
Torsten Ruger
2017-04-06 19:11:11 +03:00
parent 3fe286b5ed
commit db8f99409b
30 changed files with 29 additions and 27 deletions

View File

@ -0,0 +1,13 @@
module Vool
class ArrayStatement
attr_reader :values
def initialize( values )
@values = values
end
def length
@values.length
end
end
end

View File

@ -0,0 +1,12 @@
module Vool
class Assignment < Statement
attr_reader :name , :value
def initialize(name , value )
@name , @value = name , value
end
end
class LocalAssignment < Assignment
end
class InstanceAssignment < Assignment
end
end

View File

@ -0,0 +1,32 @@
module Vool
class IntegerStatement < Statement
attr_reader :value
def initialize(value)
@value = value
end
end
class FloatStatement < Statement
attr_reader :value
def initialize(value)
@value = value
end
end
class TrueStatement < Statement
end
class FalseStatement < Statement
end
class NilStatement < Statement
end
class SelfStatement < Statement
end
class SuperStatement < Statement
end
class StringStatement < Statement
attr_reader :value
def initialize(value)
@value = value
end
end
class SymbolStatement < StringStatement
end
end

View File

@ -0,0 +1,10 @@
module Vool
class ClassStatement
attr_reader :name, :super_class_name , :body
def initialize( name , supe , body)
@name , @super_class_name , @body = name , supe , body
end
end
end

View File

@ -0,0 +1,17 @@
module Vool
class HashStatement
attr_reader :hash
def initialize( )
@hash = {}
end
def add(key , value)
@hash[key] = value
end
def length
@hash.length
end
end
end

View File

@ -0,0 +1,25 @@
module Vool
class IfStatement < Statement
attr_reader :condition , :if_true , :if_false
def initialize( cond , if_true , if_false = [])
@condition = cond
@if_true = if_true
@if_false = if_false
simplify_condition
end
def simplify_condition
return unless @condition.is_a?(ScopeStatement)
@condition = @condition.first if @condition.single?
end
def has_false?
@if_false != nil
end
def has_true?
@if_true != nil
end
end
end

View File

@ -0,0 +1,11 @@
module Vool
# Logical Statements are guaranteed to return boolean
# either :and or :or, which may be written as && and ||
class LogicalStatement < Statement
attr_reader :name , :left , :right
def initialize(name , left , right)
@name , @left , @right = name , left , right
end
end
end

View File

@ -0,0 +1,10 @@
module Vool
class MethodStatement
attr_reader :name, :args , :body
def initialize( name , args , body)
@name , @args , @body = name , args , (body || [])
end
end
end

View File

@ -0,0 +1,9 @@
module Vool
class ReturnStatement < Statement
attr_reader :return_value
def initialize(value)
@return_value = value
end
end
end

View File

@ -0,0 +1,9 @@
module Vool
class SendStatement < Statement
attr_reader :name , :receiver , :arguments
def initialize(name , receiver , arguments = [])
@name , @receiver , @arguments = name , receiver , arguments
end
end
end

View File

@ -0,0 +1,23 @@
module Vool
class Statements < Statement
attr_reader :statements
def initialize(statements)
@statements = statements
end
def empty?
@statements.empty?
end
def single?
@statements.length == 1
end
def first
@statements.first
end
def length
@statements.length
end
end
class ScopeStatement < Statements
end
end

View File

@ -0,0 +1,24 @@
module Vool
module Named
attr_reader :name
def initialize name
@name = name
end
end
class LocalVariable < Statement
include Named
end
class InstanceVariable < Statement
include Named
end
class ClassVariable < Statement
include Named
end
class ModuleName < Statement
include Named
end
end

View File

@ -0,0 +1,17 @@
module Vool
class WhileStatement < Statement
attr_reader :condition , :statements
def initialize( condition , statements )
@condition = condition
@statements = statements
simplify_condition
end
def simplify_condition
return unless @condition.is_a?(ScopeStatement)
@condition = @condition.first if @condition.single?
end
end
end