Skip to content

Commit

Permalink
Merge branch 'ziggy' of github.com:cmsc430/www into ziggy
Browse files Browse the repository at this point in the history
  • Loading branch information
dvanhorn committed Oct 19, 2023
2 parents 27a1efe + dafd513 commit ea89403
Show file tree
Hide file tree
Showing 70 changed files with 948 additions and 65 deletions.
6 changes: 6 additions & 0 deletions langs/abscond/ast.rkt
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)
13 changes: 13 additions & 0 deletions langs/abscond/compile-stdin.rkt
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)))))

19 changes: 19 additions & 0 deletions langs/abscond/compile.rkt
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))]))

12 changes: 12 additions & 0 deletions langs/abscond/interp-stdin.rkt
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)))))

10 changes: 10 additions & 0 deletions langs/abscond/interp.rkt
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]))


13 changes: 13 additions & 0 deletions langs/abscond/main.rkt
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"))


9 changes: 9 additions & 0 deletions langs/abscond/parse.rkt
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")]))
12 changes: 12 additions & 0 deletions langs/abscond/run-stdin.rkt
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)))))

8 changes: 8 additions & 0 deletions langs/abscond/run.rkt
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))

8 changes: 8 additions & 0 deletions langs/abscond/test/compile.rkt
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)))))

7 changes: 7 additions & 0 deletions langs/abscond/test/interp.rkt
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))))

10 changes: 10 additions & 0 deletions langs/abscond/test/test-runner.rkt
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)))


11 changes: 11 additions & 0 deletions langs/blackmail/ast.rkt
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)

13 changes: 13 additions & 0 deletions langs/blackmail/compile-ops.rkt
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)]))

13 changes: 13 additions & 0 deletions langs/blackmail/compile-stdin.rkt
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)))))

26 changes: 26 additions & 0 deletions langs/blackmail/compile.rkt
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)))

9 changes: 9 additions & 0 deletions langs/blackmail/interp-prim.rkt
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)]))

12 changes: 12 additions & 0 deletions langs/blackmail/interp-stdin.rkt
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)))))

13 changes: 13 additions & 0 deletions langs/blackmail/interp.rkt
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))]))


13 changes: 13 additions & 0 deletions langs/blackmail/main.rkt
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"))


14 changes: 14 additions & 0 deletions langs/blackmail/parse.rkt
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)))

12 changes: 12 additions & 0 deletions langs/blackmail/run-stdin.rkt
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)))))

8 changes: 8 additions & 0 deletions langs/blackmail/run.rkt
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))

8 changes: 8 additions & 0 deletions langs/blackmail/test/compile.rkt
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)))))

7 changes: 7 additions & 0 deletions langs/blackmail/test/interp.rkt
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))))

14 changes: 14 additions & 0 deletions langs/blackmail/test/test-runner.rkt
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)))


13 changes: 13 additions & 0 deletions langs/con/ast.rkt
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)

13 changes: 13 additions & 0 deletions langs/con/compile-ops.rkt
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)]))

13 changes: 13 additions & 0 deletions langs/con/compile-stdin.rkt
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)))))

Loading

0 comments on commit ea89403

Please sign in to comment.