summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/ast/assembly-tree.scm40
-rw-r--r--src/modules/ast/syntax-tree.scm59
-rw-r--r--src/modules/emitter/emitter.scm43
-rw-r--r--src/modules/generator/generator.scm19
-rw-r--r--src/modules/lexer/lexer.scm86
-rw-r--r--src/modules/parser/parser.scm36
-rw-r--r--src/modules/tuple-generator/tuple-generator.scm36
-rw-r--r--src/modules/utils/t-factory.scm24
8 files changed, 0 insertions, 343 deletions
diff --git a/src/modules/ast/assembly-tree.scm b/src/modules/ast/assembly-tree.scm
deleted file mode 100644
index 3f0f1b1..0000000
--- a/src/modules/ast/assembly-tree.scm
+++ /dev/null
@@ -1,40 +0,0 @@
-(define-module (modules ast assembly-tree)
- #:use-module (srfi srfi-9)
- #:export (make-subroutine
- subroutine?
- subroutine-label
- subroutine-instructions
- subroutine-frame-size
-
- make-instruction
- instruction?
- instruction-destination
- set-instruction-destination
- instruction-operator
- instruction-src-1
- instruction-src-2
-
- make-register
- register?
- register-name
- ))
-
-(define-record-type <subroutine>
- (make-subroutine label instrs f-size)
- subroutine?
- (label subroutine-label)
- (instrs subroutine-instructions)
- (f-size subroutine-frame-size))
-
-(define-record-type <instruction>
- (make-instruction dest op src1 src2)
- instruction?
- (dest instruction-destination set-instruction-destination)
- (op instruction-operator)
- (src1 instruction-src-1)
- (src2 instruction-src-2))
-
-(define-record-type <register>
- (make-register name)
- register?
- (name register-name))
diff --git a/src/modules/ast/syntax-tree.scm b/src/modules/ast/syntax-tree.scm
deleted file mode 100644
index e2ca8da..0000000
--- a/src/modules/ast/syntax-tree.scm
+++ /dev/null
@@ -1,59 +0,0 @@
-(define-module (modules ast syntax-tree)
- #:use-module (srfi srfi-9)
- #:export (make-program
- program?
- program-function
-
- make-function
- function?
- function-id
- function-stmt
-
- make-stmt
- stmt?
- stmt-expr
-
- make-unary
- unary?
- unary-operator
- unary-expr
-
- make-const
- const?
- const-int
-
- make-id
- id?
- id-symbol))
-
-(define-record-type <program>
- (make-program func)
- program?
- (func program-function))
-
-(define-record-type <function>
- (make-function id stmt)
- function?
- (id function-id)
- (stmt function-stmt))
-
-(define-record-type <stmt>
- (make-stmt expr)
- stmt?
- (expr stmt-expr))
-
-(define-record-type <unary>
- (make-unary op expr)
- unary?
- (op unary-operator)
- (expr unary-expr))
-
-(define-record-type <const>
- (make-const int)
- const?
- (int const-int))
-
-(define-record-type <id>
- (make-id symbol)
- id?
- (symbol id-symbol))
diff --git a/src/modules/emitter/emitter.scm b/src/modules/emitter/emitter.scm
deleted file mode 100644
index 5e4b7d4..0000000
--- a/src/modules/emitter/emitter.scm
+++ /dev/null
@@ -1,43 +0,0 @@
-(define-module (modules emitter emitter)
- #:use-module (modules ast syntax-tree)
- #:use-module (modules ast assembly-tree)
- #:export (e-program))
-
-
-(define emit #f)
-(define emitln #f)
-(let ((p ""))
- (set! emit
- (lambda (str)
- (set! p (string-append/shared p str))
- p))
- (set! emitln
- (lambda (str)
- (emit (string-append/shared str "\n"))
- p))
- )
-
-(define (e-program p)
- (e-subroutine (program-function p))
- (emitln ".section .note.GNU-stack,\"\",@progbits"))
-
-(define (e-subroutine s)
- (let ((label (subroutine-label s)))
- (emitln (format #f " .globl ~a" label))
- (emitln (format #f "~a:" label)))
- (e-instructions (subroutine-instructions s)))
-
-(define (e-instructions lst)
- (unless (null? lst)
- (begin (e-instruction (car lst))
- (e-instructions (cdr lst)))))
-
-(define (e-instruction i)
- (emit (format #f " ~a" (instruction-operator i)))
- (let ((oper1 (instruction-operand-1 i))
- (oper2 (instruction-operand-2 i)))
- (when oper1
- (emit (format #f " ~a" oper1))
- (when oper2
- (emit (format #f ", ~a" oper2)))))
- (emitln ""))
diff --git a/src/modules/generator/generator.scm b/src/modules/generator/generator.scm
deleted file mode 100644
index ed00de5..0000000
--- a/src/modules/generator/generator.scm
+++ /dev/null
@@ -1,19 +0,0 @@
-(define-module (modules generator generator)
- #:use-module (srfi srfi-9 gnu)
- #:use-module (modules ast syntax-tree)
- #:use-module (modules ast assembly-tree)
- #:export (g-program))
-
-
-(define (g-program p)
- (g-subroutine (program-function p)))
-
-(define (g-subroutine s)
- (g-instructions (subroutine-instructions s)))
-
-(define (g-instructions lst)
- (define (g-instruction i)
- (set-instruction-destination i "foo"))
- (unless (null? lst)
- (begin (g-instruction (car lst))
- (g-instructions (cdr lst)))))
diff --git a/src/modules/lexer/lexer.scm b/src/modules/lexer/lexer.scm
deleted file mode 100644
index eb815b9..0000000
--- a/src/modules/lexer/lexer.scm
+++ /dev/null
@@ -1,86 +0,0 @@
-(define-module (modules lexer lexer)
- #:export (read-tokens))
-
-(define (read-tokens)
- "Returns a stream of tokens from the
-current input port."
- (define (read-tokens-loop tokens-so-far)
- (let ((token (read-token)))
- (if token
- (read-tokens-loop (cons token tokens-so-far))
- (reverse tokens-so-far))))
- (read-tokens-loop '()))
-
-(define (read-token)
- (let ((chr (read-char)))
- (cond
- ((eof-object? chr) #f)
- ((char-whitespace? chr)
- (read-token))
-
- ((eqv? chr #\()
- 'left-paren)
- ((eqv? chr #\))
- 'right-paren)
- ((eqv? chr #\{)
- 'open-brace)
- ((eqv? chr #\})
- 'close-brace)
- ((eqv? chr #\;)
- 'semi-colon)
- ((eqv? chr #\~)
- 'complement)
-
- ((eqv? chr #\+)
- (if (take-double? chr)
- 'increment
- 'add))
-
- ((eqv? chr #\-)
- (if (take-double? chr)
- 'decrement
- 'sub))
-
- ((char-numeric? chr)
- (read-constant chr))
-
- ((char-alphabetic? chr)
- (lookup-keyword (read-identifier chr)))
-
- (#t (error "illegal lexical syntax")))))
-
-(define (read-constant chr)
- (define (read-constant-helper chrs-so-far)
- (let ((chr (peek-char)))
- (cond ((and (not (eof-object? chr)) (char-numeric? chr))
- (read-constant-helper (cons (read-char) chrs-so-far)))
- ((and (not (eof-object? chr)) (char-alphabetic? chr))
- (error "identifier starting with digit"))
- (#t (reverse chrs-so-far)))))
- (string->number (list->string (read-constant-helper (list chr)))))
-
-(define (read-identifier chr)
- (define (read-identifier-helper chrs-so-far)
- (let ((chr (peek-char)))
- (cond ((and (not (eof-object? chr))
- (or (char-alphabetic? chr)
- (char-numeric? chr)
- (eqv? chr #\_)))
- (read-identifier-helper (cons (read-char) chrs-so-far)))
- (#t (reverse chrs-so-far)))))
- (list->string (read-identifier-helper (list chr))))
-
-(define (take-double? chr)
- (if (eqv? chr (peek-char))
- (read-char)
- #f))
-
-(define (lookup-keyword id)
- "Given identifier ID, converts it to a keyword
-if one is known."
- (let ((found (assoc
- id
- '(("int" . int)
- ("void" . void)
- ("return" . return)))))
- (if found (cdr found) id)))
diff --git a/src/modules/parser/parser.scm b/src/modules/parser/parser.scm
deleted file mode 100644
index cab690c..0000000
--- a/src/modules/parser/parser.scm
+++ /dev/null
@@ -1,36 +0,0 @@
-(define-module (modules parser parser)
- #:use-module (ice-9 match)
- #:use-module (modules ast syntax-tree)
- #:export (p-program))
-
-
-(define (die)
- (error "syntax error"))
-
-(define (p-program tokens)
- (match tokens
- ((func ...)
- (make-program (p-function func)))
- (_ (die))))
-
-(define (p-function tokens)
- (match tokens
- (('int (? string? id) 'left-paren 'void 'right-paren 'open-brace stmt ... 'close-brace)
- (make-function (make-id id) (p-stmt stmt)))
- (_ (die))))
-
-(define (p-stmt tokens)
- (match tokens
- (('return expr ... 'semi-colon)
- (make-stmt (p-expr expr)))
- (_ (die))))
-
-(define (p-expr tokens)
- (match tokens
- (((? integer? int))
- (make-const int))
- (((or 'sub 'complement) expr ...)
- (make-unary (car tokens) (p-expr expr)))
- (('left-paren expr ... 'right-paren)
- (p-expr expr))
- (_ (die))))
diff --git a/src/modules/tuple-generator/tuple-generator.scm b/src/modules/tuple-generator/tuple-generator.scm
deleted file mode 100644
index a2dde2d..0000000
--- a/src/modules/tuple-generator/tuple-generator.scm
+++ /dev/null
@@ -1,36 +0,0 @@
-(define-module (modules tuple-generator tuple-generator)
- #:use-module (ice-9 receive)
- #:use-module (modules utils t-factory)
- #:use-module (modules ast syntax-tree)
- #:use-module (modules ast assembly-tree)
- #:export (t-program))
-
-
-(define (t-program p)
- (make-program (t-function (program-function p))))
-
-(define (t-function f)
- (make-subroutine (t-id (function-id f))
- (t-stmt (function-stmt f))
- #f))
-
-(define (t-stmt s)
- (receive (src instrs) (t-expr (stmt-expr s))
- (append instrs
- (list (make-instruction (make-register 'eax) 'mov src #f)
- (make-instruction #f 'ret #f #f)))))
-
-(define (t-expr e)
- (cond
- ((unary? e)
- (receive (src instrs) (t-expr (unary-expr e))
- (let ((dest (make-temporary)))
- (values dest
- (append instrs
- (list (make-instruction dest 'mov src #f)
- (make-instruction dest (unary-operator e) #f #f)))))))
- (#t (values e '()))))
-
-
-(define (t-id i)
- (id-symbol i))
diff --git a/src/modules/utils/t-factory.scm b/src/modules/utils/t-factory.scm
deleted file mode 100644
index cad7c24..0000000
--- a/src/modules/utils/t-factory.scm
+++ /dev/null
@@ -1,24 +0,0 @@
-(define-module (modules utils t-factory)
- #:use-module (srfi srfi-9)
- #:export (temporary?
- temporary-name
- temporary-register
- set-temporary-register!
- make-temporary
- ))
-
-
-(define-record-type <temporary>
- (make--temporary name register)
- temporary?
- (name temporary-name)
- (register temporary-register set-temporary-register!))
-
-(define make-temporary)
-(let ((count 100))
- (set! make-temporary
- (lambda ()
- (set! count (1+ count))
- (make--temporary (string->symbol
- (format #f "t.~a" count))
- #f))))