Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
namin committed Dec 14, 2011
0 parents commit 7677fae
Show file tree
Hide file tree
Showing 31 changed files with 2,337 additions and 0 deletions.
Binary file added docs/paper.pdf
Binary file not shown.
Binary file added docs/tutorial.pdf
Binary file not shown.
60 changes: 60 additions & 0 deletions tests/README
@@ -0,0 +1,60 @@

To run the tests, make sure that your compiler file is called
"compiler.scm", and that at the top of that file, you have:
(load "tests-driver.scm") ; this should come first
(load "tests-1.1-req.scm") ; and any other test files you may have.

Also, make sure that your compiler defines the function
compile-program that takes an expression and uses "emit" to emit the
appropriate instructions.

The tests-driver defines the procedure "test-all" that will run all
the tests provided, get the output, redirect it to a file "stst.s",
and invokes gcc on that file as well as the runtime.c file that you
should have written.

The tests-driver is written for [Petite] Chez Scheme 7. You can
obtain a copy of Petite Chez Scheme from:
http://www.scheme.com

The tests-driver also assumes that you have the GNU C compiler "gcc"
already setup and added to your pathname. How you do this depends
on your platform. If you have a different C compiler that you wish
to use, you can edit the tests-driver yourself (look for the
definition of the build procedure).

If all is well, then invoking petite on your compiler and typing
(test-all) should run all the tests as in the following sample
transcript.

$ petite compiler.scm
Petite Chez Scheme Version 7.0a
Copyright (c) 1985-2005 Cadence Research Systems

> (test-all)
test 0:#f ... ok
test 1:#t ... ok
test 2:() ... ok
test 3:0 ... ok
test 4:1 ... ok
test 5:-1 ... ok
test 6:2736 ... ok
test 7:-2736 ... ok
test 8:536870911 ... ok
test 9:-536870912 ... ok
test 10:#\nul ... ok
...
test 131:#\y ... ok
test 132:#\z ... ok
test 133:#\{ ... ok
test 134:#\| ... ok
test 135:#\} ... ok
test 136:#\~ ... ok
test 137:#\rubout ... ok
passed all 138 tests
>


Enjoy.

Abdulaziz Ghuloum <aghuloum@cs.indiana.edu>
12 changes: 12 additions & 0 deletions tests/tests-1.1-req.scm
@@ -0,0 +1,12 @@
(add-tests-with-string-output "integers"
[0 => "0\n"]
[1 => "1\n"]
[-1 => "-1\n"]
[10 => "10\n"]
[-10 => "-10\n"]
[2736 => "2736\n"]
[-2736 => "-2736\n"]
[536870911 => "536870911\n"]
[-536870912 => "-536870912\n"]
)

133 changes: 133 additions & 0 deletions tests/tests-1.2-req.scm
@@ -0,0 +1,133 @@
(add-tests-with-string-output "immediate constants"
[#f => "#f\n"]
[#t => "#t\n"]
[() => "()\n"]
; [#\nul => "#\\nul\n"]
; [#\001 => "#\\soh\n"]
; [#\002 => "#\\stx\n"]
; [#\003 => "#\\etx\n"]
; [#\004 => "#\\eot\n"]
; [#\005 => "#\\enq\n"]
; [#\006 => "#\\ack\n"]
; [#\bel => "#\\bel\n"]
; [#\backspace => "#\\bs\n"]
[#\tab => "#\\tab\n"]
[#\newline => "#\\newline\n"]
; [#\vt => "#\\vt\n"]
; [#\page => "#\\ff\n"]
[#\return => "#\\return\n"]
; [#\016 => "#\\so\n"]
; [#\017 => "#\\si\n"]
; [#\020 => "#\\dle\n"]
; [#\021 => "#\\dc1\n"]
; [#\022 => "#\\dc2\n"]
; [#\023 => "#\\dc3\n"]
; [#\024 => "#\\dc4\n"]
; [#\025 => "#\\nak\n"]
; [#\026 => "#\\syn\n"]
; [#\027 => "#\\etb\n"]
; [#\030 => "#\\can\n"]
; [#\031 => "#\\em\n"]
; [#\032 => "#\\sub\n"]
; [#\033 => "#\\esc\n"]
; [#\034 => "#\\fs\n"]
; [#\035 => "#\\gs\n"]
; [#\036 => "#\\rs\n"]
; [#\037 => "#\\us\n"]
[#\space => "#\\space\n"]
[#\! => "#\\!\n"]
[#\" => "#\\\"\n"]
[#\# => "#\\#\n"]
[#\$ => "#\\$\n"]
[#\% => "#\\%\n"]
[#\& => "#\\&\n"]
[#\' => "#\\'\n"]
[#\( => "#\\(\n"]
[#\) => "#\\)\n"]
[#\* => "#\\*\n"]
[#\+ => "#\\+\n"]
[#\, => "#\\,\n"]
[#\- => "#\\-\n"]
[#\. => "#\\.\n"]
[#\/ => "#\\/\n"]
[#\0 => "#\\0\n"]
[#\1 => "#\\1\n"]
[#\2 => "#\\2\n"]
[#\3 => "#\\3\n"]
[#\4 => "#\\4\n"]
[#\5 => "#\\5\n"]
[#\6 => "#\\6\n"]
[#\7 => "#\\7\n"]
[#\8 => "#\\8\n"]
[#\9 => "#\\9\n"]
[#\: => "#\\:\n"]
[#\; => "#\\;\n"]
[#\< => "#\\<\n"]
[#\= => "#\\=\n"]
[#\> => "#\\>\n"]
[#\? => "#\\?\n"]
[#\@ => "#\\@\n"]
[#\A => "#\\A\n"]
[#\B => "#\\B\n"]
[#\C => "#\\C\n"]
[#\D => "#\\D\n"]
[#\E => "#\\E\n"]
[#\F => "#\\F\n"]
[#\G => "#\\G\n"]
[#\H => "#\\H\n"]
[#\I => "#\\I\n"]
[#\J => "#\\J\n"]
[#\K => "#\\K\n"]
[#\L => "#\\L\n"]
[#\M => "#\\M\n"]
[#\N => "#\\N\n"]
[#\O => "#\\O\n"]
[#\P => "#\\P\n"]
[#\Q => "#\\Q\n"]
[#\R => "#\\R\n"]
[#\S => "#\\S\n"]
[#\T => "#\\T\n"]
[#\U => "#\\U\n"]
[#\V => "#\\V\n"]
[#\W => "#\\W\n"]
[#\X => "#\\X\n"]
[#\Y => "#\\Y\n"]
[#\Z => "#\\Z\n"]
[#\[ => "#\\[\n"]
[#\\ => "#\\\\\n"]
[#\] => "#\\]\n"]
[#\^ => "#\\^\n"]
[#\_ => "#\\_\n"]
[#\` => "#\\`\n"]
[#\a => "#\\a\n"]
[#\b => "#\\b\n"]
[#\c => "#\\c\n"]
[#\d => "#\\d\n"]
[#\e => "#\\e\n"]
[#\f => "#\\f\n"]
[#\g => "#\\g\n"]
[#\h => "#\\h\n"]
[#\i => "#\\i\n"]
[#\j => "#\\j\n"]
[#\k => "#\\k\n"]
[#\l => "#\\l\n"]
[#\m => "#\\m\n"]
[#\n => "#\\n\n"]
[#\o => "#\\o\n"]
[#\p => "#\\p\n"]
[#\q => "#\\q\n"]
[#\r => "#\\r\n"]
[#\s => "#\\s\n"]
[#\t => "#\\t\n"]
[#\u => "#\\u\n"]
[#\v => "#\\v\n"]
[#\w => "#\\w\n"]
[#\x => "#\\x\n"]
[#\y => "#\\y\n"]
[#\z => "#\\z\n"]
[#\{ => "#\\{\n"]
[#\| => "#\\|\n"]
[#\} => "#\\}\n"]
[#\~ => "#\\~\n"]
; [#\rubout => "#\\del\n"]
)
117 changes: 117 additions & 0 deletions tests/tests-1.3-req.scm
@@ -0,0 +1,117 @@



(add-tests-with-string-output "fxadd1"
[($fxadd1 0) => "1\n"]
[($fxadd1 -1) => "0\n"]
[($fxadd1 1) => "2\n"]
[($fxadd1 -100) => "-99\n"]
[($fxadd1 1000) => "1001\n"]
[($fxadd1 536870910) => "536870911\n"]
[($fxadd1 -536870912) => "-536870911\n"]
[($fxadd1 ($fxadd1 0)) => "2\n"]
[($fxadd1 ($fxadd1 ($fxadd1 ($fxadd1 ($fxadd1 ($fxadd1 12)))))) => "18\n"]
)

(add-tests-with-string-output "fixnum->char and char->fixnum"
[($fixnum->char 65) => "#\\A\n"]
[($fixnum->char 97) => "#\\a\n"]
[($fixnum->char 122) => "#\\z\n"]
[($fixnum->char 90) => "#\\Z\n"]
[($fixnum->char 48) => "#\\0\n"]
[($fixnum->char 57) => "#\\9\n"]
[($char->fixnum #\A) => "65\n"]
[($char->fixnum #\a) => "97\n"]
[($char->fixnum #\z) => "122\n"]
[($char->fixnum #\Z) => "90\n"]
[($char->fixnum #\0) => "48\n"]
[($char->fixnum #\9) => "57\n"]
[($char->fixnum ($fixnum->char 12)) => "12\n"]
[($fixnum->char ($char->fixnum #\x)) => "#\\x\n"]
)

(add-tests-with-string-output "fixnum?"
[(fixnum? 0) => "#t\n"]
[(fixnum? 1) => "#t\n"]
[(fixnum? -1) => "#t\n"]
[(fixnum? 37287) => "#t\n"]
[(fixnum? -23873) => "#t\n"]
[(fixnum? 536870911) => "#t\n"]
[(fixnum? -536870912) => "#t\n"]
[(fixnum? #t) => "#f\n"]
[(fixnum? #f) => "#f\n"]
[(fixnum? ()) => "#f\n"]
[(fixnum? #\Q) => "#f\n"]
[(fixnum? (fixnum? 12)) => "#f\n"]
[(fixnum? (fixnum? #f)) => "#f\n"]
[(fixnum? (fixnum? #\A)) => "#f\n"]
[(fixnum? ($char->fixnum #\r)) => "#t\n"]
[(fixnum? ($fixnum->char 12)) => "#f\n"]
)


(add-tests-with-string-output "fxzero?"
[($fxzero? 0) => "#t\n"]
[($fxzero? 1) => "#f\n"]
[($fxzero? -1) => "#f\n"]
)

(add-tests-with-string-output "null?"
[(null? ()) => "#t\n"]
[(null? #f) => "#f\n"]
[(null? #t) => "#f\n"]
[(null? (null? ())) => "#f\n"]
[(null? #\a) => "#f\n"]
[(null? 0) => "#f\n"]
[(null? -10) => "#f\n"]
[(null? 10) => "#f\n"]
)

(add-tests-with-string-output "boolean?"
[(boolean? #t) => "#t\n"]
[(boolean? #f) => "#t\n"]
[(boolean? 0) => "#f\n"]
[(boolean? 1) => "#f\n"]
[(boolean? -1) => "#f\n"]
[(boolean? ()) => "#f\n"]
[(boolean? #\a) => "#f\n"]
[(boolean? (boolean? 0)) => "#t\n"]
[(boolean? (fixnum? (boolean? 0))) => "#t\n"]
)

(add-tests-with-string-output "char?"
[(char? #\a) => "#t\n"]
[(char? #\Z) => "#t\n"]
[(char? #\newline) => "#t\n"]
[(char? #t) => "#f\n"]
[(char? #f) => "#f\n"]
[(char? ()) => "#f\n"]
[(char? (char? #t)) => "#f\n"]
[(char? 0) => "#f\n"]
[(char? 23870) => "#f\n"]
[(char? -23789) => "#f\n"]
)

(add-tests-with-string-output "not"
[(not #t) => "#f\n"]
[(not #f) => "#t\n"]
[(not 15) => "#f\n"]
[(not ()) => "#f\n"]
[(not #\A) => "#f\n"]
[(not (not #t)) => "#t\n"]
[(not (not #f)) => "#f\n"]
[(not (not 15)) => "#t\n"]
[(not (fixnum? 15)) => "#f\n"]
[(not (fixnum? #f)) => "#t\n"]
)

(add-tests-with-string-output "fxlognot"
[($fxlognot 0) => "-1\n"]
[($fxlognot -1) => "0\n"]
[($fxlognot 1) => "-2\n"]
[($fxlognot -2) => "1\n"]
[($fxlognot 536870911) => "-536870912\n"]
[($fxlognot -536870912) => "536870911\n"]
[($fxlognot ($fxlognot 237463)) => "237463\n"]
)

18 changes: 18 additions & 0 deletions tests/tests-1.4-req.scm
@@ -0,0 +1,18 @@

(add-tests-with-string-output "if"
[(if #t 12 13) => "12\n"]
[(if #f 12 13) => "13\n"]
[(if 0 12 13) => "12\n"]
[(if () 43 ()) => "43\n"]
[(if #t (if 12 13 4) 17) => "13\n"]
[(if #f 12 (if #f 13 4)) => "4\n"]
[(if #\X (if 1 2 3) (if 4 5 6)) => "2\n"]
[(if (not (boolean? #t)) 15 (boolean? #f)) => "#t\n"]
[(if (if (char? #\a) (boolean? #\b) (fixnum? #\c)) 119 -23) => "-23\n"]
[(if (if (if (not 1) (not 2) (not 3)) 4 5) 6 7) => "6\n"]
[(if (not (if (if (not 1) (not 2) (not 3)) 4 5)) 6 7) => "7\n"]
[(not (if (not (if (if (not 1) (not 2) (not 3)) 4 5)) 6 7)) => "#f\n"]
[(if (char? 12) 13 14) => "14\n"]
[(if (char? #\a) 13 14) => "13\n"]
[($fxadd1 (if ($fxsub1 1) ($fxsub1 13) 14)) => "13\n"]
)

0 comments on commit 7677fae

Please sign in to comment.