summaryrefslogtreecommitdiff
path: root/module/language/scheme
AgeCommit message (Collapse)AuthorFilesLines
2012-03-03Merge branch 'stable-2.0'Mark H Weaver1-3/+800
Conflicts: module/ice-9/psyntax-pp.scm module/language/tree-il.scm
2012-03-03tree-il->scheme improvementsMark H Weaver1-3/+792
* module/language/tree-il.scm (tree-il->scheme): New implementation that simply calls 'decompile-tree-il'. * module/language/scheme/decompile-tree-il.scm (choose-output-names, do-decompile): New internal procedures. (decompile-tree-il): New and improved implementation. Print source identifiers where possible, otherwise add minimal numeric suffixes. Previously we printed the gensyms. Avoid 'begin' in contexts that provide an implicit 'begin'. Produce 'cond', 'case', 'and', 'or', 'let*', named let, and internal defines where appropriate. Recognize keyword arguments in 'opts' to disable the production of these derived syntactic forms, and to optionally strip numeric suffixes from variable names. * module/ice-9/compile-psyntax.scm: Disable partial evaluation, letrec fixing, and primitive expansion when producing psyntax-pp.scm, in order to produce output as close to the original source as practical. Disable production of derived syntactic forms as needed during bootstrap. Strip numeric suffixes from variable names. Adjust pretty-printing parameters. * module/ice-9/psyntax-pp.scm: Regenerate. It is now less than half of the original size.
2012-01-26Add warnings for unsupported `simple-format' options.Ludovic Courtès1-1/+8
* module/language/tree-il/analyze.scm (format-analysis)[check-simple-format-args]: New procedure. Use it. Add support for applications of <module-ref>. * module/system/base/message.scm (%warning-types): Handle the `format simple-format' warning. * module/language/scheme/spec.scm (scheme)[make-default-environment]: Use `simple-format' as the default `format'. * test-suite/tests/tree-il.test ("warnings")["format"]: Explicitly use (@ (ice-9 format) format) where needed. ("simple-format"): New test prefix.
2011-02-13read-enable 'positions by defaultAndy Wingo1-7/+1
* libguile/read.c (scm_read_opts): Default "positions" to #t. The compiler was already turning it on anyway, and this allows primitive-load without --auto-compile to also propagate source information through the expander, for better errors and to let macros know their source. * module/language/scheme/spec.scm: No need to enable positions here now.
2010-05-02fix a comment about environments and the scheme compilerAndy Wingo1-2/+1
* module/language/scheme/compile-tree-il.scm: Fix a comment about the format of environments.
2010-05-02remove `version' field from <language>Andy Wingo1-3/+2
* module/system/base/language.scm (<language>): Remove the `version' field from languages. It just wasn't useful. * module/language/assembly/spec.scm: * module/language/brainfuck/spec.scm: * module/language/bytecode/spec.scm: * module/language/ecmascript/spec.scm: * module/language/elisp/spec.scm: * module/language/glil/spec.scm: * module/language/objcode/spec.scm: * module/language/scheme/spec.scm: * module/language/tree-il/spec.scm: * module/language/value/spec.scm: Remove #:version from all language definitions. Shorten some language names (e.g. "Guile Scheme" -> "Scheme").
2010-03-19rename sc-expand to macroexpandAndy Wingo1-2/+2
* module/ice-9/boot-9.scm (macroexpand): Rename from sc-expand. (%pre-modules-transformer): Adapt to name change. * module/ice-9/compile-psyntax.scm: Adapt to name change. * module/ice-9/psyntax-pp.scm: Regenerated. * module/ice-9/psyntax.scm: Rename sc-expand to macroexpand. * module/language/scheme/compile-tree-il.scm (compile-tree-il): Adapt to name change.
2009-10-16compilation enviroments are always modules; simplifications & refactoringsAndy Wingo2-38/+14
* module/ice-9/boot-9.scm (make-fresh-user-module): New public function, makes an anonymous beautified module. * module/language/objcode/spec.scm: We used to have some things in here that allowed lexical variable names and values to be a part of the environment, but no more. Now an environment is just a module. If you want to "inject" free variables into code, just use lambda. * module/language/scheme/compile-tree-il.scm (compile-tree-il): Same here. Also, rely on the fact that an environment *will* be a module -- because (system base compile) guarantees that for us. * module/language/scheme/spec.scm (scheme): In the reader, rely on the environment being a module. Define a #:make-default-environment handler, which returns a beautified module, augmented with a fresh definition for current-reader, so that side effects to current-reader are restricted to the compilation unit. * module/language/tree-il/analyze.scm (report-possibly-unbound-variables): * module/language/tree-il/compile-glil.scm (compile-glil): * module/language/tree-il/optimize.scm (optimize!): The environment will be a module. * module/system/base/language.scm (<language>): New field, `make-default-environment'. Defaults to `make-fresh-user-module'. (default-environment): New accessor, returns a default environment for a language. * module/system/repl/common.scm (repl-compile): Always compile relative to the current module, because a module is always acceptable as an environment. * module/system/base/compile.scm (compile-file, compile-and-load): Both of these have a new keyword argument, #:env. For `compile-file', it defaults to the default environment of the source language, and for `compile-and-load', to the current module. (read-and-compile): If there are no expressions read, pass the joiner its default environment (via `default-environment joint').
2009-10-16language-readers receive environment as an argAndy Wingo1-13/+12
* module/language/assembly/spec.scm: * module/language/brainfuck/spec.scm: * module/language/bytecode/spec.scm: * module/language/ecmascript/spec.scm: * module/language/glil/spec.scm: * module/language/scheme/spec.scm: * module/language/tree-il/spec.scm: Language-readers now take two arguments: the port and the environment. This should allow for compile-environment-specific reader behavior. * module/system/base/compile.scm (read-and-compile): * module/system/repl/common.scm (repl-read): Pass the environment to the language-reader. * module/system/repl/repl.scm (meta-reader, prompting-meta-read): * module/system/repl/command.scm (define-meta-command): Use the second argument to repl-reader, so we avoid frobbing current-reader.
2009-10-16remove GHIL, Elisp, and R5RS languagesAndy Wingo2-699/+0
GHIL is obsolete, and it's about time we got rid of it. Elisp and R5RS were unmodified since their import from Guile-VM, so we ditch them too. R5RS compilation is supported via compiling Scheme within an R5RS environment. Elisp will be supported when we merge in Daniel's work.
2009-09-20Honor and confine expansion-time side-effects to `current-reader'.Ludovic Courtès1-1/+15
* module/language/scheme/spec.scm (scheme)[#:reader]: Honor the compilation environment's `current-reader'. * module/system/base/compile.scm (*compilation-environment*): New fluid. (current-compilation-environment): New procedure. (make-compilation-module): Provide a fresh `current-reader' fluid. (read-and-compile): Set `*compilation-environment*' appropriately. (compile): Likewise. * test-suite/tests/compiler.test (read-and-compile): New. ("current-reader"): New test prefix.
2009-08-06actually implement "fixing letrec"Andy Wingo1-4/+2
* module/Makefile.am (SOURCES): Reorganize so GHIL is compiled last, along with ecmascript. * module/language/scheme/spec.scm: Remove references to GHIL, as it's bitrotten and obsolete.. * module/language/tree-il.scm (make-tree-il-folder): Rework so that we only have down and up procs, and call down and up on each element. * module/language/tree-il/analyze.scm (analyze-lexicals): Fix a thinko handling let-values. * module/language/tree-il/fix-letrec.scm: Actually implement fixing letrec. The resulting code will perform better, but violations of the letrec restriction are not detected. This behavior is allowed by the spec, but it is undesirable. Perhaps that will be fixed later. * module/language/tree-il/inline.scm (inline!): Fix a case in which ((lambda args foo)) would be erroneously inlined to foo. Remove empty let, letrec, and fix statements. * module/language/tree-il/primitives.scm (effect-free-primitive?): New public predicate.
2009-06-17Change Guile license to LGPLv3+Neil Jerram5-70/+65
(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* )
2009-05-24update docs, clean up VM vestiges, macro docs, fix (/ a b c)Andy Wingo1-7/+0
* doc/ref/api-procedures.texi (Compiled Procedures): Fix for API changes. * doc/ref/compiler.texi (Compiling to the Virtual Machine): Replace GHIL docs with Tree-IL docs. Update the bits about the Scheme compiler to talk about Tree-IL and the expander instead of GHIL. Remove <glil-argument>. Add placeholder sections for assembly and bytecode. * doc/ref/vm.texi: Update examples with what currently happens. Reword some things. Fix a couple errors. * libguile/vm-i-system.c (externals): Remove this instruction, it's not used. * module/ice-9/documentation.scm (object-documentation): If the object is a macro, try to return documentation on the macro transformer. * module/language/assembly/disassemble.scm (disassemble-load-program): Fix problem in which we skipped the first element of the object vector, because of changes to procedure layouts a few months ago. * module/language/scheme/spec.scm (read-file): Remove read-file definition. * module/language/tree-il.scm: Reorder exports. Remove <lexical>, it was a compat shim to something that was never released. Fix `location'. * module/language/tree-il/primitives.scm (/): Fix expander for more than two args to /. * module/system/base/compile.scm (read-file-in): Remove unused definition. * module/system/base/language.scm (system): Remove language-read-file. * module/language/ecmascript/spec.scm (ecmascript): Remove read-file definition.
2009-05-20remove compile-time-environmentAndy Wingo1-10/+0
* module/ice-9/boot-9.scm (guile-user): Move the `compile' autoload to the guile-user module. Remove reference to compile-time-environment. * module/language/scheme/compile-ghil.scm: * module/language/tree-il/compile-glil.scm: * module/language/tree-il/optimize.scm: * module/system/base/compile.scm: * test-suite/tests/compiler.test: Remove definition of and references to compile-time-environment. While I do think that recompilation based on a lexical environment can be useful, I think it needs to be implemented differently. So for now we've lost nothing if we take it away, as it doesn't work with syncase anyway.
2009-05-20a few fixupsAndy Wingo1-4/+2
* 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.
2009-05-20and, or, cond etc use syntax-rules, compile scheme through tree-ilAndy Wingo2-5/+7
* 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.
2009-05-08more work on tree-il compilationAndy Wingo5-38/+96
* module/language/scheme/amatch.scm: Remove, this approach won't be used. * module/Makefile.am: Adjust for additions and removals. * module/language/scheme/compile-ghil.scm: Remove an vestigial debugging statement. * module/language/scheme/spec.scm: * module/language/scheme/compile-tree-il.scm: * module/language/scheme/decompile-tree-il.scm: Add tree-il compiler and decompiler. * module/language/tree-il/compile-glil.scm: Add some notes. * module/language/tree-il/spec.scm: No need to wrap expressions in lambdas -- GHIL needs somewhere to put its variables, we don't.
2009-05-07new language: tree-il. psyntax generates it when run in compile mode.Andy Wingo1-2/+2
* 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.
2009-05-04sc-expand in compile mode produces (ice-9 expand-support) structuresAndy Wingo1-1/+3
* 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.
2009-05-04replace sc-expand with sc-expand3, removing binding for sc-expand3Andy Wingo1-1/+1
* 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.
2009-04-24allow docstrings with internal definitionsAndy Wingo1-306/+0
* 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.
2009-04-24fix @ and syncaseAndy Wingo1-3/+0
* 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.
2009-04-24ice-9 syncase now deprecated, wooAndy Wingo2-4/+1
Remove #:use-module (ice-9 syncase) from lots of places, as it's no longer needed.
2009-04-24it is alive!!!!! + concision + fix to compile-ghilAndy Wingo1-24/+9
* 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!
2009-04-21commit some tweaks to expand.scm, likely obviated by syncase thoughAndy Wingo1-3/+3
* module/language/scheme/expand.scm (re-annotate, expand): A couple of speculative cases for dealing with syncase better -- but all of this code is likely to go.
2009-04-17hygienic compilationAndy Wingo1-6/+14
* module/language/scheme/compile-ghil.scm (lookup-transformer): Recognize macros as initial (@ ...) or (@@ ...) forms, enabling hygienic compilation.
2009-04-17more work on modules and hygiene, not finished yet, alas.Andy Wingo1-5/+3
* 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.
2009-04-17serialize module information into syncase's output -- getting ready for hygieneAndy Wingo2-2/+4
* 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.
2009-04-16support expression-by-expression compilationAndy Wingo1-9/+9
* module/language/ghil.scm (unparse-ghil): Fix unparsing of quasiquoted expressions. * module/language/ghil/spec.scm (join): Define a joiner for GHIL. * module/language/scheme/compile-ghil.scm (cenv-ghil-env): Expand the definition of a CENV so it can have an actual ghil-env, if available. (compile-ghil): Return the actual ghil env in the cenv. * module/system/base/compile.scm (compile-file): Rewrite. `output-file' is now a keyword argument, along with the new kwargs `env' and `from'. We now allow exceptions to propagate up, and instead of printing the output file to the console, we return a string corresponding to its location. (compile-and-load): Use read-and-compile. (compile-fold): Thread around the cenv as well. Return all three values. (find-language-joint, read-and-compile): New exciting helpers. The idea is that compiling a file should be semantically equivalent to compiling each expression in it, one by one. Compilation can have side effects, e.g. affecting the current language or the current reader. So what we do is find a point in the compilation path at which different expressions of a given language can be joined into one. Expressions from the source language are compiled to the joint language, then joined and compiled to the target. (compile): Just return the first value from compile-fold. * module/system/base/language.scm (language-joiner): New optional field. * scripts/compile: Rework for changes to compile-file.
2009-04-16compilation passes return third value: the continuation environmentAndy Wingo1-5/+10
* module/system/base/compile.scm: Expect compile passes to produce three values, not two. The third is the "continuation environment", the environment that can be used to compile a subsequent expression from the same source language. For example, expansion-time side effects can set the current module, which would be reflected appropriately in the continuation environment. * module/language/assembly/compile-bytecode.scm: * module/language/bytecode/spec.scm: * module/language/ecmascript/compile-ghil.scm: * module/language/ghil/compile-glil.scm: * module/language/glil/spec.scm: * module/language/objcode/spec.scm: * module/language/scheme/compile-ghil.scm: * module/system/base/compile.scm: Update compile passes to return a continuation environment.
2009-03-06support source-level annotations in syncaseAndy Wingo1-5/+7
* 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.
2009-03-06Replace eval-case with eval-whenAndy Wingo2-31/+12
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when. Eval-when is *much* simpler, and more expressive to boot. Perhaps in the future we'll get 'visit and 'revisit too. * module/ice-9/deprecated.scm (eval-case): Provide mostly-working deprecated version of eval-case. * module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we can make defmacros that are not at the toplevel now. But in the future we should replace this implementation of defmacros with one written in syntax-case. (define-module, use-modules, use-syntax): Allow at non-toplevel. (define-public, defmacro-public, export, re-export): Don't evaluate at compile-time, I can't see how that helps things. Allow `export' and `re-export' at non-toplevel. * module/ice-9/getopt-long.scm: * module/ice-9/i18n.scm: * module/oop/goops.scm: * module/oop/goops/compile.scm: * module/oop/goops/dispatch.scm: Switch to use eval-when, not eval-case. * module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case transformer with eval-when transformer. Sooooo much simpler, and it will get better once we separate expansion from compilation. * module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote properly. Not hygienic. Syncase needed. (lambda): Handle internal defines with docstrings propertly.
2009-03-02fixups to expand.scmAndy Wingo1-15/+16
* module/language/scheme/expand.scm: Some changes to avoid unnecessary begins or empty lets, and properly handle internal defines (finally).
2009-03-02add separate expansion phase, to detwingle things a bitAndy Wingo2-0/+337
* module/language/scheme/expand.scm: New module, implements a separate expansion phase, not interleaved with compilation. * module/language/scheme/amatch.scm: Helper for expand.scm, it's pmatch with support for annotated source. * module/ice-9/Makefile.am (SOURCES): Add annotate.scm to build list -- early on because it will be used in the compiler. * module/ice-9/annotate.scm: Fix the printer, default to unstripped (whatever that is), and add a deannotator. * module/system/base/compile.scm (call-with-compile-error-catch): Fix for new representation of source locations. * module/Makefile.am (SCHEME_LANG_SOURCES): Add amatch and expand.
2009-02-27use -> macro in scheme->ghil compilerAndy Wingo1-41/+46
* module/language/scheme/compile-ghil.scm (->): New macro, makes GHIL generation a bit more palatable. Use it in all the transformers.
2009-02-24Aggregate makefiles for `module/system' and `module/language'.Ludovic Courtès1-3/+0
* am/guilec (.scm.go): Create the target's directory, in case $(builddir) != $(srcdir). * configure.in: Don't output any makefile under `module/system' or `module/language'. * module/Makefile.am (SUBDIRS): Remove `language' and `system'. Add `.' to the front. (modpath, SOURCES, SCHEME_LANG_SOURCES, ECMASCRIPT_LANG_SOURCES, GHIL_LANG_SOURCES, GLIL_LANG_SOURCES, ASSEMBLY_LANG_SOURCES, BYTECODE_LANG_SOURCES, OBJCODE_LANG_SOURCES, VALUE_LANG_SOURCES): New variables, taken from former `Makefile.am' files in sub-directories.
2009-02-21compile ecmascript's parser. yay! instant load-time!Andy Wingo1-0/+2
* module/language/ghil/compile-glil.scm (codegen): If there are more than 255 arguments, make a list and use apply instead of calling directly. * module/language/Makefile.am: Now we can compile parse.scm. Yay! * module/language/scheme/compile-ghil.scm: Add a note. * module/language/ecmascript/compile-ghil.scm: Add a note.
2009-02-21be smarter about allocating local variables, reusing slots if possibleAndy Wingo1-9/+9
* module/language/Makefile.am: OK, we can compile compile-ghil.scm now, thankfully. * module/language/ecmascript/compile-ghil.scm (ormatch): New macro, a wrapper around pmatch to avoid some of the more egregious non-tail recursiveness. (comp): Use ormatch. * module/language/ghil.scm (unparse-ghil): The body of bind and mv-bind is a single expression, not a list of expressions. * module/language/ghil/compile-glil.scm (codegen): Be more clever when allocating "local" variables -- if a variable goes out of scope, its index can be re-used later. * module/language/glil.scm (parse-glil, unparse-ghil): The "rest" of a mv-bind is a flag, not a list. The "ra" of an mv-call is a label, not a GLIL expression. * module/language/objcode/spec.scm (collapse-locals, decompile-value): When decompiling a value, process the bindings list differently. Comments in the code. * module/language/scheme/compile-ghil.scm (define-scheme-translator): Fix the generated error procedure. (let): Re-indent. (letrec): Re-indent. * module/system/base/syntax.scm (record-case): If the body of a clause is null, fill it with the unspecified value.
2009-02-14generate the fixed-offset accessors at compile-timeAndy Wingo1-2/+3
* module/language/scheme/compile-ghil.scm (define-scheme-translator): Only add an else clause if the transformer didn't have one. * module/oop/goops.scm (min-fixnum, max-fixnum): Define at compile-time as well. (@slot-ref, @slot-set!): Only define transformers for these at compile-time. Avoids loading up the compiler unnecessarily. Also, allow for the `n' to be determined lexically, in which case we dispatch to the primitive. (num-standard-pre-cache, define-standard-accessor-method) (bound-check-get, standard-get, standard-set): Rework the fixed-offset getters and setters so that they can be computed at compile-time. Accessors to fields with n > num-standard-pre-cache will be dispatched to the primitive instead of within the VM.
2009-02-13no keyword arguments in GHIL / GLIL, just optional args -- faster compilesAndy Wingo1-3/+3
* module/system/base/syntax.scm (define-record): So, in the generated constructors, allow optional arguments, but not keyword arguments. Conses much less in the constructors. (define-record/keywords): And the old define-record is here. * module/language/ghil.scm (parse-ghil): * module/language/ghil/compile-glil.scm (codegen): * module/language/scheme/compile-ghil.scm (translate-1, quote) (quasiquote): Don't use keywords in this compiler hotpath. * module/system/base/language.scm (<language>): * module/system/repl/common.scm (<repl>): * module/system/vm/debug.scm (<debugger>): Use define-record/keywords.
2009-02-10propagate much more source info through compilationAndy Wingo1-5/+7
* module/language/ghil/compile-glil.scm (codegen): Record source location for offset 0 into a lambda, if we can. * module/language/scheme/compile-ghil.scm (translate-1) (define-scheme-translator): In the retrans procedures, propagate the location information from the enclosing expression if the subexpression has no location information. Gives source information to many more expressions. (location): Just propagate the source properties as they are, the glil->assembly compiler will interpret them. * module/language/glil.scm (<glil>): Change glil-source to take "props" and not "loc", as it's the source properties that we're interested in. * module/language/glil/compile-assembly.scm (limn-sources): New function, takes a list of addr-source property pairs and "compresses" them for serialization to disk. (glil->assembly): Limn the sources before writing them to disk. Avoid non-tail recursion when determining total byte length of code. * module/system/vm/program.scm (source:file, source:line, source:column): Update for new source representation. (program-source): Export. (write-program): Nicer pretty-printing of anonymous procedures. * libguile/backtrace.c (display_backtrace_get_file_line): Update for the new VM source representation. * libguile/programs.h: * libguile/programs.c (scm_program_sources): Update for the new serialized source representation, where the filename is not in the stream unless it changes. (scm_program_source): New exported function, looks up the source for a given ip offset. (scm_c_program_source): Update to return the last source information that was <= the given IP, because we only serialize source info when it changes.
2009-02-09nicety in the compilerAndy Wingo1-3/+2
* module/language/scheme/compile-ghil.scm (lookup-transformer): Use @@. Delightfully metacircular.
2009-02-09allow defmacros to unquote in macros into expanded expressionsAndy Wingo1-6/+11
* module/language/scheme/compile-ghil.scm (lookup-transformer): Allow macros to be unquoted into the car of any form that results from macro expansion. This lets modules export defmacros built on other defmacros that are not exported.
2009-02-09minor cleanupsAndy Wingo1-5/+5
* libguile/stacks.c (scm_make_stack): Instead of aborting when we misread the number of stack frames, just print a warning. I'd like to figure out what these cases are, exactly. * module/language/scheme/compile-ghil.scm (lambda): Reindent the lambda transformer. * module/system/base/compile.scm (call-with-compile-error-catch): Write the expression instead of displaying it. (call-with-output-file/atomic): Don't actually redirect output to this port, as it's not necessary -- the language-printer should respect the port that we pass.
2009-02-02Name anonymous let- or letrec-bound proceduresAndy Wingo1-2/+7
* module/language/scheme/compile-ghil.scm (let, letrec): Give names to procedures of the form (let ((foo (lambda ....)))).
2009-01-30allow specification of languages by name; add decompilers to languagesAndy Wingo1-2/+1
* module/system/base/language.scm (lookup-decompilation-order): New function, like its compiling cousin, but backwards. (compute-translation-order): Rework so that languages can be specified either by name or by identity. Return a list of language - procedure pairs, without the "to" language in the list, instead of a list of languages. (invalidate-compilation-cache!): Invalidate the decompilation cache too. (<language>): Add a decompiler field. * module/system/base/compile.scm (compile-passes): Much simpler now that lookup-compilation-order gives us the procedures directly. * module/language/*/spec.scm: Specify compilers by name, so that we can avoid unnecessary module loads, and so that when we specify decompilers, we can avoid cycles.
2009-01-29static opcodes; refactor program/objcode division; use new assembly pipelineAndy Wingo1-0/+3
* gdbinit: Untested attempts to get the stack fondling macros to deal with the new program representation. * libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source) (scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is a struct scm_objcode*. * libguile/instructions.h: * libguile/instructions.c: Hide the instruction table and the struct scm_instruction structure; all access to instructions now goes through procedures. This is because instructions are no longer in a packed array indexed by opcode. Also, declare a mask that all instructions should fit in. * libguile/objcodes.h: * libguile/objcodes.c: Rewrite so that object code directly maps its arity and length from its bytecode. This makes it unnecessary to keep this information in programs, allowing programs to be simple conses between the code (objcodes) and data (the object table and the closure variables). * libguile/programs.c (scm_make_program): Rework so that make-program takes objcode, an object table, and externals as arguments. It's much clearer this way, and we avoid malloc(). * libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode changes. * libguile/vm-engine.c (vm_run): Initialize the jump table on the first run, with the opcodes declared in the instruction sources, and with bad instructions raising an error instead of wandering off into the Unknown. * libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3 bytes. The old code was too error-prone. (NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK. (NEW_FRAME): Update for program/objcode changes. * libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION) (VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so that we have a stable bytecode API. * libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare opcodes. (load-integer): Use an int instead of a long as the accumulator; still need to revisit this code at some point, I think. (load-program): Simplify, thankfully!! Just creates the objcode slice and rolls with it. * libguile/vm-i-scheme.c: Number the opcodes explicitly. * libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare opcodes. (make-closure): Update for new program API. * libguile/vm.c (vm_make_boot_program): Update for new program/objcode API. Still a bit ugly. (scm_load_compiled_with_vm): Update for new program/objcode API. * module/language/assembly.scm (byte-length): Fix byte-length calculation for loaders, and load-program. (code-pack, code-unpack): Start to move things from (system vm conv) here. (object->code, code->object): More things from conv.scm. * module/language/glil.scm (<glil-program>): Add a new field, closure-level. (make-glil-program, compute-closure-level): Calculate the "closure level" when making a glil program. This is the maximum depth of external binding refs in this closure. (unparse-glil): Fix label serialization. * module/language/glil/compile-assembly.scm (make-meta): Prepend #f for the meta's object table, though maybe in the future we can avoid creating assembly in the first place. (assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the different sets of arguments to assoc and assoc-ref! (glil->assembly): Attempt to make the <glil-program> case more readable, and fix the bugs. Sorry I don't know how to comment this change any more than this. (glil->assembly): For <glil-module> serialize the whole key, not just the name. (dump-object): subprogram-code is already a list. Serialize integers as strings, not u8vectors. Fix the order of lists and vectors. * module/language/glil/spec.scm (glil): Switch orders, so we prefer glil -> assembly -> objcode. Actually glil->objcode doesn't work any more, needs to be removed I think. * module/language/objcode/spec.scm (objcode->value): s/objcode->program/make-program/. * module/language/scheme/inline.scm: Add acons inline. * module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes, they are header. Handle subprograms properly. Still needs help though. (decode-length): Lengths are always 3 bytes now. * module/system/vm/disasm.scm: Superficial changes to keep things working. I'd like to fix this better in the future. * module/system/vm/frame.scm (bootstrap-frame?): Fixes for program-bytecode. * module/system/vm/program.scm: Export make-program. It's program-objcode now, no more program-bytecode. * module/system/vm/vm.scm (vm-load): Use make-program. * test-suite/tests/asm-to-bytecode.test: New test, very minimal. * module/system/vm/objcode.scm: Export word-size, byte-order, and write-objcode.
2009-01-09rename translate.scm to compile-ghil.scm, and more work on compiler.texiAndy Wingo3-8/+8
* doc/ref/api-evaluation.texi: Fix some typos and xrefs. * doc/ref/compiler.texi (The Scheme Compiler): Document the scheme compiler, and start documenting the GHIL language. * doc/ref/guile.texi (Guile Implementation): Whoops, put autoconf after the implementation foo. Unless we want it before? * doc/ref/history.texi (The Emacs Thesis): Fix typo. * doc/ref/vm.texi (Environment Control Instructions): Rename offset to index. * module/language/ghil.scm (parse-ghil): Fix what I think was a bug -- the consumer in a mv-call shouldn't be a rest arg. * module/language/scheme/Makefile.am (SOURCES): * module/language/scheme/compile-ghil.scm: Rename this file from translate.scm. * module/oop/goops.scm: * module/language/scheme/spec.scm: Deal with renaming.
2009-01-08(language ghil def) becomes (language ghil)Andy Wingo2-4/+4
* module/language/Makefile.am: * module/language/ghil/Makefile.am: * module/language/ghil.scm: * module/language/ghil/compile-glil.scm: * module/language/ghil/spec.scm: * module/language/glil/Makefile.am: * module/language/glil.scm: * module/language/glil/compile-objcode.scm: * module/language/glil/spec.scm: * module/language/scheme/inline.scm: * module/language/scheme/translate.scm: * module/oop/goops.scm: Rename (language ghil def) and (language glil def) to not have the "def". They're nicer names.