Skip to content

Add Iniquity+ starter code #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions iniquity-plus/ast.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#lang racket
(provide Lit Prim0 Prim1 Prim2 Prim3 If Eof Begin
Let Var Prog Defn App
Apply FunPlain FunRest FunCase)

;; type Prog = (Prog (Listof Defn) Expr)
(struct Prog (ds e) #:prefab)

;; type Defn = (Defn Id Fun)
(struct Defn (f fun) #:prefab)

;; type Fun = (FunPlain [Listof Id] Expr)
;; | (FunRest [Listof Id] Id Expr)
;; | (FunCase [Listof FunCaseClause])
;; type FunCaseClause = (FunPlain [Listof Id] Expr)
;; | (FunRest [Listof Id] Id Expr)
(struct FunPlain (xs e) #:prefab)
(struct FunRest (xs x e) #:prefab)
(struct FunCase (cs) #:prefab)
;; type Expr = (Lit Datum)
;; | (Eof)
;; | (Prim0 Op0)
;; | (Prim1 Op1 Expr)
;; | (Prim2 Op2 Expr Expr)
;; | (Prim3 Op3 Expr Expr Expr)
;; | (If Expr Expr Expr)
;; | (Begin Expr Expr)
;; | (Let Id Expr Expr)
;; | (Var Id)
;; | (App Id (Listof Expr))
;; | (Apply Id (Listof Expr) Expr)

;; type Id = Symbol
;; type Datum = Integer
;; | Boolean
;; | Character
;; | String
;; type Op0 = 'read-byte | 'peek-byte | 'void
;; type Op1 = 'add1 | 'sub1
;; | 'zero?
;; | 'char? | 'integer->char | 'char->integer
;; | 'write-byte | 'eof-object?
;; | 'box | 'car | 'cdr | 'unbox
;; | 'empty? | 'cons? | 'box?
;; | 'vector? | 'vector-length
;; | 'string? | 'string-length
;; type Op2 = '+ | '- | '< | '=
;; | 'eq? | 'cons
;; | 'make-vector | 'vector-ref
;; | 'make-string | 'string-ref
;; type Op3 = 'vector-set!

(struct Eof () #:prefab)
(struct Lit (d) #:prefab)
(struct Prim0 (p) #:prefab)
(struct Prim1 (p e) #:prefab)
(struct Prim2 (p e1 e2) #:prefab)
(struct Prim3 (p e1 e2 e3) #:prefab)
(struct If (e1 e2 e3) #:prefab)
(struct Begin (e1 e2) #:prefab)
(struct Let (x e1 e2) #:prefab)
(struct Var (x) #:prefab)
(struct App (f es) #:prefab)
(struct Apply (f es e) #:prefab)

14 changes: 14 additions & 0 deletions iniquity-plus/build-runtime.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#lang racket
(provide runtime-path)

(require racket/runtime-path)
(define-runtime-path here ".")

(unless (system (string-append "make -C '"
(path->string (normalize-path here))
"' -s runtime.o"))
(error 'build-runtime "could not build runtime"))

(define runtime-path
(normalize-path (build-path here "runtime.o")))

Loading