From da553f996fa1ff58fd80e06d64e89ec8f860e208 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 8 Dec 2016 15:25:20 +0200 Subject: [PATCH] move compiler to typed starting to get rid of soml, bit by bit --- lib/register.rb | 2 +- lib/register/builtin/integer.rb | 6 +++--- lib/register/builtin/kernel.rb | 4 ++-- lib/register/builtin/object.rb | 4 ++-- lib/register/builtin/space.rb | 2 +- lib/register/builtin/word.rb | 6 +++--- lib/register/machine.rb | 2 +- lib/{soml => typed}/ast_helper.rb | 0 lib/{soml => typed}/compiler.rb | 2 +- lib/{soml => typed}/compiler/README.md | 0 lib/{soml => typed}/compiler/assignment.rb | 2 +- lib/{soml => typed}/compiler/basic_values.rb | 2 +- lib/{soml => typed}/compiler/call_site.rb | 2 +- lib/{soml => typed}/compiler/class_field.rb | 2 +- lib/{soml => typed}/compiler/class_statement.rb | 2 +- lib/{soml => typed}/compiler/collections.rb | 2 +- lib/{soml => typed}/compiler/field_access.rb | 2 +- lib/{soml => typed}/compiler/field_def.rb | 2 +- lib/{soml => typed}/compiler/function_definition.rb | 2 +- lib/{soml => typed}/compiler/if_statement.rb | 2 +- lib/{soml => typed}/compiler/name_expression.rb | 2 +- lib/{soml => typed}/compiler/operator_value.rb | 2 +- lib/{soml => typed}/compiler/return_statement.rb | 2 +- lib/{soml => typed}/compiler/statement_list.rb | 3 ++- lib/{soml => typed}/compiler/while_statement.rb | 2 +- stash/soml/expressions/helper.rb | 4 ++-- stash/soml/helper.rb | 2 +- stash/soml/parfait/helper.rb | 2 +- test/bench/soml/helper.rb | 2 +- test/register/interpreter/helper.rb | 2 +- 30 files changed, 36 insertions(+), 35 deletions(-) rename lib/{soml => typed}/ast_helper.rb (100%) rename lib/{soml => typed}/compiler.rb (99%) rename lib/{soml => typed}/compiler/README.md (100%) rename lib/{soml => typed}/compiler/assignment.rb (98%) rename lib/{soml => typed}/compiler/basic_values.rb (99%) rename lib/{soml => typed}/compiler/call_site.rb (99%) rename lib/{soml => typed}/compiler/class_field.rb (97%) rename lib/{soml => typed}/compiler/class_statement.rb (97%) rename lib/{soml => typed}/compiler/collections.rb (94%) rename lib/{soml => typed}/compiler/field_access.rb (98%) rename lib/{soml => typed}/compiler/field_def.rb (97%) rename lib/{soml => typed}/compiler/function_definition.rb (98%) rename lib/{soml => typed}/compiler/if_statement.rb (98%) rename lib/{soml => typed}/compiler/name_expression.rb (99%) rename lib/{soml => typed}/compiler/operator_value.rb (98%) rename lib/{soml => typed}/compiler/return_statement.rb (94%) rename lib/{soml => typed}/compiler/statement_list.rb (88%) rename lib/{soml => typed}/compiler/while_statement.rb (98%) diff --git a/lib/register.rb b/lib/register.rb index cbd6541f..e478175b 100644 --- a/lib/register.rb +++ b/lib/register.rb @@ -3,7 +3,7 @@ require "register/positioned" require "typed/parfait" require "register/machine" -require "soml/compiler" +require "typed/compiler" class Fixnum diff --git a/lib/register/builtin/integer.rb b/lib/register/builtin/integer.rb index 4749d400..d9751b46 100644 --- a/lib/register/builtin/integer.rb +++ b/lib/register/builtin/integer.rb @@ -6,18 +6,18 @@ module Register include AST::Sexp def mod4 context - compiler = Soml::Compiler.new.create_method(:Integer,:mod4 ).init_method + compiler = Typed::Compiler.new.create_method(:Integer,:mod4 ).init_method return compiler.method end def putint context - compiler = Soml::Compiler.new.create_method(:Integer,:putint ).init_method + compiler = Typed::Compiler.new.create_method(:Integer,:putint ).init_method return compiler.method end def div10 context s = "div_10" - compiler = Soml::Compiler.new.create_method(:Integer,:div10 ).init_method + compiler = Typed::Compiler.new.create_method(:Integer,:div10 ).init_method me = compiler.process( Soml::NameExpression.new( :self) ) tmp = compiler.process( Soml::NameExpression.new( :self) ) q = compiler.process( Soml::NameExpression.new( :self) ) diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index aefaa40a..14c412a2 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -7,7 +7,7 @@ module Register # so it is responsible for initial setup def __init__ context source = "__init__" - compiler = Soml::Compiler.new.create_method(:Kernel,:__init__ ) + compiler = Typed::Compiler.new.create_method(:Kernel,:__init__ ) # no method enter or return (automatically added), remove new_start = Label.new(source , source ) compiler.method.instructions = new_start @@ -34,7 +34,7 @@ module Register end def exit context - compiler = Soml::Compiler.new.create_method(:Kernel,:exit ).init_method + compiler = Typed::Compiler.new.create_method(:Kernel,:exit ).init_method emit_syscall( compiler , :exit ) return compiler.method end diff --git a/lib/register/builtin/object.rb b/lib/register/builtin/object.rb index 682ab123..2fa4ab0e 100644 --- a/lib/register/builtin/object.rb +++ b/lib/register/builtin/object.rb @@ -10,7 +10,7 @@ module Register # return is stored in return_value # (this method returns a new method off course, like all builtin) def get_internal_word context - compiler = Soml::Compiler.new.create_method(:Object , :get_internal_word , {:index => :Integer}).init_method + compiler = Typed::Compiler.new.create_method(:Object , :get_internal_word , {:index => :Integer}).init_method source = "get_internal_word" #Load self by "calling" on_name me = compiler.process( Soml::NameExpression.new( :self) ) @@ -27,7 +27,7 @@ module Register # self[index] = val basically. Index is the first arg , value the second # no return def set_internal_word context - compiler = Soml::Compiler.new.create_method(:Object , :set_internal_word , + compiler = Typed::Compiler.new.create_method(:Object , :set_internal_word , {:index => :Integer, :value => :Object} ).init_method source = "set_internal_word" #Load self by "calling" on_name diff --git a/lib/register/builtin/space.rb b/lib/register/builtin/space.rb index a20e8cda..14ba16c8 100644 --- a/lib/register/builtin/space.rb +++ b/lib/register/builtin/space.rb @@ -9,7 +9,7 @@ module Register # main entry point, ie __init__ calls this # defined here as empty, to be redefined def main context - compiler = Soml::Compiler.new.create_method(:Space , :main ).init_method + compiler = Typed::Compiler.new.create_method(:Space , :main ).init_method return compiler.method end diff --git a/lib/register/builtin/word.rb b/lib/register/builtin/word.rb index 94cf4209..0783004b 100644 --- a/lib/register/builtin/word.rb +++ b/lib/register/builtin/word.rb @@ -5,7 +5,7 @@ module Register include AST::Sexp def putstring context - compiler = Soml::Compiler.new.create_method(:Word , :putstring ).init_method + compiler = Typed::Compiler.new.create_method(:Word , :putstring ).init_method compiler.add_code Register.get_slot( "putstring" , :message , :receiver , :new_message ) index = Parfait::Word.get_length_index reg = RegisterValue.new(:r2 , :Integer) @@ -17,7 +17,7 @@ module Register # self[index] basically. Index is the first arg > 0 # return (and word sized int) is stored in return_value def get_internal_byte context - compiler = Soml::Compiler.new.create_method(:Word , :get_internal_byte , {:index => :Integer }).init_method + compiler = Typed::Compiler.new.create_method(:Word , :get_internal_byte , {:index => :Integer }).init_method source = "get_internal_word" #Load self by "calling" on_name me = compiler.process( Soml::NameExpression.new( :self) ) @@ -35,7 +35,7 @@ module Register # value the second # no return def set_internal_byte context - compiler = Soml::Compiler.new.create_method(:Word , :set_internal_byte , + compiler = Typed::Compiler.new.create_method(:Word , :set_internal_byte , {:index => :Integer, :value => :Integer } ).init_method source = "set_internal_word" #Load self by "calling" on_name diff --git a/lib/register/machine.rb b/lib/register/machine.rb index c2015a4b..e3fa833b 100644 --- a/lib/register/machine.rb +++ b/lib/register/machine.rb @@ -74,7 +74,7 @@ module Register syntax = Parser::Salama.new.parse_with_debug(bytes, reporter: Parslet::ErrorReporter::Deepest.new) parts = Parser::Transform.new.apply(syntax) #puts parts.inspect - Soml.compile( parts ) + Typed.compile( parts ) end end diff --git a/lib/soml/ast_helper.rb b/lib/typed/ast_helper.rb similarity index 100% rename from lib/soml/ast_helper.rb rename to lib/typed/ast_helper.rb diff --git a/lib/soml/compiler.rb b/lib/typed/compiler.rb similarity index 99% rename from lib/soml/compiler.rb rename to lib/typed/compiler.rb index e61faea8..9a20b8e8 100644 --- a/lib/soml/compiler.rb +++ b/lib/typed/compiler.rb @@ -1,4 +1,4 @@ -module Soml +module Typed # Compiling is the conversion of the AST into 2 things: # - code (ie sequences of Instructions inside Methods) # - an object graph containing all the Methods, their classes and Constants diff --git a/lib/soml/compiler/README.md b/lib/typed/compiler/README.md similarity index 100% rename from lib/soml/compiler/README.md rename to lib/typed/compiler/README.md diff --git a/lib/soml/compiler/assignment.rb b/lib/typed/compiler/assignment.rb similarity index 98% rename from lib/soml/compiler/assignment.rb rename to lib/typed/compiler/assignment.rb index 39913077..f2b93c77 100644 --- a/lib/soml/compiler/assignment.rb +++ b/lib/typed/compiler/assignment.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_Assignment statement diff --git a/lib/soml/compiler/basic_values.rb b/lib/typed/compiler/basic_values.rb similarity index 99% rename from lib/soml/compiler/basic_values.rb rename to lib/typed/compiler/basic_values.rb index 8d0e02a2..0366c537 100644 --- a/lib/soml/compiler/basic_values.rb +++ b/lib/typed/compiler/basic_values.rb @@ -1,4 +1,4 @@ -module Soml +module Typed # collection of the simple ones, int and strings and such Compiler.class_eval do diff --git a/lib/soml/compiler/call_site.rb b/lib/typed/compiler/call_site.rb similarity index 99% rename from lib/soml/compiler/call_site.rb rename to lib/typed/compiler/call_site.rb index d21190ad..cae23c12 100644 --- a/lib/soml/compiler/call_site.rb +++ b/lib/typed/compiler/call_site.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_CallSite statement diff --git a/lib/soml/compiler/class_field.rb b/lib/typed/compiler/class_field.rb similarity index 97% rename from lib/soml/compiler/class_field.rb rename to lib/typed/compiler/class_field.rb index 7e811c7f..b0acaaf7 100644 --- a/lib/soml/compiler/class_field.rb +++ b/lib/typed/compiler/class_field.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_ClassField statement diff --git a/lib/soml/compiler/class_statement.rb b/lib/typed/compiler/class_statement.rb similarity index 97% rename from lib/soml/compiler/class_statement.rb rename to lib/typed/compiler/class_statement.rb index 681e1f58..1a2dd9c9 100644 --- a/lib/soml/compiler/class_statement.rb +++ b/lib/typed/compiler/class_statement.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_ClassStatement statement diff --git a/lib/soml/compiler/collections.rb b/lib/typed/compiler/collections.rb similarity index 94% rename from lib/soml/compiler/collections.rb rename to lib/typed/compiler/collections.rb index 8a2473e2..3ceb3f8c 100644 --- a/lib/soml/compiler/collections.rb +++ b/lib/typed/compiler/collections.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do # attr_reader :values diff --git a/lib/soml/compiler/field_access.rb b/lib/typed/compiler/field_access.rb similarity index 98% rename from lib/soml/compiler/field_access.rb rename to lib/typed/compiler/field_access.rb index 345cbcb0..e83da282 100644 --- a/lib/soml/compiler/field_access.rb +++ b/lib/typed/compiler/field_access.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_FieldAccess statement diff --git a/lib/soml/compiler/field_def.rb b/lib/typed/compiler/field_def.rb similarity index 97% rename from lib/soml/compiler/field_def.rb rename to lib/typed/compiler/field_def.rb index e93438f8..348d8f41 100644 --- a/lib/soml/compiler/field_def.rb +++ b/lib/typed/compiler/field_def.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do include AST::Sexp diff --git a/lib/soml/compiler/function_definition.rb b/lib/typed/compiler/function_definition.rb similarity index 98% rename from lib/soml/compiler/function_definition.rb rename to lib/typed/compiler/function_definition.rb index 0fcd0344..e3526d08 100644 --- a/lib/soml/compiler/function_definition.rb +++ b/lib/typed/compiler/function_definition.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_FunctionStatement statement diff --git a/lib/soml/compiler/if_statement.rb b/lib/typed/compiler/if_statement.rb similarity index 98% rename from lib/soml/compiler/if_statement.rb rename to lib/typed/compiler/if_statement.rb index e4b30012..c4f57ea7 100644 --- a/lib/soml/compiler/if_statement.rb +++ b/lib/typed/compiler/if_statement.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do # an if evaluates the condition and jumps to the true block if true diff --git a/lib/soml/compiler/name_expression.rb b/lib/typed/compiler/name_expression.rb similarity index 99% rename from lib/soml/compiler/name_expression.rb rename to lib/typed/compiler/name_expression.rb index 331316df..842ff399 100644 --- a/lib/soml/compiler/name_expression.rb +++ b/lib/typed/compiler/name_expression.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do # attr_reader :name diff --git a/lib/soml/compiler/operator_value.rb b/lib/typed/compiler/operator_value.rb similarity index 98% rename from lib/soml/compiler/operator_value.rb rename to lib/typed/compiler/operator_value.rb index 8ba0599f..b3773394 100644 --- a/lib/soml/compiler/operator_value.rb +++ b/lib/typed/compiler/operator_value.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_OperatorExpression statement diff --git a/lib/soml/compiler/return_statement.rb b/lib/typed/compiler/return_statement.rb similarity index 94% rename from lib/soml/compiler/return_statement.rb rename to lib/typed/compiler/return_statement.rb index bd620b3e..95f8021c 100644 --- a/lib/soml/compiler/return_statement.rb +++ b/lib/typed/compiler/return_statement.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_ReturnStatement statement diff --git a/lib/soml/compiler/statement_list.rb b/lib/typed/compiler/statement_list.rb similarity index 88% rename from lib/soml/compiler/statement_list.rb rename to lib/typed/compiler/statement_list.rb index a146413c..a9dd1ccf 100644 --- a/lib/soml/compiler/statement_list.rb +++ b/lib/typed/compiler/statement_list.rb @@ -1,4 +1,5 @@ -module Soml +module Typed + Compiler.class_eval do def on_statements statement diff --git a/lib/soml/compiler/while_statement.rb b/lib/typed/compiler/while_statement.rb similarity index 98% rename from lib/soml/compiler/while_statement.rb rename to lib/typed/compiler/while_statement.rb index 8dba1c63..487506ac 100644 --- a/lib/soml/compiler/while_statement.rb +++ b/lib/typed/compiler/while_statement.rb @@ -1,4 +1,4 @@ -module Soml +module Typed Compiler.class_eval do def on_WhileStatement statement diff --git a/stash/soml/expressions/helper.rb b/stash/soml/expressions/helper.rb index 63608fa2..015079af 100644 --- a/stash/soml/expressions/helper.rb +++ b/stash/soml/expressions/helper.rb @@ -1,7 +1,7 @@ require_relative '../../helper' require 'parslet/convenience' -Soml::Compiler.class_eval do +Typed::Compiler.class_eval do def set_main main @clazz = Register.machine.space.get_class_by_name :Object @method = main @@ -23,7 +23,7 @@ module ExpressionHelper parts = Parser::Transform.new.apply(syntax) codes = Soml.ast_to_code parts #puts parts.inspect - compiler = Soml::Compiler.new + compiler = Typed::Compiler.new set_main(compiler) produced = compiler.process( codes ) assert @output , "No output given" diff --git a/stash/soml/helper.rb b/stash/soml/helper.rb index 73369450..3d1ec0e0 100644 --- a/stash/soml/helper.rb +++ b/stash/soml/helper.rb @@ -22,7 +22,7 @@ module RuntimeTests def load_program @machine = Register.machine.boot - Soml::Compiler.load_parfait + Typed::Compiler.load_parfait @machine.parse_and_compile main() @machine.collect end diff --git a/stash/soml/parfait/helper.rb b/stash/soml/parfait/helper.rb index d70a2971..c5d74d82 100644 --- a/stash/soml/parfait/helper.rb +++ b/stash/soml/parfait/helper.rb @@ -12,7 +12,7 @@ module ParfaitTests def setup @stdout = "" @machine = Register.machine.boot - Soml::Compiler.load_parfait + Typed::Compiler.load_parfait end def main diff --git a/test/bench/soml/helper.rb b/test/bench/soml/helper.rb index 2c8918ae..dde47c56 100644 --- a/test/bench/soml/helper.rb +++ b/test/bench/soml/helper.rb @@ -9,7 +9,7 @@ module BenchTests def setup @stdout = "" @machine = Register.machine.boot - Soml::Compiler.load_parfait + Typed::Compiler.load_parfait end def main diff --git a/test/register/interpreter/helper.rb b/test/register/interpreter/helper.rb index 23af1b44..b87d817f 100644 --- a/test/register/interpreter/helper.rb +++ b/test/register/interpreter/helper.rb @@ -8,7 +8,7 @@ module Ticker syntax = Parser::Salama.new.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new) parts = Parser::Transform.new.apply(syntax) #puts parts.inspect - Soml.compile( parts ) + Typed.compile( parts ) machine.collect @interpreter = Register::Interpreter.new @interpreter.start Register.machine.init