From 7173a4214939242b29da9c80a117e55386915034 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 11 May 2015 22:40:17 -0400 Subject: [PATCH] Relocated lib functions, added import helpers --- cyclone.scm | 28 ---------------------------- trans.scm | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/cyclone.scm b/cyclone.scm index 474aaf9a..9716eac9 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -21,34 +21,6 @@ (load "trans.scm") (load "cgen.scm"))) -;; Library section -;; A quicky-and-dirty (for now) implementation of r7rs libraries -;; TODO: relocate this somewhere else, once it works. Ideally -;; somewhere accessible to the interpreter -(define (library? ast) - (tagged-list? 'define-library ast)) -(define (lib:name ast) (cadr ast)) -;; Convert name (as list of symbols) to a mangled string -(define (lib:name->string name) - (apply string-append (map mangle name))) -(define (lib:exports ast) - (and-let* ((code (assoc 'export (cddr ast)))) - (cdr code))) -(define (lib:imports ast) - (and-let* ((code (assoc 'import (cddr ast)))) - (cdr code))) -(define (lib:body ast) - (and-let* ((code (assoc 'begin (cddr ast)))) - (cdr code))) -;; TODO: include, include-ci, cond-expand - -(define (lib:import->filename import) - 'TODO) ;; resolve library filename from an import -(define (lib:import->export-list) - ' TODO) ;; Read export list for a given import - -;; END Library section - ;; Code emission. ; c-compile-and-emit : (string -> A) exp -> void diff --git a/trans.scm b/trans.scm index e09c4e82..a8af92df 100644 --- a/trans.scm +++ b/trans.scm @@ -1764,6 +1764,48 @@ `(lambda () ,(convert exp #f '()))) +;; Library section +;; A quicky-and-dirty (for now) implementation of r7rs libraries +;; TODO: relocate this somewhere else, once it works. Ideally +;; somewhere accessible to the interpreter +(define (library? ast) + (tagged-list? 'define-library ast)) +(define (lib:name ast) (cadr ast)) +;; Convert name (as list of symbols) to a mangled string +(define (lib:name->string name) + (apply string-append (map mangle name))) +(define (lib:exports ast) + (and-let* ((code (assoc 'export (cddr ast)))) + (cdr code))) +(define (lib:imports ast) + (and-let* ((code (assoc 'import (cddr ast)))) + (cdr code))) +(define (lib:body ast) + (and-let* ((code (assoc 'begin (cddr ast)))) + (cdr code))) +;; TODO: include, include-ci, cond-expand + +;; resolve library filename from an import +(define (lib:import->filename import) + (string-append + (apply + string-append + (map + (lambda (i) + (string-append "/" (symbol->string i))) + import)) + ".sld")) +;; Read export list for a given import +(define (lib:import->export-list import basedir) + (let* ((dir (string-append basedir (lib:import->filename import))) + (fp (open-input-file dir)) + (lib (read-all fp)) + (exports (lib:exports (car lib)))) + (close-input-port fp) + exports)) + +;; END Library section + ; Suitable definitions for the cell functions: ;(define (cell value) (lambda (get? new-value) ; (if get? value (set! value new-value))))