Skip to content

Commit 4174503

Browse files
committed
Iniquity + GC (start).
1 parent 6aa97f2 commit 4174503

26 files changed

+2706
-0
lines changed

langs/iniquity-gc/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
UNAME := $(shell uname)
2+
.PHONY: test
3+
4+
ifeq ($(UNAME), Darwin)
5+
format=macho64
6+
else
7+
format=elf64
8+
endif
9+
10+
objs = \
11+
main.o \
12+
values.o \
13+
print.o \
14+
io.o
15+
16+
default: runtime.o
17+
18+
runtime.o: $(objs)
19+
ld -r $(objs) -o runtime.o
20+
21+
%.run: %.o runtime.o
22+
gcc runtime.o $< -o $@
23+
24+
.c.o:
25+
gcc -fPIC -c -g -o $@ $<
26+
27+
.s.o:
28+
nasm -g -f $(format) -o $@ $<
29+
30+
%.s: %.rkt
31+
racket -t compile-file.rkt -m $< > $@
32+
33+
clean:
34+
rm *.o *.s *.run
35+
36+
test: example.run
37+
@test "$(shell ./example.run)" = "$(shell racket example.rkt)"

langs/iniquity-gc/ast.rkt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#lang racket
2+
(provide (all-defined-out))
3+
4+
;; type Prog = (Prog (Listof Defn) Expr)
5+
(struct Prog (ds e) #:prefab)
6+
7+
;; type Defn = (Defn Id (Listof Id) Expr)
8+
(struct Defn (f xs e) #:prefab)
9+
10+
;; type Expr = (Eof)
11+
;; | (Empty)
12+
;; | (Int Integer)
13+
;; | (Bool Boolean)
14+
;; | (Char Character)
15+
;; | (Str String)
16+
;; | (Prim0 Op0)
17+
;; | (Prim1 Op1 Expr)
18+
;; | (Prim2 Op2 Expr Expr)
19+
;; | (Prim3 Op3 Expr Expr Expr)
20+
;; | (If Expr Expr Expr)
21+
;; | (Begin Expr Expr)
22+
;; | (Let Id Expr Expr)
23+
;; | (Var Id)
24+
;; | (App Id (Listof Expr))
25+
;; type Id = Symbol
26+
;; type Op0 = 'read-byte
27+
;; type Op1 = 'add1 | 'sub1 | 'zero?
28+
;; | 'char? | 'integer->char | 'char->integer
29+
;; | 'write-byte | 'eof-object?
30+
;; | 'box | 'car | 'cdr | 'unbox
31+
;; | 'empty? | 'cons? | 'box?
32+
;; | 'vector? | vector-length
33+
;; | 'string? | string-length
34+
;; type Op2 = '+ | '- | '< | '=
35+
;; | 'cons
36+
;; | 'make-vector | 'vector-ref
37+
;; | 'make-string | 'string-ref
38+
;; type Op3 = 'vector-set!
39+
(struct Eof () #:prefab)
40+
(struct Empty () #:prefab)
41+
(struct Int (i) #:prefab)
42+
(struct Bool (b) #:prefab)
43+
(struct Char (c) #:prefab)
44+
(struct Str (s) #:prefab)
45+
(struct Prim0 (p) #:prefab)
46+
(struct Prim1 (p e) #:prefab)
47+
(struct Prim2 (p e1 e2) #:prefab)
48+
(struct Prim3 (p e1 e2 e3) #:prefab)
49+
(struct If (e1 e2 e3) #:prefab)
50+
(struct Begin (e1 e2) #:prefab)
51+
(struct Let (x e1 e2) #:prefab)
52+
(struct Var (x) #:prefab)
53+
(struct App (f es) #:prefab)

langs/iniquity-gc/compile-file.rkt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#lang racket
2+
(provide main)
3+
(require "parse.rkt" "compile.rkt" "read-all.rkt" a86/printer)
4+
5+
;; String -> Void
6+
;; Compile contents of given file name,
7+
;; emit asm code on stdout
8+
(define (main fn)
9+
(let ((p (open-input-file fn)))
10+
(begin
11+
(read-line p) ; ignore #lang racket line
12+
(displayln (asm-string (compile (parse (read-all p)))))
13+
(close-input-port p))))

0 commit comments

Comments
 (0)