get thnads tests to work

This commit is contained in:
Torsten Ruger 2014-04-24 15:53:48 +03:00
parent d90ea3dd26
commit 601dc22b2e
11 changed files with 49 additions and 49 deletions

View File

@ -1,3 +1,9 @@
# parslet is assumed to be checked out at the same level as crystal for now
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', ".." , "parslet",'lib'))
require 'parslet'
require "asm/stack_instruction"
require "asm/arm_assembler"
require "elf/object_writer"
require 'vm/parser'

View File

@ -2,7 +2,7 @@ require 'java'
java_import java.lang.System
java_import java.io.PrintStream
module Thnad
module Vm
module Builtins
def add_builtins
public_static_method 'print', [], int, int do

View File

@ -1,13 +1,13 @@
require 'bitescript'
require 'thnad/parser'
require 'thnad/transform'
require 'thnad/builtins'
require 'vm/parser'
require 'vm/transform'
require 'vm/builtins'
module Thnad
module Vm
class Compiler
def initialize(filename)
@filename = filename
@classname = File.basename(@filename, '.thnad')
@classname = File.basename(@filename, '.vm')
end
def compile

View File

@ -1,4 +1,4 @@
module Thnad
module Vm
class Number < Struct.new :value
def eval(context, builder)
builder.ldc value

View File

@ -1,6 +1,5 @@
require 'parslet'
module Thnad
module Vm
class Parser < Parslet::Parser
rule(:name) { match('[a-z]').repeat(1).as(:name) >> space? }
rule(:number) { match('[0-9]').repeat(1).as(:number) >> space? }

View File

@ -1,7 +1,7 @@
require 'parslet'
require 'thnad/nodes'
require 'vm/nodes'
module Thnad
module Vm
class Transform < Parslet::Transform
rule(:number => simple(:value)) { Number.new(value.to_i) }
rule(:name => simple(:name)) { Name.new(name.to_s) }

View File

@ -3,10 +3,10 @@ $: << File.expand_path(File.dirname(__FILE__))
require 'minitest/autorun'
require 'minitest/spec'
require 'thnad/nodes'
require 'vm/nodes'
require 'fake_builder'
include Thnad
include Vm
describe 'Nodes' do
before do
@ -15,7 +15,7 @@ describe 'Nodes' do
end
it 'emits a number' do
input = Thnad::Number.new 42
input = Vm::Number.new 42
expected = <<HERE
ldc 42
HERE
@ -27,8 +27,8 @@ HERE
it 'emits a function call' do
@context[:params] = ['foo']
input = Thnad::Funcall.new 'baz', [Thnad::Number.new(42),
Thnad::Name.new('foo')]
input = Vm::Funcall.new 'baz', [Vm::Number.new(42),
Vm::Name.new('foo')]
expected = <<HERE
ldc 42
iload 0
@ -41,10 +41,10 @@ HERE
end
it 'emits a conditional' do
input = Thnad::Conditional.new \
Thnad::Number.new(0),
Thnad::Number.new(42),
Thnad::Number.new(667)
input = Vm::Conditional.new \
Vm::Number.new(0),
Vm::Number.new(42),
Vm::Number.new(667)
expected = <<HERE
ldc 0
ifeq else
@ -60,10 +60,10 @@ HERE
end
it 'emits a function definition' do
input = Thnad::Function.new \
input = Vm::Function.new \
'foo',
Thnad::Name.new('x'),
Thnad::Number.new(5)
Vm::Name.new('x'),
Vm::Number.new(5)
expected = <<HERE
public_static_method foo, int, int

View File

@ -1,14 +1,11 @@
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'minitest/autorun'
require_relative 'helper'
require 'minitest/spec'
require 'thnad/parser'
include Thnad
include Vm
describe Parser do
before do
@parser = Thnad::Parser.new
@parser = Vm::Parser.new
end
it 'reads a number' do

View File

@ -1,26 +1,24 @@
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'minitest/autorun'
require_relative 'helper'
require 'minitest/spec'
require 'thnad/transform'
require 'vm/transform'
include Thnad
include Vm
describe Transform do
before do
@transform = Thnad::Transform.new
@transform = Vm::Transform.new
end
it 'transforms a number' do
input = {:number => '42'}
expected = Thnad::Number.new(42)
expected = Vm::Number.new(42)
@transform.apply(input).must_equal expected
end
it 'transforms a name' do
input = {:name => 'foo'}
expected = Thnad::Name.new('foo')
expected = Vm::Name.new('foo')
@transform.apply(input).must_equal expected
end
@ -28,8 +26,8 @@ describe Transform do
it 'transforms an argument list' do
input = {:args => [{:arg => {:number => '42'}},
{:arg => {:name => 'foo'}}]}
expected = [Thnad::Number.new(42),
Thnad::Name.new('foo')]
expected = [Vm::Number.new(42),
Vm::Name.new('foo')]
@transform.apply(input).must_equal expected
end
@ -37,7 +35,7 @@ describe Transform do
it 'transforms a single-argument function call' do
input = {:funcall => {:name => 'foo'},
:args => [{:arg => {:number => '42'}}]}
expected = Thnad::Funcall.new 'foo', [Thnad::Number.new(42)]
expected = Vm::Funcall.new 'foo', [Vm::Number.new(42)]
@transform.apply(input).must_equal expected
end
@ -46,8 +44,8 @@ describe Transform do
input = {:funcall => {:name => 'baz'},
:args => [{:arg => {:number => '42'}},
{:arg => {:name => 'foo'}}]}
expected = Thnad::Funcall.new 'baz', [Thnad::Number.new(42),
Thnad::Name.new('foo')]
expected = Vm::Funcall.new 'baz', [Vm::Number.new(42),
Vm::Name.new('foo')]
@transform.apply(input).must_equal expected
end
@ -56,10 +54,10 @@ describe Transform do
input = {:cond => {:number => '0'},
:if_true => {:body => {:number => '42'}},
:if_false => {:body => {:number => '667'}}}
expected = Thnad::Conditional.new \
Thnad::Number.new(0),
Thnad::Number.new(42),
Thnad::Number.new(667)
expected = Vm::Conditional.new \
Vm::Number.new(0),
Vm::Number.new(42),
Vm::Number.new(667)
@transform.apply(input).must_equal expected
end
@ -68,10 +66,10 @@ describe Transform do
input = {:func => {:name => 'foo'},
:params => {:param => {:name => 'x'}},
:body => {:number => '5'}}
expected = Thnad::Function.new \
expected = Vm::Function.new \
'foo',
[Thnad::Name.new('x')],
Thnad::Number.new(5)
[Vm::Name.new('x')],
Vm::Number.new(5)
@transform.apply(input).must_equal expected
end