renames Typed to Vm

This commit is contained in:
Torsten Ruger 2017-01-14 19:28:44 +02:00
parent 75c7ca950e
commit bd78a2d555
95 changed files with 61 additions and 61 deletions

8
.reek
View File

@ -8,19 +8,19 @@ FeatureEnvy:
exclude: exclude:
- "Register::Interpreter" - "Register::Interpreter"
- "Arm::Translator" - "Arm::Translator"
- "Typed::ToCode" - "Vm::ToCode"
TooManyMethods: TooManyMethods:
exclude: exclude:
- "Register::Interpreter" - "Register::Interpreter"
- "Arm::Translator" - "Arm::Translator"
- "Typed::ToCode" - "Vm::ToCode"
UtilityFunction: UtilityFunction:
exclude: exclude:
- "Register::Interpreter" - "Register::Interpreter"
- "Arm::Translator" - "Arm::Translator"
- "Typed::ToCode" - "Vm::ToCode"
UncommunicativeMethodName: UncommunicativeMethodName:
exclude: exclude:
- "Register::Interpreter" - "Register::Interpreter"
- "Arm::Translator" - "Arm::Translator"
- "Typed::ToCode" - "Vm::ToCode"

View File

@ -7,9 +7,9 @@ end
require "register/padding" require "register/padding"
require "register/positioned" require "register/positioned"
require "typed/method_compiler" require "vm/method_compiler"
require "typed/parfait" require "vm/parfait"
require "register/machine" require "register/machine"
class Fixnum class Fixnum

View File

@ -4,14 +4,14 @@ module Register
module CompileHelper module CompileHelper
def self_and_int_arg(compiler , source) def self_and_int_arg(compiler , source)
me = compiler.process( Typed::Tree::NameExpression.new( :self) ) me = compiler.process( Vm::Tree::NameExpression.new( :self) )
int_arg = load_int_arg_at(compiler , source , 1 ) int_arg = load_int_arg_at(compiler , source , 1 )
return me , int_arg return me , int_arg
end end
def compiler_for( type , method_name , extra_args = {}) def compiler_for( type , method_name , extra_args = {})
args = {:index => :Integer}.merge( extra_args ) args = {:index => :Integer}.merge( extra_args )
Typed::MethodCompiler.new.create_method(type , method_name , args ).init_method Vm::MethodCompiler.new.create_method(type , method_name , args ).init_method
end end
# Load the value # Load the value

View File

@ -6,22 +6,22 @@ module Register
include AST::Sexp include AST::Sexp
def mod4 context def mod4 context
compiler = Typed::MethodCompiler.new.create_method(:Integer,:mod4 ).init_method compiler = Vm::MethodCompiler.new.create_method(:Integer,:mod4 ).init_method
return compiler.method return compiler.method
end end
def putint context def putint context
compiler = Typed::MethodCompiler.new.create_method(:Integer,:putint ).init_method compiler = Vm::MethodCompiler.new.create_method(:Integer,:putint ).init_method
return compiler.method return compiler.method
end end
def div10 context def div10 context
s = "div_10" s = "div_10"
compiler = Typed::MethodCompiler.new.create_method(:Integer,:div10 ).init_method compiler = Vm::MethodCompiler.new.create_method(:Integer,:div10 ).init_method
me = compiler.process( Typed::Tree::NameExpression.new( :self) ) me = compiler.process( Vm::Tree::NameExpression.new( :self) )
tmp = compiler.process( Typed::Tree::NameExpression.new( :self) ) tmp = compiler.process( Vm::Tree::NameExpression.new( :self) )
q = compiler.process( Typed::Tree::NameExpression.new( :self) ) q = compiler.process( Vm::Tree::NameExpression.new( :self) )
const = compiler.process( Typed::Tree::IntegerExpression.new(1) ) const = compiler.process( Vm::Tree::IntegerExpression.new(1) )
# int tmp = self >> 1 # int tmp = self >> 1
compiler.add_code Register.op( s , ">>" , tmp , const) compiler.add_code Register.op( s , ">>" , tmp , const)
# int q = self >> 2 # int q = self >> 2

View File

@ -6,7 +6,7 @@ module Register
# it isn't really a function, ie it is jumped to (not called), exits and may not return # it isn't really a function, ie it is jumped to (not called), exits and may not return
# so it is responsible for initial setup # so it is responsible for initial setup
def __init__ context def __init__ context
compiler = Typed::MethodCompiler.new.create_method(:Kernel,:__init__ ) compiler = Vm::MethodCompiler.new.create_method(:Kernel,:__init__ )
new_start = Register.label("__init__ start" , "__init__" ) new_start = Register.label("__init__ start" , "__init__" )
compiler.method.set_instructions( new_start) compiler.method.set_instructions( new_start)
compiler.set_current new_start compiler.set_current new_start
@ -29,7 +29,7 @@ module Register
end end
def exit context def exit context
compiler = Typed::MethodCompiler.new.create_method(:Kernel,:exit ).init_method compiler = Vm::MethodCompiler.new.create_method(:Kernel,:exit ).init_method
emit_syscall( compiler , :exit ) emit_syscall( compiler , :exit )
return compiler.method return compiler.method
end end

View File

@ -9,7 +9,7 @@ module Register
# main entry point, ie __init__ calls this # main entry point, ie __init__ calls this
# defined here as empty, to be redefined # defined here as empty, to be redefined
def main context def main context
compiler = Typed::MethodCompiler.new.create_method(:Space , :main ).init_method compiler = Vm::MethodCompiler.new.create_method(:Space , :main ).init_method
return compiler.method return compiler.method
end end

View File

@ -7,7 +7,7 @@ module Register
include CompileHelper include CompileHelper
def putstring context def putstring context
compiler = Typed::MethodCompiler.new.create_method(:Word , :putstring ).init_method compiler = Vm::MethodCompiler.new.create_method(:Word , :putstring ).init_method
compiler.add_slot_to_reg( "putstring" , :message , :receiver , :new_message ) compiler.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
index = Parfait::Word.get_length_index index = Parfait::Word.get_length_index
reg = RegisterValue.new(:r2 , :Integer) reg = RegisterValue.new(:r2 , :Integer)

View File

@ -18,7 +18,7 @@ module Register
@source = source @source = source
@next = nekst @next = nekst
return unless source return unless source
raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(Typed::Code) raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(Vm::Code)
end end
attr_reader :source attr_reader :source

View File

@ -11,7 +11,7 @@ require_relative "method_compiler/return_statement"
require_relative "method_compiler/statement_list" require_relative "method_compiler/statement_list"
require_relative "method_compiler/while_statement" require_relative "method_compiler/while_statement"
module Typed module Vm
CompilerModules = [ "assignment" , "basic_values" , "call_site", CompilerModules = [ "assignment" , "basic_values" , "call_site",
"collections" , "field_access", "collections" , "field_access",
@ -56,13 +56,13 @@ module Typed
# Helper function to create a new compiler and compie the statement(s) # Helper function to create a new compiler and compie the statement(s)
def self.compile statement def self.compile statement
compiler = MethodCompiler.new compiler = MethodCompiler.new
code = Typed.ast_to_code statement code = Vm.ast_to_code statement
compiler.process code compiler.process code
end end
class MethodCompiler class MethodCompiler
CompilerModules.each do |mod| CompilerModules.each do |mod|
include Typed.const_get( mod.camelize ) include Vm.const_get( mod.camelize )
end end
def initialize( method = nil ) def initialize( method = nil )
@ -83,7 +83,7 @@ module Typed
# Dispatches `code` according to it's class name, for class NameExpression # Dispatches `code` according to it's class name, for class NameExpression
# a method named `on_NameExpression` is invoked with one argument, the `code` # a method named `on_NameExpression` is invoked with one argument, the `code`
# #
# @param [Typed::Code, nil] code # @param [Vm::Code, nil] code
def process(code) def process(code)
name = code.class.name.split("::").last name = code.class.name.split("::").last
# Invoke a specific handler # Invoke a specific handler

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Assignment module Assignment
def on_Assignment( statement ) def on_Assignment( statement )

View File

@ -1,4 +1,4 @@
module Typed module Vm
# collection of the simple ones, int and strings and such # collection of the simple ones, int and strings and such
module BasicValues module BasicValues

View File

@ -1,4 +1,4 @@
module Typed module Vm
module CallSite module CallSite
def on_CallSite( statement ) def on_CallSite( statement )

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Collections module Collections

View File

@ -1,4 +1,4 @@
module Typed module Vm
module FieldAccess module FieldAccess
def on_FieldAccess statement def on_FieldAccess statement

View File

@ -1,4 +1,4 @@
module Typed module Vm
module IfStatement module IfStatement
# an if evaluates the condition and jumps to the true block if true # an if evaluates the condition and jumps to the true block if true

View File

@ -1,4 +1,4 @@
module Typed module Vm
module NameExpression module NameExpression
# attr_reader :name # attr_reader :name

View File

@ -1,4 +1,4 @@
module Typed module Vm
module OperatorExpression module OperatorExpression
def on_OperatorExpression statement def on_OperatorExpression statement

View File

@ -1,4 +1,4 @@
module Typed module Vm
module ReturnStatement module ReturnStatement
def on_ReturnStatement statement def on_ReturnStatement statement

View File

@ -1,4 +1,4 @@
module Typed module Vm
module StatementList module StatementList
def on_Statements statement def on_Statements statement
process_all( statement.statements ) process_all( statement.statements )

View File

@ -1,4 +1,4 @@
module Typed module Vm
module WhileStatement module WhileStatement
def on_WhileStatement statement def on_WhileStatement statement

View File

@ -1,5 +1,5 @@
# Base class for Expresssion and Statement # Base class for Expresssion and Statement
module Typed module Vm
class Code ; end class Code ; end
class Statement < Code ; end class Statement < Code ; end

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class Assignment < Statement class Assignment < Statement
attr_accessor :name , :value attr_accessor :name , :value

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class IntegerExpression < Expression class IntegerExpression < Expression
include ValuePrinter include ValuePrinter

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class CallSite < Expression class CallSite < Expression
attr_accessor :name , :receiver , :arguments attr_accessor :name , :receiver , :arguments

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class FieldAccess < Expression class FieldAccess < Expression
attr_accessor :receiver , :field attr_accessor :receiver , :field

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class IfStatement < Statement class IfStatement < Statement
attr_accessor :branch_type , :condition , :if_true , :if_false attr_accessor :branch_type , :condition , :if_true , :if_false

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class OperatorExpression < Expression class OperatorExpression < Expression
attr_accessor :operator , :left_expression , :right_expression attr_accessor :operator , :left_expression , :right_expression

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class ReturnStatement < Statement class ReturnStatement < Statement
attr_accessor :return_value attr_accessor :return_value

View File

@ -1,4 +1,4 @@
module Typed module Vm
class Statements < Statement class Statements < Statement
attr_accessor :statements attr_accessor :statements
def to_s def to_s

View File

@ -1,4 +1,4 @@
module Typed module Vm
def self.ast_to_code statement def self.ast_to_code statement
compiler = ToCode.new compiler = ToCode.new
@ -122,7 +122,7 @@ module Typed
def on_assignment statement def on_assignment statement
name , value = *statement name , value = *statement
w = Typed::Tree::Assignment.new() w = Vm::Tree::Assignment.new()
w.name = process name w.name = process name
w.value = process(value) w.value = process(value)
w w

View File

@ -1,4 +1,4 @@
module Typed module Vm
module Tree module Tree
class WhileStatement < Statement class WhileStatement < Statement
attr_accessor :branch_type , :condition , :statements attr_accessor :branch_type , :condition , :statements

View File

@ -1,6 +1,6 @@
require_relative 'helper' require_relative 'helper'
module Typed module Vm
class TestWord < MiniTest::Test class TestWord < MiniTest::Test
include Fragments include Fragments

View File

@ -12,7 +12,7 @@ module ParfaitTests
def setup def setup
@stdout = "" @stdout = ""
@machine = Register.machine.boot @machine = Register.machine.boot
Typed::Compiler.load_parfait Vm::Compiler.load_parfait
end end
def main def main

View File

@ -9,7 +9,7 @@ module BenchTests
def setup def setup
@stdout = "" @stdout = ""
@machine = Register.machine.boot @machine = Register.machine.boot
# Typed::Compiler.load_parfait # Vm::Compiler.load_parfait
# most interesting parts saved as interger/word .soml in this dir # most interesting parts saved as interger/word .soml in this dir
end end

View File

@ -5,7 +5,7 @@ class HelloTest < MiniTest::Test
def check def check
machine = Register.machine.boot machine = Register.machine.boot
Typed.compile( @input ) Vm.compile( @input )
objects = Register::Collector.collect_space objects = Register::Collector.collect_space
machine.translate_arm machine.translate_arm
writer = Elf::ObjectWriter.new(machine , objects ) writer = Elf::ObjectWriter.new(machine , objects )

View File

@ -22,8 +22,8 @@ require 'salama'
module Compiling module Compiling
def clean_compile(clazz_name , method_name , args , statements) def clean_compile(clazz_name , method_name , args , statements)
compiler = Typed::MethodCompiler.new.create_method(clazz_name,method_name,args ).init_method compiler = Vm::MethodCompiler.new.create_method(clazz_name,method_name,args ).init_method
compiler.process( Typed.ast_to_code( statements ) ) compiler.process( Vm.ast_to_code( statements ) )
end end
end end

View File

@ -8,7 +8,7 @@ module Register
def setup def setup
Register.machine.boot Register.machine.boot
do_clean_compile do_clean_compile
Typed.compile( @input ) Vm.compile( @input )
Collector.collect_space Collector.collect_space
@interpreter = Interpreter.new @interpreter = Interpreter.new
@interpreter.start Register.machine.init @interpreter.start Register.machine.init

View File

@ -8,4 +8,4 @@ require_relative "melon/test_all"
require_relative "register/test_all" require_relative "register/test_all"
require_relative "typed/test_all" require_relative "vm/test_all"

View File

@ -5,8 +5,8 @@ module Register
def check def check
Register.machine.boot unless Register.machine.booted Register.machine.boot unless Register.machine.booted
compiler = Typed::MethodCompiler.new Parfait.object_space.get_main compiler = Vm::MethodCompiler.new Parfait.object_space.get_main
code = Typed.ast_to_code @input code = Vm.ast_to_code @input
assert code.to_s , @input assert code.to_s , @input
produced = compiler.process( code ) produced = compiler.process( code )
assert @output , "No output given" assert @output , "No output given"
@ -37,8 +37,8 @@ module Register
end end
def check_nil def check_nil
assert @expect , "No output given" assert @expect , "No output given"
compiler = Typed::MethodCompiler.new compiler = Vm::MethodCompiler.new
code = Typed.ast_to_code( @input ) code = Vm.ast_to_code( @input )
assert code.to_s , @input assert code.to_s , @input
produced = compiler.process( code ) produced = compiler.process( code )
produced = Parfait.object_space.get_main.instructions produced = Parfait.object_space.get_main.instructions

View File

@ -4,8 +4,8 @@ class ToCodeTest < MiniTest::Test
include AST::Sexp include AST::Sexp
def check clazz def check clazz
tree = Typed.ast_to_code @statement tree = Vm.ast_to_code @statement
assert_equal tree.class , Typed::Tree.const_get( clazz ) assert_equal tree.class , Vm::Tree.const_get( clazz )
end end
def test_field_access def test_field_access