gets rid of soml-parser completely

This commit is contained in:
Torsten Ruger
2016-12-08 20:13:08 +02:00
parent 4cd979e3e9
commit ca4bdcc528
21 changed files with 26 additions and 65 deletions

View File

@ -1,10 +1,9 @@
require "register/padding"
require "register/positioned"
require "typed/parfait"
require "register/machine"
require "typed/compiler"
require "typed/parfait"
require "register/machine"
class Fixnum
def fits_u8?

View File

@ -18,10 +18,10 @@ module Register
def div10 context
s = "div_10"
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) )
const = compiler.process( Soml::IntegerExpression.new(1) )
me = compiler.process( Typed::NameExpression.new( :self) )
tmp = compiler.process( Typed::NameExpression.new( :self) )
q = compiler.process( Typed::NameExpression.new( :self) )
const = compiler.process( Typed::IntegerExpression.new(1) )
# int tmp = self >> 1
compiler.add_code Register.op( s , ">>" , tmp , const)
# int q = self >> 2

View File

@ -13,7 +13,7 @@ module Register
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) )
me = compiler.process( Typed::NameExpression.new( :self) )
# Load the argument
index = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )
@ -31,7 +31,7 @@ module Register
{:index => :Integer, :value => :Object} ).init_method
source = "set_internal_word"
#Load self by "calling" on_name
me = compiler.process( Soml::NameExpression.new( :self) )
me = compiler.process( Typed::NameExpression.new( :self) )
# Load the index
index = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )

View File

@ -20,7 +20,7 @@ module Register
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) )
me = compiler.process( Typed::NameExpression.new( :self) )
# Load the argument
index = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )
@ -39,7 +39,7 @@ module Register
{:index => :Integer, :value => :Integer } ).init_method
source = "set_internal_word"
#Load self by "calling" on_name
me = compiler.process( Soml::NameExpression.new( :self) )
me = compiler.process( Typed::NameExpression.new( :self) )
# Load the index
index = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )

View File

@ -19,7 +19,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?(Soml::Code)
raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(Typed::Code)
end
attr_reader :source

View File

@ -1,5 +1,6 @@
require 'parslet/convenience'
require_relative "collector"
module Register
# The Register Machine is an abstraction of the register level. This is seperate from the
# actual assembler level to allow for several cpu architectures.

View File

@ -2,7 +2,8 @@ require 'parslet'
require "logging"
require "elf/object_writer"
require 'soml-parser'
require "ast"
AST::Node.class_eval do
def first
children.first

View File

@ -1,11 +0,0 @@
class Class < Object
field List instance_methods
field Type instance_type
field Word name
field Word super_class_name
Word get_name()
return self.name
end
end

View File

@ -1,88 +0,0 @@
class Integer < Value
int as_char()
if_plus( self - 9)
return 32
else
return 48 + self
end
end
int div10_soml()
int tmp = self >> 1
int q = self >> 2
q = q + tmp
tmp = q >> 4
q = q + tmp
tmp = q >> 8
q = q + tmp
tmp = q >> 16
q = q + tmp
q = q >> 3
int r = q * 10
r = self - r
r = r + 6
r = r >> 4
return q + r
end
Word as_string(Word str)
if_minus( self - 10 )
int num = as_char()
str = str.push_char( num )
else
int rest = self.div10()
str = rest.as_string( str )
rest = rest * 10
rest = self - rest
str = rest.as_string(str)
end
return str
end
Word to_s()
Word start = " "
start.set_length(0)
return as_string( start )
end
int puti()
Word str = self.to_s()
str.putstring()
return self
end
int mod4()
return self & 3
end
int fibr( )
if_plus( self - 2 )
int tmp
tmp = self - 1
int a = tmp.fibr( )
tmp = self - 2
int b = tmp.fibr( )
return a + b
else
return self
end
end
int fibw( )
int result = 1
int a = 0
int b = 1
int i = 2
while_plus( self - i )
result = a + b
a = b
b = result
i = i + 1
end
return result
end
end

View File

@ -1,3 +0,0 @@
class Message < Object
end

View File

@ -1,17 +0,0 @@
class Object
Type get_type()
return self.type
end
Class get_class()
Type l = self.type
return l.object_class
end
Word get_class_name()
Type l = self.type
Class c = l.object_class
return c.name
end
end

View File

@ -1,6 +0,0 @@
class Type < Object
field Class object_class
field List instance_methods
field Integer indexed_length
end

View File

@ -1,29 +0,0 @@
class Word < Object
int _internal_index(int index)
return index + 11
end
int get_char_at(int index)
index = _internal_index(index)
return get_internal_byte(index)
end
int set_length(int i)
set_internal_word( 2 , i)
return i
end
int set_char_at( int index , int val)
index = _internal_index(index)
return set_internal_byte(index , val)
end
Word push_char(int char)
int index = self.char_length + 1
self.set_length(index)
set_char_at(index , char)
return self
end
end

View File

@ -32,7 +32,7 @@ module Typed
# Helper function to create a new compiler and compie the statement(s)
def self.compile statement
compiler = Compiler.new
code = Soml.ast_to_code statement
code = Typed.ast_to_code statement
compiler.process code
end
@ -51,7 +51,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 [Soml::Code, nil] code
# @param [Typed::Code, nil] code
def process(code)
name = code.class.name.split("::").last
# Invoke a specific handler
@ -173,23 +173,11 @@ module Typed
raise "space is a reserved name" if name == :space
name
end
# load the soml files from parfait directory
# Need to remove this and put it back into ruby code
def self.load_parfait
["word","class","type","message" ,"integer", "object"].each do |o|
str = File.open(File.expand_path("parfait/#{o}.soml", File.dirname(__FILE__))).read
syntax = Parser::Salama.new.parse_with_debug(str, reporter: Parslet::ErrorReporter::Deepest.new)
parts = Parser::Transform.new.apply(syntax)
code = Soml.ast_to_code parts
self.new.process( code )
end
end
end
end
require_relative "ast_helper"
require_relative "ast/code"
require_relative "compiler/assignment"
require_relative "compiler/basic_values"
require_relative "compiler/call_site"

View File

@ -9,7 +9,7 @@ module Typed
name_s = no_space( statement.name.value )
@method.ensure_local( name_s, statement.type ) unless( @method.has_arg(name_s))
# if there is a value assigned, process it as am assignemnt statement (kind of call on_assign)
process( Soml::Assignment.new(statement.name , statement.value ) ) if statement.value
process( Typed::Assignment.new(statement.name , statement.value ) ) if statement.value
return nil
end
end