Skip to content

Commit 4610dc7

Browse files
committed
Helper scripts and an example for Jig
1 parent 150aba0 commit 4610dc7

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

www/notes/jig/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.run

www/notes/jig/compile-file.rkt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#lang racket
2+
(provide (all-defined-out))
3+
(require "compile.rkt" "syntax.rkt" "asm/printer.rkt")
4+
5+
;; String -> Void
6+
;; Compile contents of given file name,
7+
;; emit asm code on stdout
8+
(define (main fn)
9+
(with-input-from-file fn
10+
(λ ()
11+
(let ((c (read-line))
12+
(p (read)))
13+
(unless (expr? p) (error "syntax error" p))
14+
(asm-display (compile (sexpr->prog p)))))))

www/notes/jig/example.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#lang racket
2+
(begin
3+
(define (f x y) (+ x y))
4+
(let ((x (cons (f 1 2) '()))) x))

www/notes/jig/interp-file.rkt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#lang racket
2+
(provide (all-defined-out))
3+
(require "interp.rkt" "syntax.rkt")
4+
5+
;; String -> Void
6+
;; Parse and interpret contents of given filename,
7+
;; print result on stdout
8+
(define (main fn)
9+
(with-input-from-file fn
10+
(λ ()
11+
(let ((c (read-line)))
12+
(let ((p (read)))
13+
(unless (expr? p) (error "syntax error" p))
14+
(writeln (interp (sexpr->prog p))))))))

0 commit comments

Comments
 (0)