-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ziggy' of github.com:cmsc430/www into ziggy
- Loading branch information
Showing
70 changed files
with
948 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#lang racket | ||
(provide Lit) | ||
|
||
;; type Expr = (Lit Integer) | ||
|
||
(struct Lit (i) #:prefab) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "compile.rkt") | ||
(require a86/printer) | ||
|
||
;; -> Void | ||
;; Compile contents of stdin, | ||
;; emit asm code on stdout | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(asm-display (compile (parse (read))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#lang racket | ||
(provide (all-defined-out)) | ||
(require "ast.rkt") | ||
(require a86/ast) | ||
|
||
(define rax 'rax) | ||
|
||
;; Expr -> Asm | ||
(define (compile e) | ||
(prog (Global 'entry) | ||
(Label 'entry) | ||
(compile-e e) | ||
(Ret))) | ||
|
||
;; Expr -> Asm | ||
(define (compile-e e) | ||
(match e | ||
[(Lit i) (seq (Mov rax i))])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "interp.rkt") | ||
|
||
;; -> Void | ||
;; Parse and interpret contents of stdin, | ||
;; print result on stdout | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(println (interp (parse (read))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#lang racket | ||
(provide interp) | ||
(require "ast.rkt") | ||
|
||
;; Expr -> Integer | ||
(define (interp e) | ||
(match e | ||
[(Lit i) i])) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(require "ast.rkt") | ||
(require "parse.rkt") | ||
(require "interp.rkt") | ||
(require "compile.rkt") | ||
(require "run.rkt") | ||
(provide (all-from-out "ast.rkt")) | ||
(provide (all-from-out "parse.rkt")) | ||
(provide (all-from-out "interp.rkt")) | ||
(provide (all-from-out "compile.rkt")) | ||
(provide (all-from-out "run.rkt")) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#lang racket | ||
(provide parse) | ||
(require "ast.rkt") | ||
|
||
;; S-Expr -> Expr | ||
(define (parse s) | ||
(match s | ||
[(? exact-integer?) (Lit s)] | ||
[_ (error "Parse error")])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "compile.rkt") | ||
(require "run.rkt") | ||
|
||
;; -> Void | ||
;; Compile contents of stdin and use asm-interp to run | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(run (compile (parse (read))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#lang racket | ||
(require a86/interp) | ||
(provide run) | ||
|
||
;; Asm -> Integer | ||
(define (run is) | ||
(asm-interp is)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#lang racket | ||
(require "../compile.rkt") | ||
(require "../parse.rkt") | ||
(require "../run.rkt") | ||
(require "test-runner.rkt") | ||
|
||
(test (λ (e) (run (compile (parse e))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#lang racket | ||
(require "../interp.rkt") | ||
(require "../parse.rkt") | ||
(require "test-runner.rkt") | ||
|
||
(test (λ (e) (interp (parse e)))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#lang racket | ||
(provide test) | ||
(require rackunit) | ||
|
||
(define (test run) | ||
(begin ;; Abscond | ||
(check-equal? (run 7) 7) | ||
(check-equal? (run -8) -8))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#lang racket | ||
(provide Lit Prim1) | ||
|
||
;; type Expr = (Lit Integer) | ||
;; | (Prim1 Op1 Expr) | ||
|
||
;; type Op1 = 'add1 | 'sub1 | ||
|
||
(struct Lit (i) #:prefab) | ||
(struct Prim1 (p e) #:prefab) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide compile-op1) | ||
(require "ast.rkt") | ||
(require a86/ast) | ||
|
||
(define rax 'rax) | ||
|
||
;; Op1 -> Asm | ||
(define (compile-op1 p) | ||
(match p | ||
['add1 (Add rax 1)] | ||
['sub1 (Sub rax 1)])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "compile.rkt") | ||
(require a86/printer) | ||
|
||
;; -> Void | ||
;; Compile contents of stdin, | ||
;; emit asm code on stdout | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(asm-display (compile (parse (read))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#lang racket | ||
(provide (all-defined-out)) | ||
(require "ast.rkt") | ||
(require "compile-ops.rkt") | ||
(require a86/ast) | ||
|
||
(define rax 'rax) | ||
|
||
;; Expr -> Asm | ||
(define (compile e) | ||
(prog (Global 'entry) | ||
(Label 'entry) | ||
(compile-e e) | ||
(Ret))) | ||
|
||
;; Expr -> Asm | ||
(define (compile-e e) | ||
(match e | ||
[(Lit i) (seq (Mov rax i))] | ||
[(Prim1 p e) (compile-prim1 p e)])) | ||
|
||
;; Op1 Expr -> Asm | ||
(define (compile-prim1 p e) | ||
(seq (compile-e e) | ||
(compile-op1 p))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#lang racket | ||
(provide interp-prim1) | ||
|
||
;; Op1 Integer -> Integer | ||
(define (interp-prim1 op i) | ||
(match op | ||
['add1 (add1 i)] | ||
['sub1 (sub1 i)])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "interp.rkt") | ||
|
||
;; -> Void | ||
;; Parse and interpret contents of stdin, | ||
;; print result on stdout | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(println (interp (parse (read))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide interp) | ||
(require "ast.rkt") | ||
(require "interp-prim.rkt") | ||
|
||
;; Expr -> Integer | ||
(define (interp e) | ||
(match e | ||
[(Lit i) i] | ||
[(Prim1 p e) | ||
(interp-prim1 p (interp e))])) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(require "ast.rkt") | ||
(require "parse.rkt") | ||
(require "interp.rkt") | ||
(require "compile.rkt") | ||
(require "run.rkt") | ||
(provide (all-from-out "ast.rkt")) | ||
(provide (all-from-out "parse.rkt")) | ||
(provide (all-from-out "interp.rkt")) | ||
(provide (all-from-out "compile.rkt")) | ||
(provide (all-from-out "run.rkt")) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#lang racket | ||
(provide parse) | ||
(require "ast.rkt") | ||
|
||
;; S-Expr -> Expr | ||
(define (parse s) | ||
(match s | ||
[(? exact-integer?) (Lit s)] | ||
[(list (? op1? o) e) (Prim1 o (parse e))] | ||
[_ (error "Parse error")])) | ||
|
||
(define (op1? x) | ||
(memq x '(add1 sub1))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "compile.rkt") | ||
(require "run.rkt") | ||
|
||
;; -> Void | ||
;; Compile contents of stdin and use asm-interp to run | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(run (compile (parse (read))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#lang racket | ||
(require a86/interp) | ||
(provide run) | ||
|
||
;; Asm -> Integer | ||
(define (run is) | ||
(asm-interp is)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#lang racket | ||
(require "../compile.rkt") | ||
(require "../parse.rkt") | ||
(require "../run.rkt") | ||
(require "test-runner.rkt") | ||
|
||
(test (λ (e) (run (compile (parse e))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#lang racket | ||
(require "../interp.rkt") | ||
(require "../parse.rkt") | ||
(require "test-runner.rkt") | ||
|
||
(test (λ (e) (interp (parse e)))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#lang racket | ||
(provide test) | ||
(require rackunit) | ||
|
||
(define (test run) | ||
(begin ;; Abscond | ||
(check-equal? (run 7) 7) | ||
(check-equal? (run -8) -8)) | ||
|
||
(begin ;; Blackmail | ||
(check-equal? (run '(add1 (add1 7))) 9) | ||
(check-equal? (run '(add1 (sub1 7))) 7))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide Lit Prim1 IfZero) | ||
|
||
;; type Expr = (Lit Integer) | ||
;; | (Prim1 Op1 Expr) | ||
;; | (IfZero Expr Expr Expr) | ||
|
||
;; type Op1 = 'add1 | 'sub1 | ||
|
||
(struct Lit (i) #:prefab) | ||
(struct Prim1 (p e) #:prefab) | ||
(struct IfZero (e1 e2 e3) #:prefab) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide compile-op1) | ||
(require "ast.rkt") | ||
(require a86/ast) | ||
|
||
(define rax 'rax) | ||
|
||
;; Op1 -> Asm | ||
(define (compile-op1 p) | ||
(match p | ||
['add1 (Add rax 1)] | ||
['sub1 (Sub rax 1)])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#lang racket | ||
(provide main) | ||
(require "parse.rkt") | ||
(require "compile.rkt") | ||
(require a86/printer) | ||
|
||
;; -> Void | ||
;; Compile contents of stdin, | ||
;; emit asm code on stdout | ||
(define (main) | ||
(read-line) ; ignore #lang racket line | ||
(asm-display (compile (parse (read))))) | ||
|
Oops, something went wrong.