* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
* module/language/tree-il.scm (tree-il->scheme):
* module/ice-9/psyntax.scm (build-conditional): Attempt to not generate
(if #f #f) as the second arm of an if, but it doesn't seem to be
successful.
* module/ice-9/psyntax-pp.scm (syntax-rules): Regenerate.
* test-suite/tests/syntax.test (exception:unexpected-syntax): Change
capitalization.
("unquote-splicing"): Update test.
("begin"): Add in second arms on these ifs, to avoid the strange though
harmless expansion of `if'.
(matches?): New helper macro.
("lambda"): Match on lexically bound symbols, as they will be
alpha-renamed.
* module/ice-9/psyntax.scm (chi-lambda-clause): Strip the docstring
before passing it on to the continuation.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/eval.test (exception:failed-match): New exception, for
syntax-case failed matches.
("evaluator"): Fix macro-as-parameter tests. They pass now :)
* module/ice-9/psyntax.scm (chi-install-global, syntax-case): Fix a
couple of cases in which bare datums were passed to output
constructors.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/scheme/spec.scm (scheme): Clean up the #:compilers
list.
* module/language/tree-il/compile-glil.scm (flatten): Fix call to
`length' in call/cc compiler.
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
bound. Used by local-ref and external-ref in paranoid mode.
* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
switching to use psyntax as the first pass of the compiler, and perhaps
soon of the interpreter too, we need to make sure it expands out all
forms to primitive expressions. So define expanders for these derived
syntax forms, as in the R5RS report.
* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
expanded.
* module/ice-9/psyntax.scm (build-void): New constructor, for making
undefined values.
(build-primref): Add in a hack so that primitive refs in the boot
module expand out to toplevel refs, not module refs.
(chi-void): Use build-void.
(if): Define an expander for if that calls build-conditional.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
so as not to depend on binding order for the result of
(current-module).
* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
primary intermediate language. Not yet fully tested, but at least it
can compile psyntax-pp.scm.
* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
count towards a function's nlocs.
* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
Define a "compilation module" fluid.
(flatten-lambda): Fix a call to make-glil-argument. Fix bug in
heapifying arguments.
(flatten): Fix number of arguments passed to apply instruction. Add a
special case for `(values ...)'. If inlining primitive-refs fails,
try expanding into toplevel-refs if the comp-module's variable is the
same as the root variable.
* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
src variable for <module-ref>.
* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
closure test case.
* module/ice-9/psyntax.scm (build-lambda, build-let, build-named-let)
(build-letrec): Actually pass along the original ids to tree-il
constructors.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/tree-il.scm: Add fields in <lambda>, <let>, and
<letrec> for the original variable names.
* module/language/tree-il/compile-glil.scm (compile-glil): Adapt for new
make-lambda arg.
* module/ice-9/psyntax.scm (build-letrec, build-let, build-lambda)
(build-named-let): Take extra args for the original names of the
gensyms. Not used yet. Callers adapted.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/Makefile.am: Add tree-il sources.
* module/ice-9/compile-psyntax.scm: Adjust for sc-expand producing
tree-il in compile mode.
* module/ice-9/psyntax.scm: Switch from expand-support to tree-il for
generating output in compile mode. Completely generate tree-il -- the
output wasn't Scheme before, but now it's completely not Scheme.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/scheme/compile-ghil.scm: Strip structures using
tree-il, not expand-support.
* module/language/tree-il.scm:
* module/language/tree-il/spec.scm
* module/language/tree-il/compile-glil.scm: New language. It will compile
to GLIL, though it doesn't yet.
* module/ice-9/expand-support.scm (make-module-ref, make-lexical): Add
source arguments to these constructors.
* module/ice-9/psyntax.scm:
* module/ice-9/psyntax-pp.scm: Adapt to match, though we don't wire
everything up yet.
* module/ice-9/psyntax.scm (build-global-definition): Remove mod
argument, as it does not seem we could ever define something in another
module.
(chi-install-global): Build the define as a definition, not an
application. Doesn't matter now, but it will later.
(chi-top): Fix build-global-definition call.
* module/ice-9/psyntax.scm: Regenerated.
* module/ice-9/psyntax.scm (build-lexical-reference): Change to be a
function. Take an extra arg, the original name of the variable. If we
are compiling, make a #<lexical>, annotated with the original var name.
All callers changed.
(build-lexical-assignment): Also a function, taking also the original
var name, using build-lexical-reference to build its output.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/psyntax.scm (*mode*): New moving part, a fluid.
(sc-expand): Dynamically bind *mode* to the expansion mode.
(build-global-reference): Change to be a procedure instead of local
syntax. Import the logic about when to make a @ or @@ form to here,
from boot-9.scm. If we are compiling, build output using (ice-9
expand-support)'s make-module-ref, otherwise just making the familiar
s-expressions. (This will allow us to correctly expand in modules in
which @ or @@ are not bound, at least when we are compiling.)
(build-global-assignment): Use the result of build-global-reference. A
bit hacky, but hey.
(top-level-eval-hook, local-eval-hook): Strip expansion structures
before evalling.
* module/ice-9/boot-9.scm (make-module-ref): Remove, this logic is now
back in psyntax.scm.
* module/ice-9/compile-psyntax.scm (source): Since we expand in compile
mode, we need to strip expansion structures.
* module/ice-9/expand-support.scm (strip-expansion-structures): Remove
the logic about whether and how to strip @/@@ from here, as it's part
of psyntax now.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/scheme/compile-ghil.scm (compile-ghil): Strip expansion
structures -- for now. In the future, we might translate directly from
these structures into GHIL.
* module/ice-9/boot-9.scm (sc-expand3):
* module/ice-9/psyntax.scm (sc-expand3): Replace sc-expand with
sc-expand3, as expand3 with one argument is the same as sc-expand.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/compile-psyntax.scm:
* module/language/scheme/compile-ghil.scm: Change callers to sc-expand3
to use sc-expand.
* module/ice-9/boot-9.scm: Comment some more things.
* module/ice-9/psyntax.scm: Remove error-hook -- callers should just use
syntax-violation. Change all callers.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/boot-9.scm (and-map, or-map): Move these definitions up so
psyntax can use them.
(andmap): Remove, yay.
* module/ice-9/psyntax.scm: Remove notes about andmap, and just use
Guile's and-map -- except in cases that need the multiple list support,
in which case we have a private and-map*.
* module/ice-9/psyntax-pp.scm: Regenerated.
* libguile/macros.c (scm_macro_p): Update docs.
* module/ice-9/boot-9.scm (module-define!, module-ref): Define pre-boot
forms of these functions as well. I suspect module-add! can go soon.
(module-lookup-keyword, module-define-keyword!)
(module-undefine-keyword!) Remove these.
* module/ice-9/psyntax-pp.scm: Regenerate. Notice the difference?
* module/ice-9/psyntax.scm (put-global-definition-hook)
(get-global-definition-hook): Rework to expect first-class macros. Heh
heh.
(remove-global-definition-hook): Pleasantly, this hook can go away.
(chi-install-global): Terrorism to generate the right kind of output --
will clean up.
(chi-top): Unify definition handling for all kinds of values.
* libguile/macros.c (macro_print): Show syntax-case bindings, if present.
(macro_mark): Mark the extra two words if they're there.
(scm_make_syncase_macro, scm_make_extended_syncase_macro): OK! A new
take at the "how do we represent syncase macros in Guile" problem.
Whereas we need a disjoint type, but would like it to be compatible
with old predicates (e.g. `macro?'), and need to be able to extend
existing syntax definitions (e.g. `cond'), let's add a bit to macros to
indicate whether they have syncase macro bindings or not, and a fourth
macro type for native syncase macros.
(scm_macro_type): Return 'syntax-case for native syntax-case macros.
Note that other macro types may have syntax-case bindings.
(scm_macro_name): Return #f if the transformer is not a procedure.
(scm_syncase_macro_type, scm_syncase_macro_binding): New accessors for
the syncase macro bindings.
* libguile/macros.h: Add API for syncase macros.
* module/ice-9/boot-9.scm (module-define-keyword!): Adapt to use syncase
macros, though they are not yet used. Reorder other syncase API.
* module/ice-9/psyntax.scm (chi-expr): Fix syntax-violation invocation.
* module/ice-9/boot-9.scm:
* module/ice-9/psyntax-pp.scm:
* module/ice-9/psyntax.scm: Change syntax-dispatch to $sc-dispatch, as it
is in current psyntax. The idea is that this isn't really a public
variable, though it has to be, currently, so just obscure that fact
with an obscure name.
* module/ice-9/boot-9.scm (datum->syntax, syntax->datum): Rename from
datum->syntax-object and syntax-object->datum, following r6rs. Change
all callers. Reorder some of the other exports from psyntax.
* module/ice-9/psyntax.scm: Change datum->syntax and syntax->datum
definitions and callers.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/oop/goops.scm (define-class-pre-definition): Update for changes.
* module/ice-9/boot-9.scm (syntax-violation): Well, as long as we have to
have a function for indicating syntax errors, let's let it be a
well-thought-out one -- syntax-violation from r6rs. No more
syntax-error.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/psyntax.scm: Replace instances of syntax-error with
syntax-violation. Implement as a scm-error to 'syntax-error, with some
nice arguments.
* libguile/modules.c (scm_module_local_variable): Allow this to be called
before modules are booted with #f as the module.
* module/ice-9/boot-9.scm (module-define-keyword!)
(module-lookup-keyword, module-undefine-keyword!): Well, if syncase
forces us to allow the keyword bindings to be partitioned from value
bindings, let's go ahead and do that in boot-9 instead of in
psyntax. A step on the way to removing `install-global-transformer'.
(sc-chi): Remove.
* module/ice-9/psyntax.scm (put-global-definition-hook):
(remove-global-definition-hook, get-global-definition-hook): Use our
new module-* functions.
(sc-chi): Remove, no longer needed.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/boot-9.scm (define-macro, defmacro): Add the ability to
have a docstring.
* module/ice-9/documentation.scm (object-documentation): Remove
references to defmacro? and macro?. Since we store the transformation
procedure as the binding, we can get docs from the procedure directly.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/psyntax.scm (put-global-definition-hook):
Take the type and the value separately, so we can set the variable to
the procedure, while keeping the *sc-expander* to be the "binding
object".
(global-extend): Pass type and val separately.
* module/Makefile.am (SCHEME_LANG_SOURCES):
* module/language/scheme/expand.scm: Remove expand.scm, we don't need it
any more.
* module/ice-9/psyntax.scm (build-lambda, chi-lambda-clause): Support
docstrings with internal definitions. What are Scheme people thinking
these days?
* module/ice-9/psyntax-pp.scm: Regenerated.
* libguile/eval.h:
* libguile/eval.c (scm_m_eval_when): Define a cheap eval-when, used
before syncase has booted.
* module/Makefile.am: Reorder to put (system vm) and (system repl)
modules after the compiler, as they are not needed at runtime.
* module/ice-9/boot-9.scm: Move the eval-when earlier, to be the first
thing -- so when we recompile Guile we do so all in the '(guile)
module, not '(guile-user).
* module/ice-9/compile-psyntax.scm: Rewrite to assume that psyntax.scm
will eval-when to set its module, etc. Have everything in a let --
otherwise the `format' call is in (guile), but `target' was defined
in (guile-user). Also, write in an eval-when to the expanded file.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/networking.scm:
* module/ice-9/psyntax.scm:
* module/ice-9/r4rs.scm: Sprinkles of eval-when, for flavor.
* module/ice-9/psyntax.scm (chi-macro): It's possible for a macro
procedure to have no module, if the procedure was made before modules
were booted.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/psyntax.scm
* module/ice-9/psyntax-pp.scm
* module/ice-9/boot-9.scm (make-module-ref): We were so almost there
with what we had, sniff. The deal is that
(begin (load "foo.scm") ((@@ (foo) bar)))
would expand to
(begin (load "foo.scm") (bar))
because bar was unbound at expansion time, and make-module-ref assumed
it was like the else in a cond. But it shouldn't have, because we
/explicitly/ asked for the @@ var -- so now if we see a @ or @@, we
never drop it. @@ introduced by hygiene can be dropped if it doesn't
reference a var, though.
Practically speaking, this means tagging all modules in psyntax with
their intent: public or private (corresponding to @ or @@), hygiene
(introduced by a macro), or bare (when we don't have a module). I'm
not sure when we'd see a bare.
The implementation is complicated by the need to support the old
format and the new format at the same time, so that psyntax-pp can be
regenerated.
* module/ice-9/boot-9.scm
(make-module-ref): equal?, not eq?, when matching on module name.
(Module names don't have to come from an invocation of module-name in
this process.)
* module/ice-9/psyntax.scm (build-global-reference)
(build-global-assignment, @): Rework the format of the module in syntax
objects so that a car of #f indicates a public reference. Loading (foo
%module-public-interface) didn't guarantee that (foo) was loaded and
useful.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/scheme/compile-ghil.scm (lookup-transformer):
primitive-macro? does not exist any more.
* module/ice-9/boot-9.scm: Remove lots of debugging prints. Remove some
already-deprecated attempts to load modules from shared libraries.
* module/ice-9/psyntax.scm: If we have to create a variable for a
syntactic binding, initialize its contents to a gensym. I'd like
something more meaningful, but at least this way we can tell different
macros apart. Only warn about missing modules if modules are booted.
Chi the value part of a (set! (@ ...) ) expression -- whoops!
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/glil.scm (parse-glil): Fix an unquoting error.
* module/language/scheme/compile-ghil.scm: No need to import syncase, we
gots it. Rework compiler to expand only once, with syncase, instead of
incrementally. Fix define-scheme-transformer to work with syncase, by
not referencing bare keywords. It works!
* module/ice-9/psyntax.scm: Allow the redefinition of keywords to
variables. Otherwise we can't do (define let #f), which is totally
useful and stuff.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/boot-9.scm (module-name): Return '(guile) before the
module system is booted, for syncase's benefit. Defer redefinition
until the module system is booted.
* module/ice-9/psyntax.scm (put-global-definition-hook): Only set a
variable if it's unbound.
* module/ice-9/psyntax.scm: Regenerated.
* module/ice-9/boot-9.scm: Define a version of module-add! for psyntax,
before modules are booted.
* module/ice-9/psyntax.scm: Remove a warning, and rename a variable.
Initialize a new variable to 'sc-macro, though it will have no effect.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/psyntax.scm (syntax-type): Handle a new type, module-ref.
Like external-macro, it also has a procedure as a binding.
(chi-expr): module-ref forms -- that is to say, (@ (foo ...) bar) -- as
expressions they are global references, but with respect to a specific
module.
(@, @@): Define module-ref syntax handlers.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/syncase.scm: Mark as primitive syntax so we don't clobber
their definitions.
The reason I'm doing things like this is so as to support (set! (@@ ...)
...) sensibly, which will be the next patch.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/psyntax.scm (syntax-type): Look up the type of the car of
a form relative to its module, if it is a syntax object. Fixes hygiene
wrt modules and private macros.
* module/ice-9/syncase.scm (sc-macro): Add a comment.
* module/system/base/pmatch.scm: The big test case: just export pmatch,
not ppat too.
* module/ice-9/expand-support.scm (strip-expansion-structures): Enable
@/@@ substitution.
* module/ice-9/psyntax-pp.scm: Recompile.
* module/ice-9/psyntax.scm: Since syntax objects are quotable, make the
module field the module name, not the module itself. Scope the operand
of global calls appropriately. Thread modules through syntax-dispatch
destructuring. Houston, we have hygiene.
* module/ice-9/syncase.scm: Adapt to module / module-name changes.
* module/ice-9/compile-psyntax.scm: No more expansion-eval-closure.
* module/ice-9/expand-support.scm (strip-expansion-structures): Only @@
names whose module is not the current module. Actually @@ serialization
is disabled for this commit, just to get this one in and keep things
working.
* module/ice-9/psyntax-pp.scm: Recompiled.
* module/ice-9/psyntax.scm (put-global-definition-hook)
(get-global-definition-hook): Instead of going through that stupid
getprop/putprop interface, let's just inline Guile-specific code here.
(build-global-reference, build-global-assignment): Fix a bug where the
module and public? were switched, which happily allowed things to
compile. (We reintroduce a similar bug above in expand-support.)
(lookup): Add a module argument.
(global-extend): Adapt for put-global-definition-hook invocation.
(syntax-type): Lookup with mod. Return mod even for lexicals and
define-form -- why not.
(chi-top, fluid-let-syntax, syntax, set!): Lookup with mod. Wrap with
mod.
* module/ice-9/syncase.scm (expansion-eval-closure)
(current-eval-closure, env->eval-closure): OK! So the idea is: module
hygiene is syncase's business, not ours. So lose the eval-closure
fluid. Also, eval closures are so 1990s.
(sc-macro): But, we have to take the module from the env, sadly. In the
future this will be different.
Remove the rest of the eval-closure bits. Enable source reporting,
while we're debugging.
* module/language/scheme/compile-ghil.scm (lookup-transformer): Adapt for
eval closure fluid changes.
* libguile/debug.h:
* libguile/debug.c (scm_procedure_module): New procedure, returns the
module that was current when the given procedure was defined. Used by
syncase to scope free identifiers.
* module/ice-9/psyntax-pp.scm: Recompiled.
* module/ice-9/psyntax.scm: Thread the module through the syntax
expansion. This is harder than it would appear because in many places
the different components of syntax objects are destructured.
* module/ice-9/syncase.scm (guile-macro): Adapt to new signature for
syntax transformer functions.
* module/ice-9/psyntax.scm: Now that we have gone through the
intermediate step (in which both representations of syntax-object had
to coexist), change all callers to make-syntax-object to pass the third
argument, and restore the define-structure definition of syntax
objects.
* module/ice-9/psyntax-pp.scm: Recompile.
* module/ice-9/psyntax.scm (make-syntax-object): As an intermediate step
to adding modules to syntax objects, replace the definition of
syntax-object as a structure with an expanded-out definition that has
(1) a constructor that takes 2 or 3 arguments, and (2) a predicate that
works with vectors of length 3 or 4. I couldn't just redefine
make-syntax-object, for example, because these are internal
definitions, and we can't have duplicate bindings in a letrec.
* module/ice-9/Makefile.am: Replace annotate.scm with expand-support.scm.
* module/ice-9/annotate.scm: Removed; subsumed into expand-support.scm.
* module/ice-9/compile-psyntax.scm: Strip out expansion structures before
writing to disk.
* module/ice-9/expand-support.scm: New file. Provides annotation support,
and other compound data types for use by the expander. Currently the
only one that is used is the toplevel reference, <module-ref>, but we
will record lexicals this way soon.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/psyntax.scm (build-global-reference)
(build-global-assignment): Instead of expanding out global references
as symbols, expand them as <module-ref> structures, with space to
record the module that they should be scoped against. This is in
anticipation of us actually threading the module info through the
syntax transformation, so that we can get hygiene with respect to
modules.
* module/ice-9/syncase.scm: Replace eval-when. Since sc-expand will give
us something that isn't Scheme because we put the <module-ref>
structures in it, strip that info whenever we actually do need scheme.
* module/language/scheme/compile-ghil.scm (lookup-transformer): Strip
expansion structures here too.
* module/language/scheme/expand.scm (language): Swap annotate for
expand-support. But this file will die soon, I think.
* module/ice-9/annotate.scm (set-annotation-stripped!): Fix prototype to
correspond to what syncase needs.
* module/ice-9/psyntax.scm (strip-annotation): Use `if', not `when', for
portability.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/ice-9/psyntax.scm (build-annotated): New helper, used by the
output constructors.
(build-application, build-conditional, build-lexical-reference)
(build-lexical-assignment, build-global-reference)
(build-global-assignment, build-global-definition, build-lambda)
(build-primref, build-data, build-sequence, build-let)
(build-named-let, build-letrec, build-lexical-var): Use
build-annotated, so we produce annotated source if we have source
information.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/annotate.scm (<annotation>): Slightly more concise
printing.
(annotate): Don't create annotations if we have no source info.
* module/ice-9/psyntax.scm (annotation?): Remove this definition, as we
now provide annotation support.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/syncase.scm: Use (ice-9 annotate).
* module/language/scheme/expand.scm (eval-when): Define the eval-when
transformer.
Moved ice-9/ and oop/ under module/, with the idea being that we have
only scheme under module/. Adjusted configure.in and Makefile.am
appropriately. Put oop/ at the end of the compilation order.