From d3a0a6314baac790b9b15909580f83646eccb28a Mon Sep 17 00:00:00 2001 From: inglorion Date: Mon, 17 Sep 2012 05:56:41 -0700 Subject: [PATCH] Added test case for auto-words and made it pass on amd64 and i386. --- lib/voodoo/validator.rb | 2 +- test/Makefile | 6 +-- test/auto-words.out | 9 +++++ test/auto-words.voo | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 test/auto-words.out create mode 100644 test/auto-words.voo diff --git a/lib/voodoo/validator.rb b/lib/voodoo/validator.rb index 4b05f54..08781d5 100644 --- a/lib/voodoo/validator.rb +++ b/lib/voodoo/validator.rb @@ -6,7 +6,7 @@ module Voodoo BINOPS = [:add, :and, :asr, :bsr, :div, :'get-byte', :'get-word', :mod, :mul, :or, :rol, :ror, :shl, :shr, :sub, :xor] # Expressions that take a single parameter - UNOPS = [:'auto-bytes', :not] + UNOPS = [:'auto-bytes', :'auto-words', :not] # Expressions that take zero or more parameters VARARG_EXPRS = [:call, :'tail-call'] # Symbols that may occur as the first word of an expression diff --git a/test/Makefile b/test/Makefile index 36555d2..3bc34c0 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,9 +3,9 @@ include ../Makefile.cfg NASM ?= nasm VOODOOC ?= env RUBYLIB=$(PWD)/../lib:$(RUBYLIB) ../bin/voodooc -TARGETS = auto-bytes at block bitwise bytes call div else-if fact goto hello \ - if many-vars mod mul plusminus raw rotate set-at set-byte set-word \ - shift tail-calls vtable gcd +TARGETS = auto-bytes auto-words at block bitwise bytes call div else-if fact \ + goto hello if many-vars mod mul plusminus raw rotate set-at set-byte \ + set-word shift tail-calls vtable gcd all : $(TARGETS) diff --git a/test/auto-words.out b/test/auto-words.out new file mode 100644 index 0000000..1b62884 --- /dev/null +++ b/test/auto-words.out @@ -0,0 +1,9 @@ +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 +48 49 50 0 +72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 +42 +19 +91 +17 +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 diff --git a/test/auto-words.voo b/test/auto-words.voo new file mode 100644 index 0000000..ee7f570 --- /dev/null +++ b/test/auto-words.voo @@ -0,0 +1,103 @@ +#### Test program for auto-words + +section data + +print_word_space_fmt: +string "%d \x00" + +print_int_fmt: +string "%d\n\x00" + +section functions +export main +import printf + +align +print_words: +function words n + # Prints n words. + let max sub n 1 + let i 0 + let x 0 +print_words_loop: + iflt i max + set x get-word words i + call printf print_word_space_fmt x + set i add i 1 + goto print_words_loop + end if + set x get-word words max + call printf print_int_fmt x + return 0 +end function + +align +test: +function + let words auto-words 17 + let i 0 +test_loop: + iflt i 17 + set-word words i i + set i add i 1 + goto test_loop + end if + call print_words words 17 + call test_pass words + + block + let a 42 + let more-words auto-words 19 + let b 0 + let c 72 +test_loop1: + iflt b 19 + set-word more-words b c + set b add b 1 + set c add c 1 + goto test_loop1 + end if + call print_words more-words 19 + call printf print_int_fmt a + call printf print_int_fmt b + call printf print_int_fmt c + end block + + call printf print_int_fmt i + call print_words words 17 + + # Allocate memory in a block inside a loop. The memory + # should be freed on each iteration, so this should not + # run out of memory. + set i 0 +test_loop2: + iflt i 262144 + block + set words auto-words 16384 + end block + set i add i 1 + goto test_loop2 + end if + + return 0 +end function + +align +test_pass: +function text + call print_words text 17 + let words auto-words 4 + set-word words 0 48 + set-word words 1 49 + set-word words 2 50 + set-word words 3 0 + call print_words words 4 + return 0 +end function + +align +main: +function argc argv + call test + return 0 +end function -- 2.11.4.GIT