HomeAboutCodePastes
summaryrefslogtreecommitdiff
path: root/r7rs-tools.svnwiki
blob: 18509e2800d1f7d0fe092d42469f64f7d72f88a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[[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 the 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!

=== Author

[[https://wiki.call-cc.org/users/diego-mundo|Diego A. Mundo]]

=== Repository

[[https://code.dieggsy.com/r7rs-tools/]]

=== Version history

; 0.1.0 : Initial release

=== License

Public Domain