move compiler to typed
starting to get rid of soml, bit by bit
This commit is contained in:
parent
c3a28d2abc
commit
da553f996f
@ -3,7 +3,7 @@ require "register/positioned"
|
|||||||
require "typed/parfait"
|
require "typed/parfait"
|
||||||
require "register/machine"
|
require "register/machine"
|
||||||
|
|
||||||
require "soml/compiler"
|
require "typed/compiler"
|
||||||
|
|
||||||
|
|
||||||
class Fixnum
|
class Fixnum
|
||||||
|
@ -6,18 +6,18 @@ module Register
|
|||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
|
||||||
def mod4 context
|
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
|
return compiler.method
|
||||||
end
|
end
|
||||||
def putint context
|
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
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def div10 context
|
def div10 context
|
||||||
s = "div_10"
|
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) )
|
me = compiler.process( Soml::NameExpression.new( :self) )
|
||||||
tmp = compiler.process( Soml::NameExpression.new( :self) )
|
tmp = compiler.process( Soml::NameExpression.new( :self) )
|
||||||
q = compiler.process( Soml::NameExpression.new( :self) )
|
q = compiler.process( Soml::NameExpression.new( :self) )
|
||||||
|
@ -7,7 +7,7 @@ module Register
|
|||||||
# so it is responsible for initial setup
|
# so it is responsible for initial setup
|
||||||
def __init__ context
|
def __init__ context
|
||||||
source = "__init__"
|
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
|
# no method enter or return (automatically added), remove
|
||||||
new_start = Label.new(source , source )
|
new_start = Label.new(source , source )
|
||||||
compiler.method.instructions = new_start
|
compiler.method.instructions = new_start
|
||||||
@ -34,7 +34,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def exit context
|
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 )
|
emit_syscall( compiler , :exit )
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
@ -10,7 +10,7 @@ module Register
|
|||||||
# return is stored in return_value
|
# return is stored in return_value
|
||||||
# (this method returns a new method off course, like all builtin)
|
# (this method returns a new method off course, like all builtin)
|
||||||
def get_internal_word context
|
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"
|
source = "get_internal_word"
|
||||||
#Load self by "calling" on_name
|
#Load self by "calling" on_name
|
||||||
me = compiler.process( Soml::NameExpression.new( :self) )
|
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
|
# self[index] = val basically. Index is the first arg , value the second
|
||||||
# no return
|
# no return
|
||||||
def set_internal_word context
|
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
|
{:index => :Integer, :value => :Object} ).init_method
|
||||||
source = "set_internal_word"
|
source = "set_internal_word"
|
||||||
#Load self by "calling" on_name
|
#Load self by "calling" on_name
|
||||||
|
@ -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 = Soml::Compiler.new.create_method(:Space , :main ).init_method
|
compiler = Typed::Compiler.new.create_method(:Space , :main ).init_method
|
||||||
return compiler.method
|
return compiler.method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module Register
|
|||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
|
||||||
def putstring context
|
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 )
|
compiler.add_code Register.get_slot( "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)
|
||||||
@ -17,7 +17,7 @@ module Register
|
|||||||
# self[index] basically. Index is the first arg > 0
|
# self[index] basically. Index is the first arg > 0
|
||||||
# return (and word sized int) is stored in return_value
|
# return (and word sized int) is stored in return_value
|
||||||
def get_internal_byte context
|
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"
|
source = "get_internal_word"
|
||||||
#Load self by "calling" on_name
|
#Load self by "calling" on_name
|
||||||
me = compiler.process( Soml::NameExpression.new( :self) )
|
me = compiler.process( Soml::NameExpression.new( :self) )
|
||||||
@ -35,7 +35,7 @@ module Register
|
|||||||
# value the second
|
# value the second
|
||||||
# no return
|
# no return
|
||||||
def set_internal_byte context
|
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
|
{:index => :Integer, :value => :Integer } ).init_method
|
||||||
source = "set_internal_word"
|
source = "set_internal_word"
|
||||||
#Load self by "calling" on_name
|
#Load self by "calling" on_name
|
||||||
|
@ -74,7 +74,7 @@ module Register
|
|||||||
syntax = Parser::Salama.new.parse_with_debug(bytes, reporter: Parslet::ErrorReporter::Deepest.new)
|
syntax = Parser::Salama.new.parse_with_debug(bytes, reporter: Parslet::ErrorReporter::Deepest.new)
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
#puts parts.inspect
|
#puts parts.inspect
|
||||||
Soml.compile( parts )
|
Typed.compile( parts )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
# Compiling is the conversion of the AST into 2 things:
|
# Compiling is the conversion of the AST into 2 things:
|
||||||
# - code (ie sequences of Instructions inside Methods)
|
# - code (ie sequences of Instructions inside Methods)
|
||||||
# - an object graph containing all the Methods, their classes and Constants
|
# - an object graph containing all the Methods, their classes and Constants
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_Assignment statement
|
def on_Assignment statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
# collection of the simple ones, int and strings and such
|
# collection of the simple ones, int and strings and such
|
||||||
|
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_CallSite statement
|
def on_CallSite statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_ClassField statement
|
def on_ClassField statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_ClassStatement statement
|
def on_ClassStatement statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
# attr_reader :values
|
# attr_reader :values
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_FieldAccess statement
|
def on_FieldAccess statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_FunctionStatement statement
|
def on_FunctionStatement statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
# 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
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
# attr_reader :name
|
# attr_reader :name
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_OperatorExpression statement
|
def on_OperatorExpression statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_ReturnStatement statement
|
def on_ReturnStatement statement
|
@ -1,4 +1,5 @@
|
|||||||
module Soml
|
module Typed
|
||||||
|
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_statements statement
|
def on_statements statement
|
@ -1,4 +1,4 @@
|
|||||||
module Soml
|
module Typed
|
||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
|
|
||||||
def on_WhileStatement statement
|
def on_WhileStatement statement
|
@ -1,7 +1,7 @@
|
|||||||
require_relative '../../helper'
|
require_relative '../../helper'
|
||||||
require 'parslet/convenience'
|
require 'parslet/convenience'
|
||||||
|
|
||||||
Soml::Compiler.class_eval do
|
Typed::Compiler.class_eval do
|
||||||
def set_main main
|
def set_main main
|
||||||
@clazz = Register.machine.space.get_class_by_name :Object
|
@clazz = Register.machine.space.get_class_by_name :Object
|
||||||
@method = main
|
@method = main
|
||||||
@ -23,7 +23,7 @@ module ExpressionHelper
|
|||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
codes = Soml.ast_to_code parts
|
codes = Soml.ast_to_code parts
|
||||||
#puts parts.inspect
|
#puts parts.inspect
|
||||||
compiler = Soml::Compiler.new
|
compiler = Typed::Compiler.new
|
||||||
set_main(compiler)
|
set_main(compiler)
|
||||||
produced = compiler.process( codes )
|
produced = compiler.process( codes )
|
||||||
assert @output , "No output given"
|
assert @output , "No output given"
|
||||||
|
@ -22,7 +22,7 @@ module RuntimeTests
|
|||||||
|
|
||||||
def load_program
|
def load_program
|
||||||
@machine = Register.machine.boot
|
@machine = Register.machine.boot
|
||||||
Soml::Compiler.load_parfait
|
Typed::Compiler.load_parfait
|
||||||
@machine.parse_and_compile main()
|
@machine.parse_and_compile main()
|
||||||
@machine.collect
|
@machine.collect
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module ParfaitTests
|
|||||||
def setup
|
def setup
|
||||||
@stdout = ""
|
@stdout = ""
|
||||||
@machine = Register.machine.boot
|
@machine = Register.machine.boot
|
||||||
Soml::Compiler.load_parfait
|
Typed::Compiler.load_parfait
|
||||||
end
|
end
|
||||||
|
|
||||||
def main
|
def main
|
||||||
|
@ -9,7 +9,7 @@ module BenchTests
|
|||||||
def setup
|
def setup
|
||||||
@stdout = ""
|
@stdout = ""
|
||||||
@machine = Register.machine.boot
|
@machine = Register.machine.boot
|
||||||
Soml::Compiler.load_parfait
|
Typed::Compiler.load_parfait
|
||||||
end
|
end
|
||||||
|
|
||||||
def main
|
def main
|
||||||
|
@ -8,7 +8,7 @@ module Ticker
|
|||||||
syntax = Parser::Salama.new.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new)
|
syntax = Parser::Salama.new.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new)
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
#puts parts.inspect
|
#puts parts.inspect
|
||||||
Soml.compile( parts )
|
Typed.compile( parts )
|
||||||
machine.collect
|
machine.collect
|
||||||
@interpreter = Register::Interpreter.new
|
@interpreter = Register::Interpreter.new
|
||||||
@interpreter.start Register.machine.init
|
@interpreter.start Register.machine.init
|
||||||
|
Loading…
Reference in New Issue
Block a user