Permalink
Browse files

fixes and what not

  • Loading branch information...
charliesome committed Apr 7, 2012
1 parent 53eee05 commit e47da9c52bb0fafba1775f409fb2f96972cbb62a
Showing with 17 additions and 14 deletions.
  1. +7 −6 Makefile
  2. +2 −1 lib/d16cc/compiler.rb
  3. +5 −5 lib/d16cc/node_compiler.rb
  4. +3 −2 lib/d16cc/scope.rb
View
@@ -1,13 +1,14 @@
.SUFFIXES: .c .s
.c.s:
- ./compile $< > $@
+ @echo "dc16cc $<"
+ @./compile $< > $@
-%.bin: %.s
- #./as16 $< | grep -Pv "^(LABEL|LINKED)" | ruby -e 'puts STDIN.read.split' > $@
- ./dasm $< temp.bin
- ruby -e 'File.open("temp.bin", "rb") { |f| f.read }.bytes.each_slice(2) { |a,b| printf("%02x%02x\n", b, a) }' > $@
- rm temp.bin
+%.bin: %.s Makefile
+ @echo "dasm $<"
+ @./dasm $< temp.bin
+ @ruby -e 'File.open("temp.bin", "rb") { |f| f.read }.bytes.each_slice(2) { |a,b| printf("%02x%02x\n", b, a) }' > $@
+ @rm temp.bin
clean:
rm -f *.s
View
@@ -12,7 +12,8 @@ def <<(line)
end
def to_s
- [":#{name}", *lines.map { |l| " #{l}" }].join "\n"
+ # SET A,A is a workaround for noname--'s assembler which outputs 0x000F if a label is on its own line
+ [":#{name} SET A,A", *lines.map { |l| " #{l}" }].join "\n"
end
end
View
@@ -51,10 +51,10 @@ def local_ref(local, offset = 0)
end
def int_to_words(int, type)
- words = [int % 65536, (int / 65536) % 65536]
+ words = [int % 65536, (int / 65536) % 65536].reverse.drop_while(&:zero?).reverse
if words.size > type.size
warn! node, "Overflow in implicit constant conversion"
- word.take type.size
+ words.take type.size
else
words + [0] * (type.size - words.size)
end
@@ -286,11 +286,11 @@ def If
compile_node node.then
if node.else
compiler.section << "SET PC, #{end_label}"
- compiler.section << ":#{else_label}"
+ compiler.section << ":#{else_label} SET A,A"
compile_node node.else
- compiler.section << ":#{end_label}"
+ compiler.section << ":#{end_label} SET A,A"
else
- compiler.section << ":#{else_label}"
+ compiler.section << ":#{else_label} SET A,A"
end
end
end
View
@@ -47,8 +47,9 @@ def set_local(local)
end
def declare(name, type)
- set_local Local.new self, name, type, @size
- @size += type.size
+ set_local(Local.new(self, name, type, @size)).tap do
+ @size += type.size
+ end
end
def [](name)

0 comments on commit e47da9c

Please sign in to comment.