renames Typed to Vm
This commit is contained in:
parent
75c7ca950e
commit
bd78a2d555
8
.reek
8
.reek
@ -8,19 +8,19 @@ FeatureEnvy:
|
||||
exclude:
|
||||
- "Register::Interpreter"
|
||||
- "Arm::Translator"
|
||||
- "Typed::ToCode"
|
||||
- "Vm::ToCode"
|
||||
TooManyMethods:
|
||||
exclude:
|
||||
- "Register::Interpreter"
|
||||
- "Arm::Translator"
|
||||
- "Typed::ToCode"
|
||||
- "Vm::ToCode"
|
||||
UtilityFunction:
|
||||
exclude:
|
||||
- "Register::Interpreter"
|
||||
- "Arm::Translator"
|
||||
- "Typed::ToCode"
|
||||
- "Vm::ToCode"
|
||||
UncommunicativeMethodName:
|
||||
exclude:
|
||||
- "Register::Interpreter"
|
||||
- "Arm::Translator"
|
||||
- "Typed::ToCode"
|
||||
- "Vm::ToCode"
|
||||
|
@ -7,9 +7,9 @@ end
|
||||
|
||||
require "register/padding"
|
||||
require "register/positioned"
|
||||
require "typed/method_compiler"
|
||||
require "vm/method_compiler"
|
||||
|
||||
require "typed/parfait"
|
||||
require "vm/parfait"
|
||||
require "register/machine"
|
||||
|
||||
class Fixnum
|
||||
|
@ -4,14 +4,14 @@ module Register
|
||||
module CompileHelper
|
||||
|
||||
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 )
|
||||
return me , int_arg
|
||||
end
|
||||
|
||||
def compiler_for( type , method_name , 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
|
||||
|
||||
# Load the value
|
||||
|
@ -6,22 +6,22 @@ module Register
|
||||
include AST::Sexp
|
||||
|
||||
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
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
def div10 context
|
||||
s = "div_10"
|
||||
compiler = Typed::MethodCompiler.new.create_method(:Integer,:div10 ).init_method
|
||||
me = compiler.process( Typed::Tree::NameExpression.new( :self) )
|
||||
tmp = compiler.process( Typed::Tree::NameExpression.new( :self) )
|
||||
q = compiler.process( Typed::Tree::NameExpression.new( :self) )
|
||||
const = compiler.process( Typed::Tree::IntegerExpression.new(1) )
|
||||
compiler = Vm::MethodCompiler.new.create_method(:Integer,:div10 ).init_method
|
||||
me = compiler.process( Vm::Tree::NameExpression.new( :self) )
|
||||
tmp = compiler.process( Vm::Tree::NameExpression.new( :self) )
|
||||
q = compiler.process( Vm::Tree::NameExpression.new( :self) )
|
||||
const = compiler.process( Vm::Tree::IntegerExpression.new(1) )
|
||||
# int tmp = self >> 1
|
||||
compiler.add_code Register.op( s , ">>" , tmp , const)
|
||||
# int q = self >> 2
|
||||
|
@ -6,7 +6,7 @@ module Register
|
||||
# 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
|
||||
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__" )
|
||||
compiler.method.set_instructions( new_start)
|
||||
compiler.set_current new_start
|
||||
@ -29,7 +29,7 @@ module Register
|
||||
end
|
||||
|
||||
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 )
|
||||
return compiler.method
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ module Register
|
||||
# main entry point, ie __init__ calls this
|
||||
# defined here as empty, to be redefined
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -7,7 +7,7 @@ module Register
|
||||
include CompileHelper
|
||||
|
||||
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 )
|
||||
index = Parfait::Word.get_length_index
|
||||
reg = RegisterValue.new(:r2 , :Integer)
|
||||
|
@ -18,7 +18,7 @@ module Register
|
||||
@source = source
|
||||
@next = nekst
|
||||
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
|
||||
attr_reader :source
|
||||
|
||||
|
@ -11,7 +11,7 @@ require_relative "method_compiler/return_statement"
|
||||
require_relative "method_compiler/statement_list"
|
||||
require_relative "method_compiler/while_statement"
|
||||
|
||||
module Typed
|
||||
module Vm
|
||||
|
||||
CompilerModules = [ "assignment" , "basic_values" , "call_site",
|
||||
"collections" , "field_access",
|
||||
@ -56,13 +56,13 @@ module Typed
|
||||
# Helper function to create a new compiler and compie the statement(s)
|
||||
def self.compile statement
|
||||
compiler = MethodCompiler.new
|
||||
code = Typed.ast_to_code statement
|
||||
code = Vm.ast_to_code statement
|
||||
compiler.process code
|
||||
end
|
||||
|
||||
class MethodCompiler
|
||||
CompilerModules.each do |mod|
|
||||
include Typed.const_get( mod.camelize )
|
||||
include Vm.const_get( mod.camelize )
|
||||
end
|
||||
|
||||
def initialize( method = nil )
|
||||
@ -83,7 +83,7 @@ module Typed
|
||||
# Dispatches `code` according to it's class name, for class NameExpression
|
||||
# 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)
|
||||
name = code.class.name.split("::").last
|
||||
# Invoke a specific handler
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Assignment
|
||||
|
||||
def on_Assignment( statement )
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
# collection of the simple ones, int and strings and such
|
||||
|
||||
module BasicValues
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module CallSite
|
||||
|
||||
def on_CallSite( statement )
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
|
||||
module Collections
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module FieldAccess
|
||||
|
||||
def on_FieldAccess statement
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module IfStatement
|
||||
|
||||
# an if evaluates the condition and jumps to the true block if true
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module NameExpression
|
||||
|
||||
# attr_reader :name
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module OperatorExpression
|
||||
|
||||
def on_OperatorExpression statement
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module ReturnStatement
|
||||
|
||||
def on_ReturnStatement statement
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module StatementList
|
||||
def on_Statements statement
|
||||
process_all( statement.statements )
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module WhileStatement
|
||||
|
||||
def on_WhileStatement statement
|
@ -1,5 +1,5 @@
|
||||
# Base class for Expresssion and Statement
|
||||
module Typed
|
||||
module Vm
|
||||
|
||||
class Code ; end
|
||||
class Statement < Code ; end
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class Assignment < Statement
|
||||
attr_accessor :name , :value
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class IntegerExpression < Expression
|
||||
include ValuePrinter
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class CallSite < Expression
|
||||
attr_accessor :name , :receiver , :arguments
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class FieldAccess < Expression
|
||||
attr_accessor :receiver , :field
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class IfStatement < Statement
|
||||
attr_accessor :branch_type , :condition , :if_true , :if_false
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class OperatorExpression < Expression
|
||||
attr_accessor :operator , :left_expression , :right_expression
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class ReturnStatement < Statement
|
||||
attr_accessor :return_value
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
class Statements < Statement
|
||||
attr_accessor :statements
|
||||
def to_s
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
|
||||
def self.ast_to_code statement
|
||||
compiler = ToCode.new
|
||||
@ -122,7 +122,7 @@ module Typed
|
||||
|
||||
def on_assignment statement
|
||||
name , value = *statement
|
||||
w = Typed::Tree::Assignment.new()
|
||||
w = Vm::Tree::Assignment.new()
|
||||
w.name = process name
|
||||
w.value = process(value)
|
||||
w
|
@ -1,4 +1,4 @@
|
||||
module Typed
|
||||
module Vm
|
||||
module Tree
|
||||
class WhileStatement < Statement
|
||||
attr_accessor :branch_type , :condition , :statements
|
@ -1,6 +1,6 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Typed
|
||||
module Vm
|
||||
class TestWord < MiniTest::Test
|
||||
include Fragments
|
||||
|
||||
|
@ -12,7 +12,7 @@ module ParfaitTests
|
||||
def setup
|
||||
@stdout = ""
|
||||
@machine = Register.machine.boot
|
||||
Typed::Compiler.load_parfait
|
||||
Vm::Compiler.load_parfait
|
||||
end
|
||||
|
||||
def main
|
||||
|
@ -9,7 +9,7 @@ module BenchTests
|
||||
def setup
|
||||
@stdout = ""
|
||||
@machine = Register.machine.boot
|
||||
# Typed::Compiler.load_parfait
|
||||
# Vm::Compiler.load_parfait
|
||||
# most interesting parts saved as interger/word .soml in this dir
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ class HelloTest < MiniTest::Test
|
||||
|
||||
def check
|
||||
machine = Register.machine.boot
|
||||
Typed.compile( @input )
|
||||
Vm.compile( @input )
|
||||
objects = Register::Collector.collect_space
|
||||
machine.translate_arm
|
||||
writer = Elf::ObjectWriter.new(machine , objects )
|
||||
|
@ -22,8 +22,8 @@ require 'salama'
|
||||
|
||||
module Compiling
|
||||
def clean_compile(clazz_name , method_name , args , statements)
|
||||
compiler = Typed::MethodCompiler.new.create_method(clazz_name,method_name,args ).init_method
|
||||
compiler.process( Typed.ast_to_code( statements ) )
|
||||
compiler = Vm::MethodCompiler.new.create_method(clazz_name,method_name,args ).init_method
|
||||
compiler.process( Vm.ast_to_code( statements ) )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ module Register
|
||||
def setup
|
||||
Register.machine.boot
|
||||
do_clean_compile
|
||||
Typed.compile( @input )
|
||||
Vm.compile( @input )
|
||||
Collector.collect_space
|
||||
@interpreter = Interpreter.new
|
||||
@interpreter.start Register.machine.init
|
||||
|
@ -8,4 +8,4 @@ require_relative "melon/test_all"
|
||||
|
||||
require_relative "register/test_all"
|
||||
|
||||
require_relative "typed/test_all"
|
||||
require_relative "vm/test_all"
|
||||
|
@ -5,8 +5,8 @@ module Register
|
||||
|
||||
def check
|
||||
Register.machine.boot unless Register.machine.booted
|
||||
compiler = Typed::MethodCompiler.new Parfait.object_space.get_main
|
||||
code = Typed.ast_to_code @input
|
||||
compiler = Vm::MethodCompiler.new Parfait.object_space.get_main
|
||||
code = Vm.ast_to_code @input
|
||||
assert code.to_s , @input
|
||||
produced = compiler.process( code )
|
||||
assert @output , "No output given"
|
||||
@ -37,8 +37,8 @@ module Register
|
||||
end
|
||||
def check_nil
|
||||
assert @expect , "No output given"
|
||||
compiler = Typed::MethodCompiler.new
|
||||
code = Typed.ast_to_code( @input )
|
||||
compiler = Vm::MethodCompiler.new
|
||||
code = Vm.ast_to_code( @input )
|
||||
assert code.to_s , @input
|
||||
produced = compiler.process( code )
|
||||
produced = Parfait.object_space.get_main.instructions
|
@ -4,8 +4,8 @@ class ToCodeTest < MiniTest::Test
|
||||
include AST::Sexp
|
||||
|
||||
def check clazz
|
||||
tree = Typed.ast_to_code @statement
|
||||
assert_equal tree.class , Typed::Tree.const_get( clazz )
|
||||
tree = Vm.ast_to_code @statement
|
||||
assert_equal tree.class , Vm::Tree.const_get( clazz )
|
||||
end
|
||||
|
||||
def test_field_access
|
Loading…
Reference in New Issue
Block a user