remove own sat

This commit is contained in:
Torsten Ruger 2015-09-15 18:56:55 +03:00
parent 9c89415857
commit eca1e6b1af
12 changed files with 0 additions and 419 deletions

View File

@ -1,84 +0,0 @@
# collection of the simple ones, int and strings and such
module Ast
class IntegerExpression < Expression
attr_reader :value
def initialize val
@value = val
end
def attributes
[:value]
end
def inspect
self.class.name + ".new(" + value.to_s+ ")"
end
def to_s
value.to_s
end
end
class TrueExpression < Expression
def to_s
"true"
end
def attributes
[]
end
end
class FalseExpression < Expression
def to_s
"false"
end
def attributes
[]
end
end
class NilExpression < Expression
def to_s
"nil"
end
def attributes
[]
end
end
class NameExpression < Expression
attr_reader :name
def initialize name
@name = name.to_sym
end
def attributes
[:name]
end
def inspect
"#{self.class.name}.new(#{name.inspect})"
end
def to_s
name.to_s
end
end
class VariableExpression < NameExpression
end
class ModuleName < NameExpression
end
class StringExpression < Expression
attr_reader :string
def initialize str
@string = str
end
def attributes
[:string]
end
def inspect
self.class.name + '.new("' + string + '")'
end
def to_s
'"' + string.to_s + '"'
end
end
end

View File

@ -1,26 +0,0 @@
module Ast
class BlockExpression < Expression
attr_reader :call_exp, :args , :body_exp
def initialize call_exp, args , body_exp
@call_exp = call_exp.to_sym
@args = args
@body_exp = body_exp
end
def attributes
[:call_exp, :args , :body_exp]
end
def inspect
self.class.call_exp + ".new(" + call_exp.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") + "] ," + body_exp.inspect + ")"
end
def to_s
"#{call_exp}(" + args.join(",") + ")"
end
def attributes
[:call_exp , :args , :body_exp]
end
end
end

View File

@ -1,24 +0,0 @@
module Ast
# assignment, like operators are really function calls
class CallSiteExpression < Expression
attr_reader :name, :args , :receiver
def initialize name, args , receiver = Ast::NameExpression.new(:self)
@name = name.to_sym
@args = args
@receiver = receiver
end
def attributes
[:name , :args , :receiver]
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") + "] ," + receiver.inspect + ")"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
end
end

View File

@ -1,31 +0,0 @@
module Ast
class ArrayExpression < Expression
attr_reader :values
def attributes
[:values]
end
def initialize vals
@values = vals
end
def inspect
self.class.name + ".new(" + values.to_s+ ")"
end
end
class AssociationExpression < Expression
attr_reader :key , :value
def initialize key , value
@key , @value = key , value
end
def attributes
[:key , :value]
end
def inspect
self.class.name + ".new(" + key.inspect + " , " + value.inspect + ")"
end
end
class HashExpression < ArrayExpression
end
end

View File

@ -1,82 +0,0 @@
# abstract syntax tree (ast)
# This Layer is semi automagically created by parslet using the transform
# It in turn is responsible for the transformation to the next layer, vm code
# This happens in the compile function which must return a Vm::Code derivative
# PS: compare is only for tests and should be factored out to there
Array.class_eval do
def to_basic
collect do |item|
item.to_basic
end
end
end
Symbol.class_eval do
def to_basic
to_s
end
end
String.class_eval do
def to_basic
to_s
end
end
module Ast
class Expression
def attributes
raise "abstract called for #{self}"
end
def to_basic()
data = { "class" => self.class.name }
attributes.each do |name|
val = instance_variable_get("@#{name}".to_sym)
res = val.to_basic
data[name] = res
end
data
end
def self.from_basic(hash)
clazz = hash.delete("class")
keys = hash.keys
klass = clazz.split("::").inject(Object) {|o,c| o.const_get(c)}
keys.delete("class")
values = keys.collect{|k| read_basic(hash[k]) }
klass.new(*values)
end
def self.read_basic val
return from_basic(val) if val.is_a?(Hash)
return val.collect{|i| from_basic(i)} if(val.is_a? Array )
val
end
def inspect
self.class.name + ".new()"
end
def == other
return false unless other.class == self.class
attributes.each do |a|
left = send(a)
right = other.send(a)
return false unless left.class == right.class
return false unless left == right
end
return true
end
end
end
require_relative "basic_expressions"
require_relative "call_site_expression"
require_relative "compound_expressions"
require_relative "if_expression"
require_relative "function_expression"
require_relative "module_expression"
require_relative "operator_expressions"
require_relative "return_expression"
require_relative "while_expression"
require_relative "expression_list"

View File

@ -1,20 +0,0 @@
module Ast
class ExpressionList < Expression
attr_reader :expressions
def initialize expressions
@expressions = expressions
end
def attributes
[:expressions]
end
def inspect
self.class.name + ".new( ["+ expressions.collect(&:inspect).join( ",") +"])"
end
def to_s
expressions.collect(&:inspect).join("\n")
end
end
end

View File

@ -1,25 +0,0 @@
module Ast
class FunctionExpression < Expression
attr_reader :name, :params, :body , :receiver
def initialize name, params, body , receiver = nil
@name = name.to_sym
@params = params
@body = body
@receiver = receiver
end
def attributes
[:name, :params, :body , :receiver]
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
params.collect{|m| m.inspect }.join( ",") +"] , [" +
body.collect{|m| m.inspect }.join( ",") +"] ,"+ receiver.inspect + " )"
end
def to_s
ret = "def "
ret += "#{receiver}." if receiver
ret + "#{name}( " + params.join(",") + ") \n" + body.join("\n") + "end\n"
end
end
end

View File

@ -1,15 +0,0 @@
module Ast
class IfExpression < Expression
attr_reader :cond, :if_true, :if_false
def initialize cond, if_true, if_false
@cond, @if_true, @if_false = cond, if_true, if_false
end
def attributes
[:cond, :if_true, :if_false]
end
def inspect
self.class.name + ".new(" + cond.inspect + ", "+
if_true.inspect + "," + if_false.inspect + " )"
end
end
end

View File

@ -1,41 +0,0 @@
module Ast
class ModuleExpression < Expression
attr_reader :name ,:expressions
def initialize name , expressions
@name = name.to_sym
@expressions = expressions
end
def attributes
[:name , :expressions]
end
def inspect
self.class.name + ".new(" + @name.inspect + " ," + @expressions.inspect + " )"
end
def to_s
"module #{name}\n #{expressions}\nend\n"
end
end
class ClassExpression < ModuleExpression
def initialize name , derived , expressions
super(name , expressions)
@derived_from = derived
end
def attributes
[:name , :derived_from , :expressions]
end
def inspect
self.class.name + ".new(" + @name.inspect + " ," +
@derived_from.inspect + ", " + @expressions.inspect + " )"
end
def derived_from
@derived_from ? @derived_from : :Object
end
def to_s
s = "class #{name} < #{derived_from}\n #{expressions}\nend\n"
end
end
end

View File

@ -1,37 +0,0 @@
module Ast
class OperatorExpression < Expression
attr_reader :operator, :left, :right
def initialize operator, left, right
@operator, @left, @right = operator, left, right
end
def attributes
[:operator, :left, :right]
end
def inspect
self.class.name + ".new(" + operator.inspect + ", " + left.inspect + "," + right.inspect + ")"
end
def to_s
"#{left} #{operator} #{right}"
end
end
class AssignmentExpression < Expression
attr_reader :left, :right
def initialize left, right
@left, @right = left, right
end
def attributes
[:left, :right]
end
def inspect
self.class.name + ".new(" + left.inspect + "," + right.inspect + ")"
end
def to_s
"#{left} = #{right}"
end
end
end

View File

@ -1,17 +0,0 @@
module Ast
class ReturnExpression < Expression
attr_reader :expression
def initialize expression
@expression = expression
end
def inspect
self.class.name + ".new(" + expression.inspect + " )"
end
def to_s
"return #{expression}\n"
end
def attributes
[:expression]
end
end
end

View File

@ -1,17 +0,0 @@
module Ast
class WhileExpression < Expression
attr_reader :condition, :body
def initialize condition, body
@condition , @body = condition , body
end
def inspect
self.class.name + ".new(" + condition.inspect + ", " + body.inspect + " )"
end
def to_s
"while(#{condition}) do\n" + body.join("\n") + "\nend\n"
end
def attributes
[:condition, :body]
end
end
end