Skip to content

Commit

Permalink
a gensym starts at zero now, and hand tests for both compiler and swigls
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Mattis committed Apr 25, 2012
1 parent 321f013 commit 9296906
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 490 deletions.
37 changes: 26 additions & 11 deletions asm/asm-support.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@inst->number

sym
reset-sym-counter
reset-syms
snoc

;; Random bits
Expand Down Expand Up @@ -53,16 +53,31 @@
;; PURPOSE
;; Returns a new, uniquely numbered symbol using
;; the first argument as a base.
(define SYM-COUNTER 0)
(define sym
(lambda (id)
(let ([newsym (string->symbol
(format "~a~a" id SYM-COUNTER))])
(set! SYM-COUNTER (add1 SYM-COUNTER))
newsym)))

(define (reset-sym-counter)
(set! SYM-COUNTER 0))
;;(define SYM-COUNTER 0)
;;(define sym
;; (lambda (id)
;; (let ([newsym (string->symbol
;; (format "~a~a" id SYM-COUNTER))])
;; (set! SYM-COUNTER (add1 SYM-COUNTER))
;; newsym)))

;;(define (reset-sym-counter)
;; (set! SYM-COUNTER 0))

;;make hash table
(define GENSYM-TABLE (make-hash))

;;starts symbols at zero
(define (sym id)
(let ([next (hash-ref GENSYM-TABLE id
(lambda () 0))])
(hash-set! GENSYM-TABLE id (add1 next))
(string->symbol
(format "~a~a" id next))))

;;set symbols back to zero
(define (reset-syms)
(set! GENSYM-TABLE (make-hash)))

;; CONTRACT
;; pad :: string number -> string
Expand Down
1 change: 1 addition & 0 deletions compiler/base.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

(provide (all-defined-out))


;; Structures


Expand Down
106 changes: 63 additions & 43 deletions compiler/hand.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,72 @@
"../asm/asm-base.rkt"
"../asm/asm-support.rkt"
"base.rkt"
"helpers.rkt")
"helpers.rkt"
"driver.rkt"
"../asm-interp/main.rkt")

(define-check (check-files f1 f2)
(reset-syms)
(check-equal?
(file->list f1)
(file->list f2)))

(test-suite
"hand-written tests for CS420"
(test-case
"(+ 3 5)"
(compile '(+ 3 5) "foo.hack")
(check-files "foo.hack" "testingFiles/one.hack"))
(test-case
"(- 9 1)"
(compile '(- 9 1) "foo.hack")
(check-files "foo.hack" "testingFiles/two.hack"))
(test-case
"(+ 3(- 5 2)"
(compile '(+ 3(- 5 2)) "foo.hack")
(check-files "foo.hack" "testingFiles/three.hack"))
(test-case
"(- 3(+ 5 2)"
(compile '(- 3(+ 5 2)) "foo.hack")
(check-files "foo.hack" "testingFiles/four.hack"))
(test-case
"(- 3(+ 5 2)"
(compile '(- 3(+ 5 2)) "foo.hack")
(check-files "foo.hack" "testingFiles/four.hack"))
(test-case
"(+(+ 1 2)(- 4 3))"
(compile '(+(+ 1 2)(- 4 3)) "foo.hack")
(check-files "foo.hack" "testingFiles/five.hack"))
(test-case
"(-(- 8 1)(+ 1 3))"
(compile '(+(+ 1 2)(- 4 3)) "foo.hack")
(check-files "foo.hack" "testingFiles/six.hack"))
(test-case
"(+(+ 3 5) 5)"
(compile '(+(+ 1 2)(- 4 3)) "foo.hack")
(check-files "foo.hack" "testingFiles/seven.hack"))
(test-case
"(+(- 3 1) 6))"
(compile '(+(- 3 1)6) "foo.hack")
(check-files "foo.hack" "testingFiles/eight.hack"))
(test-case
"(-(- 4 2)1)"
(compile '(-(-4 2)1) "foo.hack")
(check-files "foo.hack" "testingFiles/nine.hack")))
(define all-tests
(test-suite
"hand-written tests for pow compiler"
(test-case
"(+ 3 5)"
(driver "expressions/one.420")
(emulate "expressions/one.hack")
(check-files "expressions/one.hack" "assemblyFiles/one.hack"))
(test-case
"(- 9 1)"
(driver "expressions/two.420")
(emulate "expressions/two.hack")
(check-files "expressions/two.hack" "assemblyFiles/two.hack"))
(test-case
"(+ 3(- 5 2)"
(driver "expressions/three.420")
(emulate "expressions/three.hack")
(check-files "expressions/three.hack" "assemblyFiles/three.hack"))
(test-case
"(- 3(+ 5 2)"
(driver "expressions/four.420")
(emulate "expressions/four.hack")
(check-files "expressions/four.hack" "assemblyFiles/four.hack"))
(test-case
"(+(+ 1 2)(- 4 3))"
(driver "expressions/five.420")
(emulate "expressions/five.hack")
(check-files "expressions/five.hack" "assemblyFiles/five.hack"))
(test-case
"(-(- 8 1)(+ 1 3))"
(driver "expressions/six.420")
(emulate "expressions/six.hack")
(check-files "expressions/six.hack" "assemblyFiles/six.hack"))
(test-case
"(+(+ 3 5) 5)"
(driver "expressions/seven.420")
(emulate "expressions/seven.hack")
(check-files "expressions/seven.hack" "assemblyFiles/seven.hack"))
(test-case
"(+(- 3 1) 6))"
(driver "expressions/eight.420")
(emulate "expressions/eight.hack")
(check-files "expressions/eight.hack" "assemblyFiles/eight.hack"))
(test-case
"(-(- 4 2)1)"
(driver "expressions/nine.420")
(emulate "expressions/nine.hack")
(check-files "expressions/nine.hack" "assemblyFiles/nine.hack"))))

(define GUI true)
(define NOISY 'quiet)
(require rackunit/text-ui rackunit/gui)

(if GUI
(test/gui all-tests)
(printf "Failed ~a tests."
(run-tests all-tests
(if NOISY 'normal 'quiet))))

7 changes: 4 additions & 3 deletions compiler/pass2.rkt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
;; Pass 2

#lang racket
(require "base.rkt")
(require "base.rkt"
"../asm/asm-support.rkt")
(provide pass2)

;; PURPOSE
Expand Down Expand Up @@ -38,11 +39,11 @@
lhs
rhs
(list
(id (gensym 'bin) (binop (binop-op structure)
(id (sym 'bin) (binop (binop-op structure)
(id-sym (last lhs))
(id-sym (last rhs))
)))))]


[(num? structure) (list (id (gensym 'num) (num-value structure)))]
[(num? structure) (list (id (sym 'num) (num-value structure)))]
))
11 changes: 0 additions & 11 deletions compiler/testingFiles/eight.hack

This file was deleted.

13 changes: 0 additions & 13 deletions compiler/testingFiles/five.hack

This file was deleted.

11 changes: 0 additions & 11 deletions compiler/testingFiles/four.hack

This file was deleted.

11 changes: 0 additions & 11 deletions compiler/testingFiles/nine.hack

This file was deleted.

6 changes: 0 additions & 6 deletions compiler/testingFiles/one.hack

This file was deleted.

11 changes: 0 additions & 11 deletions compiler/testingFiles/seven.hack

This file was deleted.

13 changes: 0 additions & 13 deletions compiler/testingFiles/six.hack

This file was deleted.

10 changes: 0 additions & 10 deletions compiler/testingFiles/three.hack

This file was deleted.

5 changes: 0 additions & 5 deletions compiler/testingFiles/two.hack

This file was deleted.

2 changes: 1 addition & 1 deletion swigls-compiler/compiled/drracket/errortrace/base_rkt.dep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
("5.1.3" ("067de99e59fbd83a249da8721d62f8d9e0a5dcac" . "fe7f45f50d59c122149c4844dfa443f330203fa1") (collects #"errortrace" #"errortrace-key.rkt") (collects #"racket" #"main.rkt") (collects #"racket" #"lang" #"reader.rkt"))
("5.1.3" ("484574349c984866b7771f366f3426f3c57e8f11" . "fe7f45f50d59c122149c4844dfa443f330203fa1") (collects #"errortrace" #"errortrace-key.rkt") (collects #"racket" #"main.rkt") (collects #"racket" #"lang" #"reader.rkt"))
Binary file modified swigls-compiler/compiled/drracket/errortrace/base_rkt.zo
Binary file not shown.
Loading

0 comments on commit 9296906

Please sign in to comment.