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
|
|
|
#
|
2019-08-19 10:33:12 +02:00
|
|
|
# VOOL is the abstraction of ruby, ruby minusthe fluff
|
2017-04-08 11:09:25 +02:00
|
|
|
# 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
|
|
|
|
#
|
2019-08-19 10:33:12 +02:00
|
|
|
# Also Vool has expression and statements, revealing that age old dichotomy of code and
|
|
|
|
# data. Statements represent code whereas Expressions resolve to data.
|
|
|
|
# (in ruby there are no pure statements, everthing resolves to data)
|
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
|
|
|
|
#
|
2019-08-19 10:33:12 +02:00
|
|
|
# Basically Statements represent code, generally speaking code "does things".
|
|
|
|
# But Vool distinguishes Expressions (see below), that represent data, and as such
|
|
|
|
# don't do things themselves, rather passively participate in being pushed around
|
2017-04-08 11:09:25 +02:00
|
|
|
class Statement
|
|
|
|
|
2017-04-12 10:52:23 +02:00
|
|
|
def to_mom( _ )
|
|
|
|
# temporary warning to find unimplemented kids
|
|
|
|
raise "Not implemented for #{self}"
|
|
|
|
end
|
|
|
|
|
2019-09-19 19:48:21 +02:00
|
|
|
def at_depth(depth , lines)
|
2018-07-03 21:18:19 +02:00
|
|
|
prefix = " " * 2 * depth
|
2019-09-19 19:48:21 +02:00
|
|
|
strings = lines.split("\n")
|
2018-07-03 21:18:19 +02:00
|
|
|
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
|
|
|
|
2019-08-19 10:33:12 +02:00
|
|
|
# An Expression is a Statement that represents data. ie variables constants
|
|
|
|
# (see basic_values) , but alos classes, methods and lambdas
|
|
|
|
class Expression < Statement
|
|
|
|
|
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
|
|
|
end
|
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-03-15 16:03:38 +01:00
|
|
|
|
2019-08-19 10:33:12 +02:00
|
|
|
# for loading into a slot, return the "slot_definition" that can be passed to
|
2018-03-15 16:03:38 +01:00
|
|
|
# SlotLoad.
|
2019-08-19 10:33:12 +02:00
|
|
|
def to_slot(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-07-20 13:22:26 +02:00
|
|
|
require_relative "assignment"
|
2018-06-29 21:46:00 +02:00
|
|
|
require_relative "basic_values"
|
2018-07-30 13:45:37 +02:00
|
|
|
require_relative "call_statement"
|
2019-08-19 10:33:12 +02:00
|
|
|
require_relative "class_expression"
|
2018-06-29 21:46:00 +02:00
|
|
|
require_relative "if_statement"
|
2018-07-20 13:22:26 +02:00
|
|
|
require_relative "ivar_assignment"
|
2019-08-19 10:33:12 +02:00
|
|
|
require_relative "lambda_expression"
|
2018-06-29 21:46:00 +02:00
|
|
|
require_relative "local_assignment"
|
2019-08-25 13:40:59 +02:00
|
|
|
require_relative "macro_expression"
|
2019-08-19 10:33:12 +02:00
|
|
|
require_relative "method_expression"
|
|
|
|
require_relative "class_method_expression"
|
2018-06-29 21:46:00 +02:00
|
|
|
require_relative "return_statement"
|
|
|
|
require_relative "statements"
|
|
|
|
require_relative "send_statement"
|
2019-08-19 17:48:13 +02:00
|
|
|
require_relative "super_statement"
|
2018-06-29 21:46:00 +02:00
|
|
|
require_relative "variables"
|
|
|
|
require_relative "while_statement"
|
|
|
|
require_relative "yield_statement"
|