2017-04-08 11:09:25 +02:00
|
|
|
# Virtual
|
|
|
|
# Object Oriented
|
2017-08-30 16:21:13 +02:00
|
|
|
# Language
|
2017-04-08 11:09:25 +02:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# if/unless/ternary , reverse ifs (ie statement if condition), reverse whiles,
|
|
|
|
# implicit blocks, splats and multiple assigns etc
|
|
|
|
#
|
|
|
|
# Also, Vool is a typed tree, not abstract, so there is a base class Statement
|
|
|
|
# and all it's derivation that make up the syntax tree
|
|
|
|
#
|
2018-03-15 06:54:14 +01:00
|
|
|
# Also Vool has expression and statements and simple syntax. So returns must be explicit
|
|
|
|
# not everthing is just assignable, ifs can only test simple expressions etc (wip)
|
|
|
|
#
|
2017-04-08 11:09:25 +02:00
|
|
|
# This allows us to write compilers or passes of the compiler(s) as functions on the
|
|
|
|
# classes.
|
2017-08-30 16:21:13 +02:00
|
|
|
#
|
2017-04-08 11:09:25 +02:00
|
|
|
module Vool
|
|
|
|
|
|
|
|
# Base class for all statements in the tree. Derived classes correspond to known language
|
|
|
|
# constructs
|
|
|
|
#
|
|
|
|
# Compilers or compiler passes are written by implementing methods.
|
|
|
|
#
|
|
|
|
class Statement
|
|
|
|
|
2018-03-15 06:54:14 +01:00
|
|
|
# after creation vool normalizes to ensure valid syntax and simplify
|
|
|
|
# also throw errors if violation
|
2018-03-15 08:16:56 +01:00
|
|
|
def normalize()
|
|
|
|
raise self.class.name
|
2018-03-15 06:54:14 +01:00
|
|
|
end
|
|
|
|
|
2017-04-12 10:52:23 +02:00
|
|
|
def to_mom( _ )
|
|
|
|
# temporary warning to find unimplemented kids
|
|
|
|
raise "Not implemented for #{self}"
|
|
|
|
end
|
|
|
|
|
2018-07-03 21:18:19 +02:00
|
|
|
def at_depth(depth , *strings)
|
|
|
|
prefix = " " * 2 * depth
|
|
|
|
strings.collect{|str| prefix + str}.join("\n")
|
|
|
|
end
|
|
|
|
|
2018-03-15 08:16:56 +01:00
|
|
|
end
|
2017-04-08 11:09:25 +02:00
|
|
|
|
2018-03-15 08:16:56 +01:00
|
|
|
class Expression
|
2017-04-08 16:22:53 +02:00
|
|
|
|
2018-03-16 06:02:11 +01:00
|
|
|
def ct_type
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2018-03-15 08:16:56 +01:00
|
|
|
def normalize
|
|
|
|
raise "should not be normalized #{self}"
|
2017-04-08 16:22:53 +02:00
|
|
|
end
|
2018-07-05 13:02:38 +02:00
|
|
|
def to_mom(compiler)
|
2018-03-15 16:03:38 +01:00
|
|
|
raise "should not be momed #{self}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# for loading into a lot, return the "slot_definition" that can be passed to
|
|
|
|
# SlotLoad.
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-03-15 16:03:38 +01:00
|
|
|
raise "not iplemented in #{self}"
|
|
|
|
end
|
2018-03-15 06:54:14 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-04-08 11:09:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2018-06-29 21:46:00 +02:00
|
|
|
require_relative "assign_statement"
|
|
|
|
require_relative "array_statement"
|
|
|
|
require_relative "basic_values"
|
|
|
|
require_relative "block_statement"
|
|
|
|
require_relative "class_statement"
|
|
|
|
require_relative "hash_statement"
|
|
|
|
require_relative "if_statement"
|
|
|
|
require_relative "logical_statement"
|
|
|
|
require_relative "local_assignment"
|
|
|
|
require_relative "method_statement"
|
|
|
|
require_relative "return_statement"
|
|
|
|
require_relative "statements"
|
|
|
|
require_relative "send_statement"
|
|
|
|
require_relative "variables"
|
|
|
|
require_relative "while_statement"
|
|
|
|
require_relative "yield_statement"
|