Skip to content
Merged

Next #99

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
8 changes: 8 additions & 0 deletions langs/a86/ast.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@
(instruct Je (x) check:target)
(instruct Jne (x) check:target)
(instruct Jl (x) check:target)
(instruct Jle (x) check:target)
(instruct Jg (x) check:target)
(instruct Jge (x) check:target)
(instruct And (dst src) check:src-dest)
(instruct Or (dst src) check:src-dest)
(instruct Xor (dst src) check:src-dest)
Expand Down Expand Up @@ -191,7 +193,9 @@
(Je? x)
(Jne? x)
(Jl? x)
(Jle? x)
(Jg? x)
(Jge? x)
(And? x)
(Or? x)
(Xor? x)
Expand Down Expand Up @@ -271,8 +275,12 @@
(cons s (label-uses asm))]
[(cons (Jg (? label-symbol? s)) asm)
(cons s (label-uses asm))]
[(cons (Jge (? label-symbol? s)) asm)
(cons s (label-uses asm))]
[(cons (Jl (? label-symbol? s)) asm)
(cons s (label-uses asm))]
[(cons (Jle (? label-symbol? s)) asm)
(cons s (label-uses asm))]
[(cons (Call (? label-symbol? s)) asm)
(cons s (label-uses asm))]
[(cons (Lea _ (? label-symbol? s)) asm)
Expand Down
8 changes: 7 additions & 1 deletion langs/a86/printer.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
[(Offset (? reg? r) i)
(string-append "[" (reg->string r) " + " (number->string i) "]")]
[(Offset (? label? l) i)
(string-append "[" (symbol->string l) " + " (number->string i) "]")]
(string-append "[" (label-symbol->string l) " + " (number->string i) "]")]
[(Const l)
(symbol->string l)]
[(? exp?) (exp->string a)]))
Expand Down Expand Up @@ -127,9 +127,15 @@
[(Jl l)
(string-append tab "jl "
(jump-target->string l))]
[(Jle l)
(string-append tab "jle "
(jump-target->string l))]
[(Jg l)
(string-append tab "jg "
(jump-target->string l))]
[(Jge l)
(string-append tab "jge "
(jump-target->string l))]
[(Call l)
(string-append tab "call "
(jump-target->string l))]
Expand Down
4 changes: 3 additions & 1 deletion langs/evildoer/interp-file.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(println (interp (parse (read p))))
(let ((r (interp (parse (read p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
4 changes: 3 additions & 1 deletion langs/fraud/interp-file.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(println (interp (parse (read p))))
(let ((r (interp (parse (read p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
2 changes: 1 addition & 1 deletion langs/hoax/ast.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
;; | 'vector? | vector-length
;; | 'string? | string-length
;; type Op2 = '+ | '- | '< | '=
;; | 'cons
;; | 'cons | 'eq?
;; | 'make-vector | 'vector-ref
;; | 'make-string | 'string-ref
;; type Op3 = 'vector-set!
Expand Down
6 changes: 3 additions & 3 deletions langs/hoax/compile-ops.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@

(Sar rax char-shift)

(Add r9 1) ; adds 1
(Sar r9 1) ; when
(Sal r9 1) ; len is odd
(Add r8 1) ; adds 1
(Sar r8 1) ; when
(Sal r8 1) ; len is odd

(Label loop)
(Mov (Offset rbx 0) eax)
Expand Down
4 changes: 3 additions & 1 deletion langs/hoax/interp-file.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(println (interp (parse (read p))))
(let ((r (interp (parse (read p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
2 changes: 1 addition & 1 deletion langs/hoax/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
[(Eof) eof]
[(Empty) '()]
[(Var x) (lookup r x)]
[(Str s) (string-copy s)]
[(Str s) s]
[(Prim0 'void) (void)]
[(Prim0 'read-byte) (read-byte)]
[(Prim0 'peek-byte) (peek-byte)]
Expand Down
5 changes: 4 additions & 1 deletion langs/hoax/test/test-runner.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@
(check-equal? (run '(string-ref "fred" 2)) #\e)
(check-equal? (run '(string-ref "fred" 4)) 'err)
(check-equal? (run '(string? "fred")) #t)
(check-equal? (run '(string? (cons 1 2))) #f))
(check-equal? (run '(string? (cons 1 2))) #f)
(check-equal? (run '(begin (make-string 3 #\f)
(make-string 3 #\f)))
"fff"))

(define (test-runner-io run)
;; Evildoer examples
Expand Down
4 changes: 3 additions & 1 deletion langs/hustle/interp-file.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(println (interp (parse (read p))))
(let ((r (interp (parse (read p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
6 changes: 3 additions & 3 deletions langs/iniquity/compile-ops.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@

(Sar rax char-shift)

(Add r9 1) ; adds 1
(Sar r9 1) ; when
(Sal r9 1) ; len is odd
(Add r8 1) ; adds 1
(Sar r8 1) ; when
(Sal r8 1) ; len is odd

(Label loop)
(Mov (Offset rbx 0) eax)
Expand Down
4 changes: 3 additions & 1 deletion langs/iniquity/interp-file.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(println (interp (parse (read-all p))))
(let ((r (interp (parse (read-all p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
2 changes: 1 addition & 1 deletion langs/iniquity/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[(Eof) eof]
[(Empty) '()]
[(Var x) (lookup r x)]
[(Str s) (string-copy s)]
[(Str s) s]
[(Prim0 'void) (void)]
[(Prim0 'read-byte) (read-byte)]
[(Prim0 'peek-byte) (peek-byte)]
Expand Down
3 changes: 3 additions & 0 deletions langs/iniquity/test/test-runner.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
(check-equal? (run '(string-ref "fred" 4)) 'err)
(check-equal? (run '(string? "fred")) #t)
(check-equal? (run '(string? (cons 1 2))) #f)
(check-equal? (run '(begin (make-string 3 #\f)
(make-string 3 #\f)))
"fff")

;; Iniquity tests
(check-equal? (run
Expand Down
6 changes: 3 additions & 3 deletions langs/jig/compile-ops.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@

(Sar rax char-shift)

(Add r9 1) ; adds 1
(Sar r9 1) ; when
(Sal r9 1) ; len is odd
(Add r8 1) ; adds 1
(Sar r8 1) ; when
(Sal r8 1) ; len is odd

(Label loop)
(Mov (Offset rbx 0) eax)
Expand Down
4 changes: 3 additions & 1 deletion langs/jig/interp-file.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(println (interp (parse (read-all p))))
(let ((r (interp (parse (read-all p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
2 changes: 1 addition & 1 deletion langs/jig/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[(Eof) eof]
[(Empty) '()]
[(Var x) (lookup r x)]
[(Str s) (string-copy s)]
[(Str s) s]
[(Prim0 'void) (void)]
[(Prim0 'read-byte) (read-byte)]
[(Prim0 'peek-byte) (peek-byte)]
Expand Down
3 changes: 3 additions & 0 deletions langs/jig/test/test-runner.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
(check-equal? (run '(string-ref "fred" 4)) 'err)
(check-equal? (run '(string? "fred")) #t)
(check-equal? (run '(string? (cons 1 2))) #f)
(check-equal? (run '(begin (make-string 3 #\f)
(make-string 3 #\f)))
"fff")

;; Iniquity tests
(check-equal? (run
Expand Down
6 changes: 3 additions & 3 deletions langs/knock/compile-ops.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@

(Sar rax char-shift)

(Add r9 1) ; adds 1
(Sar r9 1) ; when
(Sal r9 1) ; len is odd
(Add r8 1) ; adds 1
(Sar r8 1) ; when
(Sal r8 1) ; len is odd

(Label loop)
(Mov (Offset rbx 0) eax)
Expand Down
15 changes: 15 additions & 0 deletions langs/knock/interp-file.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#lang racket
(provide main)
(require "parse.rkt" "interp.rkt" "read-all.rkt")

;; String -> Void
;; Parse and interpret contents of given filename,
;; print result on stdout
(define (main fn)
(let ((p (open-input-file fn)))
(begin
(read-line p) ; ignore #lang racket line
(let ((r (interp (parse (read-all p)))))
(unless (void? r)
(println r)))
(close-input-port p))))
3 changes: 3 additions & 0 deletions langs/knock/test/test-runner.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
(check-equal? (run '(string-ref "fred" 4)) 'err)
(check-equal? (run '(string? "fred")) #t)
(check-equal? (run '(string? (cons 1 2))) #f)
(check-equal? (run '(begin (make-string 3 #\f)
(make-string 3 #\f)))
"fff")

;; Iniquity tests
(check-equal? (run
Expand Down
24 changes: 22 additions & 2 deletions langs/loot/ast.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
;; | (Begin Expr Expr)
;; | (Let Id Expr Expr)
;; | (Var Id)
;; | (Match Expr (Listof Pat) (Listof Expr))
;; | (App Expr (Listof Expr))
;; | (Lam Id (Listof Id) Expr)
;; type Id = Symbol
Expand All @@ -30,13 +31,24 @@
;; | 'write-byte | 'eof-object?
;; | 'box | 'car | 'cdr | 'unbox
;; | 'empty? | 'cons? | 'box?
;; | 'vector? | vector-length
;; | 'string? | string-length
;; | 'vector? | 'vector-length
;; | 'string? | 'string-length
;; type Op2 = '+ | '- | '< | '=
;; | 'cons
;; | 'make-vector | 'vector-ref
;; | 'make-string | 'string-ref
;; type Op3 = 'vector-set!
;; type Pat = (PVar Id)
;; | (PWild)
;; | (PLit Lit)
;; | (PBox Pat)
;; | (PCons Pat Pat)
;; | (PAnd Pat Pat)
;; type Lit = Boolean
;; | Character
;; | Integer
;; | '()

(struct Eof () #:prefab)
(struct Empty () #:prefab)
(struct Int (i) #:prefab)
Expand All @@ -53,3 +65,11 @@
(struct Var (x) #:prefab)
(struct App (e es) #:prefab)
(struct Lam (f xs e) #:prefab)
(struct Match (e ps es) #:prefab)

(struct PVar (x) #:prefab)
(struct PWild () #:prefab)
(struct PLit (x) #:prefab)
(struct PBox (p) #:prefab)
(struct PCons (p1 p2) #:prefab)
(struct PAnd (p1 p2) #:prefab)
6 changes: 3 additions & 3 deletions langs/loot/compile-ops.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@

(Sar rax char-shift)

(Add r9 1) ; adds 1
(Sar r9 1) ; when
(Sal r9 1) ; len is odd
(Add r8 1) ; adds 1
(Sar r8 1) ; when
(Sal r8 1) ; len is odd

(Label loop)
(Mov (Offset rbx 0) eax)
Expand Down
Loading