HomeAboutCodePastes
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordieggsy <dieggsy@pm.me>2021-03-24 12:25:55 -0400
committerdieggsy <dieggsy@pm.me>2021-03-24 12:25:55 -0400
commitdb7396da60949497a816c9e96cfe919b937c69ef (patch)
tree70b997437e390739b5720e55a285c61f1c23223a
parent4416e7bbde7ec6e3e65d3edc9d8423aafe71f6b0 (diff)
downloadr7rs-tools-db7396da60949497a816c9e96cfe919b937c69ef.tar.gz
Cleanup and documentation
-rwxr-xr-xr7csc.scm3
-rw-r--r--r7csi-bin.scm20
-rw-r--r--r7csi.scm22
-rw-r--r--r7rs-env.scm11
-rw-r--r--r7rs-tools.egg10
-rw-r--r--r7rs-tools.svnwiki60
6 files changed, 94 insertions, 32 deletions
diff --git a/r7csc.scm b/r7csc.scm
index 89b44cb..babb1d8 100755
--- a/r7csc.scm
+++ b/r7csc.scm
@@ -9,7 +9,8 @@
(scheme base)
(chicken foreign))
- (define r7rs-options '("-x" "-X" "r7rs" "-R" "r7rs" "-uses" "library" "-uses" "eval"))
+ (define r7rs-options '("-x" "-X" "r7rs" "-R" "r7rs" "-uses" "library" "-uses" "eval"
+ "-X" "r7rs-env" "-R" "r7rs-env"))
(define (compile)
(let*-values ([(csc) (foreign-value "C_CSC_PROGRAM" c-string)]
diff --git a/r7csi-bin.scm b/r7csi-bin.scm
deleted file mode 100644
index 772c657..0000000
--- a/r7csi-bin.scm
+++ /dev/null
@@ -1,20 +0,0 @@
-(module r7csi ()
- (import (only (chicken process-context) get-environment-variable command-line-arguments)
- (only (chicken process) process-execute)
- (only (chicken base) exit)
- (only (chicken pathname) make-pathname)
- (only (chicken file) file-exists?)
- (scheme base)
- (chicken foreign))
-
- (define r7rs-options
- (append '("-R" "r7csi")))
-
- (define (interpret)
- (let*-values ([(csi) (foreign-value "C_CSI_PROGRAM" c-string)]
- [(path) (foreign-value "C_INSTALL_BIN_HOME" c-string)]
- [(csipath) (or (file-exists? (make-pathname path csi)) "csi")])
- (process-execute csipath
- (append r7rs-options (command-line-arguments)))))
-
- (interpret))
diff --git a/r7csi.scm b/r7csi.scm
index 30835da..8e86c39 100644
--- a/r7csi.scm
+++ b/r7csi.scm
@@ -1,8 +1,20 @@
(module r7csi ()
- (import (scheme base)
- (scheme eval))
+ (import (only (chicken process-context) get-environment-variable command-line-arguments)
+ (only (chicken process) process-execute)
+ (only (chicken base) exit)
+ (only (chicken pathname) make-pathname)
+ (only (chicken file) file-exists?)
+ (scheme base)
+ (chicken foreign))
- (define env (environment '(only chicken.base exit)))
- (##sys#current-environment (##sys#slot env 2))
- (##sys#macro-environment (##sys#slot env 2)))
+ (define r7rs-options
+ (append '("-R" "r7rs-env")))
+ (define (interpret)
+ (let*-values ([(csi) (foreign-value "C_CSI_PROGRAM" c-string)]
+ [(path) (foreign-value "C_INSTALL_BIN_HOME" c-string)]
+ [(csipath) (or (file-exists? (make-pathname path csi)) "csi")])
+ (process-execute csipath
+ (append r7rs-options (command-line-arguments)))))
+
+ (interpret))
diff --git a/r7rs-env.scm b/r7rs-env.scm
new file mode 100644
index 0000000..1e99681
--- /dev/null
+++ b/r7rs-env.scm
@@ -0,0 +1,11 @@
+(module r7rs-env ()
+ (import (scheme base)
+ (scheme eval)
+ (srfi 1))
+
+ (define env (environment '(only chicken.base exit)))
+ (##sys#current-environment (##sys#slot env 2))
+ (##sys#macro-environment (filter-map
+ (lambda (e)
+ (and (list? e) e))
+ (##sys#slot env 2))))
diff --git a/r7rs-tools.egg b/r7rs-tools.egg
index 03c78f5..578d531 100644
--- a/r7rs-tools.egg
+++ b/r7rs-tools.egg
@@ -1,10 +1,8 @@
-((synopsis "'Pure' r7rs compiler and interpreter")
+((synopsis "\"Pure\" r7rs compiler and interpreter")
(category tools)
(author "Diego A. Mundo")
(license "public domain")
- (dependencies r7rs)
- (components (program r7csi-bin
- (csc-options "-O3" "-d0")
- (install-name r7csi))
- (extension r7csi)
+ (dependencies r7rs srfi-1)
+ (components (program r7csi (csc-options "-O3" "-d0"))
+ (extension r7rs-env)
(program r7csc (csc-options "-O3" "-d0"))))
diff --git a/r7rs-tools.svnwiki b/r7rs-tools.svnwiki
new file mode 100644
index 0000000..d2df284
--- /dev/null
+++ b/r7rs-tools.svnwiki
@@ -0,0 +1,60 @@
+[[tags: egg]]
+[[toc:]]
+
+== r7rs-tools
+
+"Pure" r7rs compiler and interpreter.
+
+"Pure" = only {{(scheme base)}} by default, no {{scheme}}, {{chicken.base}}, or
+{{chicken.syntax}})
+
+=== r7rs-env module
+
+The core of {{r7rs-tools}}, uses a hack around {{##sys#current-environment}}
+and {{##sys#macro-environment}} to set the environment to only include
+procedures and syntax from {{(scheme base)}}. You can manually reset the
+environment to {{(scheme base)}} by using {{(import r7rs-env)}}.
+
+The following is the full implementation of this module:
+
+<enscript highlight="scheme">
+(module r7rs-env ()
+ (import (scheme base)
+ (scheme eval)
+ (srfi 1))
+
+ (define env (environment '(only chicken.base exit)))
+ (##sys#current-environment (##sys#slot env 2))
+ (##sys#macro-environment (filter-map
+ (lambda (e)
+ (and (list? e) e))
+ (##sys#slot env 2))))
+</enscript>
+
+=== r7csc program
+
+The {{r7csc}} program is equivalent to the following invocation of {{csc}}:
+
+ csc -x -X r7rs -R r7rs -uses library -X r7rs-env -R r7rs-env [args ...]
+
+This makes {{csc}} compile with an initial environment containing only exports
+of {{(scheme base)}}.
+
+=== r7csi program
+
+The {{r7csi}} program is equivalent to the following invocation of {{csi}}:
+
+ csi -R r7rs-env [args ...]
+
+This starts {{csi}} with an initial environment containing only exports of
+{{(scheme base)}}
+
+=== Caveats
+
+The implementation currently uses CHICKEN internals because I couldn't really
+find a satisfactory way to achieve it otherwise, which means it may be subject
+to more instability with new updates to the core system.
+
+I'm not an expert on CHICKEN's internals, so at the end of the day this is
+simply a best effort through kludges and trial and error that seems to work.
+More testing may still be required. Suggestions and improvements welcome!