mirror of
https://github.com/samsonjs/compiler.git
synced 2026-03-25 08:45:52 +00:00
updated .gitignore (new test dir)
This commit is contained in:
parent
b8581b8b24
commit
574a793638
8 changed files with 17 additions and 188 deletions
22
.gitignore
vendored
22
.gitignore
vendored
|
|
@ -1,5 +1,17 @@
|
|||
test
|
||||
*.o
|
||||
test*.asm
|
||||
test_lt
|
||||
test_print
|
||||
test/*.o
|
||||
test/*.asm
|
||||
test/test_big
|
||||
test/test_lt
|
||||
test/test_gt
|
||||
test/test_ge
|
||||
test/test_le
|
||||
test/test_eq
|
||||
test/test_neq
|
||||
test/test_while
|
||||
test/test_if
|
||||
test/test_until
|
||||
test/test_repeat
|
||||
test/test_do
|
||||
test/test_for
|
||||
test/test_break
|
||||
test/test_print
|
||||
27
Makefile
27
Makefile
|
|
@ -1,27 +0,0 @@
|
|||
lt: test.rb test_lt.code
|
||||
ruby test.rb test_lt.code > test_lt.asm
|
||||
nasm -f elf -g -o test_lt.o test_lt.asm
|
||||
ld -o test_lt test_lt.o
|
||||
# $? indicates success as per unix convention
|
||||
./test_lt
|
||||
|
||||
print: test.rb test_print.code
|
||||
ruby test.rb test_print.code > test_print.asm
|
||||
nasm -f elf -g -o test_print.o test_print.asm
|
||||
ld -o test_print test_print.o
|
||||
# $? indicates success as per unix convention
|
||||
./test_print
|
||||
|
||||
build: test.rb test.code
|
||||
ruby test.rb test.code > test.asm
|
||||
nasm -f elf -g -o test.o test.asm
|
||||
ld -o test test.o
|
||||
# $? indicates success as per unix convention
|
||||
./test
|
||||
|
||||
clean:
|
||||
@rm -f test*.o
|
||||
@rm -f test test_lt test_print
|
||||
@rm -f test*.asm
|
||||
@rm -f *.o
|
||||
|
||||
65
test.code
65
test.code
|
|
@ -1,65 +0,0 @@
|
|||
a=1
|
||||
print a
|
||||
aa=10
|
||||
print aa
|
||||
somethinglong=65536
|
||||
print somethinglong
|
||||
x=5*(3-5)
|
||||
print x
|
||||
c=1- -a
|
||||
print c
|
||||
g=1* -1
|
||||
print g
|
||||
h=x*2+2
|
||||
print h
|
||||
j=h-27/9
|
||||
k=j-8/2
|
||||
m=k-4*(5+5+5)
|
||||
n=m+85
|
||||
|
||||
if 1
|
||||
x=3
|
||||
if 1 c=4
|
||||
end
|
||||
end
|
||||
if 1x=3 if 1c=4 end end
|
||||
|
||||
if 1 > 2
|
||||
x=3
|
||||
if 1 c=4
|
||||
end
|
||||
else
|
||||
x=2
|
||||
end
|
||||
|
||||
while 0
|
||||
while a < 10
|
||||
a = a + 1
|
||||
end
|
||||
end
|
||||
|
||||
until a == 0
|
||||
a = a - 1
|
||||
if -1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
cc = c
|
||||
repeat
|
||||
cc = cc * 2
|
||||
if cc == 32
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
s=0
|
||||
for x = 1 to 5
|
||||
s = s + x
|
||||
end
|
||||
|
||||
do 10
|
||||
a = a * a
|
||||
end
|
||||
|
||||
xitcode=a-a
|
||||
54
test.rb
54
test.rb
|
|
@ -1,54 +0,0 @@
|
|||
require 'compiler'
|
||||
require 'stringio'
|
||||
|
||||
def error(msg) STDERR.puts(msg) end
|
||||
|
||||
def parse(input)
|
||||
compiler = Compiler.new(input)
|
||||
compiler.parse # tuple of [data, bss, code]
|
||||
|
||||
rescue ParseError => e
|
||||
error("[error] #{e.message}")
|
||||
error("[context] #{e.context}")
|
||||
# error("Aborting!")
|
||||
error(e.caller)
|
||||
exit(1)
|
||||
end
|
||||
|
||||
def interpolate(template, data)
|
||||
data.inject(template) do |template, mapping|
|
||||
token, replacement = *mapping
|
||||
template.sub("{#{token}}", replacement)
|
||||
end
|
||||
end
|
||||
|
||||
def main(arg)
|
||||
input = if File.readable?(arg)
|
||||
File.open(arg)
|
||||
else
|
||||
# StringIO.new("5*(3-5)*2+2-9/3-8/2-4*(5+5+5)\n")
|
||||
StringIO.new("abc=999\nabc-888\n")
|
||||
end
|
||||
data, bss, code = *parse(input)
|
||||
template = File.read("template.asm")
|
||||
asm = interpolate(template, :data => data, :bss => bss, :code => code)
|
||||
STDOUT.puts(asm)
|
||||
end
|
||||
|
||||
Blacklist = [:eof?, :many, :whitespace?, :op_char?, :skip_whitespace,
|
||||
:any_whitespace?, :skip_any_whitespace, :emit, :indent,
|
||||
:newline?, :digit?, :alpha?, :newline?, :get_char,
|
||||
:get_op, :op?, :alnum?, :get_name, :get_number]
|
||||
|
||||
if false
|
||||
set_trace_func proc { |event, file, line, id, binding, classname|
|
||||
if classname == Compiler &&
|
||||
event != 'line' &&
|
||||
!Blacklist.include?(id) &&
|
||||
id.to_s[0,4] != 'x86_'
|
||||
printf "%8s %-2d %10s\n", event, line, id
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
main(ARGV[0].to_s)
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
x = 1 < 3
|
||||
y = 3 < 1
|
||||
z = 1 < 1
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
p 0
|
||||
p 1
|
||||
p -1
|
||||
p 123
|
||||
p -123
|
||||
p 4096
|
||||
p -4096
|
||||
xitcode=0
|
||||
|
|
@ -1 +0,0 @@
|
|||
(5*(3 - 5)*2 - 33 - 9/3 - 8/2 + 4*(5 + 5 + 5)) + (4*5 - 21/2 - 15 + 5)
|
||||
25
testi.rb
25
testi.rb
|
|
@ -1,25 +0,0 @@
|
|||
require 'interpreter'
|
||||
require 'stringio'
|
||||
|
||||
def error(msg) STDERR.puts(msg) end
|
||||
|
||||
def eval(input)
|
||||
interpreter = Interpreter.new(input)
|
||||
interpreter.run
|
||||
|
||||
rescue ParseError => e
|
||||
error("[error] #{e.message}")
|
||||
error("Aborting!")
|
||||
exit(1)
|
||||
end
|
||||
|
||||
def main(arg)
|
||||
input = if File.readable?(arg)
|
||||
File.open(arg)
|
||||
else
|
||||
STDIN
|
||||
end
|
||||
puts(eval(input))
|
||||
end
|
||||
|
||||
main(ARGV[0].to_s)
|
||||
Loading…
Reference in a new issue