Skip to content

Commit

Permalink
Added basic test of STDIN, and hacky first version of IO#getc
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarh committed Jan 5, 2014
1 parent d24d56b commit 54a0c13
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion features/compiler.feature
Expand Up @@ -37,6 +37,7 @@ Feature: Compiler
| inputs/06print.rb | outputs/06print.txt | Basic print/puts support |
| inputs/interpolate.rb | outputs/interpolate.txt | Simple string interpolation |
| inputs/div.rb | outputs/div.txt | Repeated divs to check register alloc. |
| inputs/stdout.rb | outputs/stdout.txt | Test basic STDIN/STDOUT |
| inputs/stdout.rb | outputs/stdout.txt | Test basic STDOUT |
| inputs/stdin.rb | outputs/stdin.txt | Test basic STDIN |


1 change: 1 addition & 0 deletions features/inputs/stdin.rb
@@ -0,0 +1 @@
puts STDIN.getc
1 change: 1 addition & 0 deletions features/outputs/stdin.txt
@@ -0,0 +1 @@
116
2 changes: 1 addition & 1 deletion features/step_definitions/compiler_steps.rb
Expand Up @@ -37,7 +37,7 @@
Tempfile.open('ruby-compiler') do |exe|
STDERR.puts "Asm file is in #{tmp.path}.s"
`gcc -gstabs -o #{exe.path}-binary #{tmp.path}.s ./runtime.o`
@output = `#{exe.path}-binary`
@output = `echo test | #{exe.path}-binary`
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions lib/core/io.rb
@@ -1,11 +1,31 @@

class IO < Object
def initialize
# %s(puts "IO.new")
end

def getc
c = 0
tmp = 0

# FIXME: This code is specific to a 32 bit little endian
# arch, and is also horribly inefficient because we don't
# have an easy way of getting the address of a stack allocated
# variable.
%s(do
(assign tmp (malloc 4))
(assign (index tmp 0) 0)
(read 0 tmp 1)
(assign c (__get_fixnum (index tmp 0)))
(free tmp)
)
c
end

def file?
end

def path
end

end

0 comments on commit 54a0c13

Please sign in to comment.