Skip to content

Commit 0b8aa94

Browse files
committed
Merge branch 'new-knock'
This includes many updates+fixes. Here are the highlights: * New implementations for Knock+Jig * Update of notes from the sexpr style to the a86 style (up to Knock) * Update of test suite for Hustle+Iniquity+Jig (not Knock because Racket doesn't have the `call` functionality built-in)
2 parents 9a4f71a + c14e76f commit 0b8aa94

File tree

107 files changed

+3764
-4337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3764
-4337
lines changed

langs/a86/ast.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
(define check:target
1818
(λ (x n)
19-
(unless (symbol? x) ; either register or label
19+
(unless (or (symbol? x) (offset? x)); either register or label
2020
(error n "expects symbol; given ~v" x))
2121
x))
2222

langs/a86/printer.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
(define (jump-target->string t)
5151
(match t
5252
[(? reg?) (reg->string t)]
53+
[(Offset (? reg? r) i)
54+
(string-append "[" (reg->string r) " + " (number->string i) "]")]
5355
[_ (label-symbol->string t)]))
5456

5557
(define tab (make-string 8 #\space))

langs/extort/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "types.h"
55
#include "runtime.h"
66

7+
FILE* in;
8+
FILE* out;
9+
void (*error_handler)();
10+
711
void print_result(int64_t);
812
void print_char(int64_t);
913

langs/extort/runtime.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#ifndef RUNTIME_H
2+
#define RUNTIME_H
13
int64_t entry();
2-
FILE* in;
3-
FILE* out;
4-
void (*error_handler)();
4+
extern FILE* in;
5+
extern FILE* out;
6+
extern void (*error_handler)();
7+
#endif /* RUNTIME_H */

langs/fraud/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "types.h"
55
#include "runtime.h"
66

7+
FILE* in;
8+
FILE* out;
9+
void (*error_handler)();
10+
711
void print_result(int64_t);
812
void print_char(int64_t);
913

langs/fraud/runtime.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#ifndef RUNTIME_H
2+
#define RUNTIME_H
13
int64_t entry();
2-
FILE* in;
3-
FILE* out;
4-
void (*error_handler)();
4+
extern FILE* in;
5+
extern FILE* out;
6+
extern void (*error_handler)();
7+
#endif /* RUNTIME_H */

langs/hustle/interp-io.rkt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#lang racket
2-
(provide make-interp/io)
2+
(provide interp/io)
3+
(require "interp.rkt")
34

4-
;; (Expr -> Answer) -> (Expr String -> String)
5+
;; Expr String -> (Cons Value String)
56
;; Interpret e with given string as input,
67
;; collect output as string (including printed result)
7-
(define (make-interp/io interp)
8-
(λ (e in)
9-
(parameterize ((current-output-port (open-output-string))
10-
(current-input-port (open-input-string in)))
8+
(define (interp/io e input)
9+
(parameterize ((current-output-port (open-output-string))
10+
(current-input-port (open-input-string input)))
1111
(cons (interp e)
12-
(get-output-string (current-output-port))))))
12+
(get-output-string (current-output-port)))))

langs/hustle/interp-prims-heap-bits.rkt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
[(list 'sub1 (? int-bits? i)) (cons h (- i (imm->bits 1)))]
1111
[(list 'zero? (? int-bits? i)) (cons h (imm->bits (zero? i)))]
1212
[(list 'char? v) (cons h (imm->bits (char-bits? v)))]
13-
[(list 'char->integer (? char-bits?)) (cons h (imm->bits (char->integer (bits->imm v))))]
14-
[(list 'integer->char (? cp-bits?)) (cons h (imm->bits (integer->char (bits->imm v))))]
13+
[(list 'char->integer (? char-bits?)) (cons h (imm->bits (char->integer (bits->value v))))]
14+
[(list 'integer->char (? cp-bits?)) (cons h (imm->bits (integer->char (bits->value v))))]
1515
[(list 'eof-object? v) (cons h (if (= v (imm->bits eof)) val-true val-false))]
16-
[(list 'write-byte (? byte-bits?)) (cons h (begin (write-byte (bits->imm v)) val-void))]
16+
[(list 'write-byte (? byte-bits?)) (cons h (begin (write-byte (bits->value v)) val-void))]
1717
[(list 'box v) (alloc-box v h)]
1818
[(list 'unbox (? box-bits? i)) (cons h (heap-ref h i))]
1919
[(list 'car (? cons-bits? i)) (cons h (heap-ref h i))]

langs/hustle/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include "types.h"
55
#include "runtime.h"
66

7+
FILE* in;
8+
FILE* out;
9+
void (*error_handler)();
10+
int64_t *heap;
11+
712
void print_result(int64_t);
813

914
void error_exit() {
@@ -19,11 +24,16 @@ int main(int argc, char** argv) {
1924
in = stdin;
2025
out = stdout;
2126
error_handler = &error_exit;
22-
heap = malloc(8 * heap_size);
27+
heap = malloc(8 * heap_size); // 8-byte words * number of words we want
28+
29+
// `heap` gets passed in `rdi`
30+
// (defined by the calling convention, not up to us!)
2331
int64_t result = entry(heap);
32+
// See if we need to print the initial tick
33+
if (cons_type_tag == (ptr_type_mask & result)) printf("'");
2434
print_result(result);
2535
if (result != val_void) printf("\n");
26-
free(heap);
36+
free(heap); // good memory hygiene
2737
return 0;
2838
}
2939

langs/hustle/runtime.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
#ifndef RUNTIME_H
2+
#define RUNTIME_H
13
int64_t entry();
2-
FILE* in;
3-
FILE* out;
4-
void (*error_handler)();
4+
extern FILE* in;
5+
extern FILE* out;
6+
extern void (*error_handler)();
57

68
// in words
79
#define heap_size 10000
8-
int64_t *heap;
10+
extern int64_t *heap;
11+
#endif /* RUNTIME_H */

0 commit comments

Comments
 (0)