summaryrefslogtreecommitdiff
path: root/module/ice-9/psyntax-pp.scm
AgeCommit message (Collapse)AuthorFilesLines
2024-12-06Temporarily revert commit 7379049d3 (to make Guile bootstrap)Mikael Djurfeldt1-130/+66
2024-11-25psyntax: simplify free-id=?Andy Wingo1-60/+61
* module/ice-9/psyntax.scm (free-id=?): Simplify. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-20psyntax: Cosmetic change to overriden globalsAndy Wingo1-142/+159
* module/ice-9/psyntax.scm (define/override, define*/override): Use instead of set! on globals. ($sc-dispatch): Renest. Will compile to the same thing as before. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19psyntax: Clean up sourcev/src namingsAndy Wingo1-9/+8
* module/ice-9/psyntax.scm: Look forward to the all-sourcev world by just naming things "src". * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19psyntax: Simplify output constructors.Andy Wingo1-83/+73
* module/ice-9/psyntax.scm: Eta-reduce build-void, build-call, et al. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19psyntax: Factor module-variable use to helpersAndy Wingo1-65/+131
* module/ice-9/psyntax.scm (resolve-module*, resolve-variable): New helpers. (free-id=?, resolve-identifier): Use new helpers. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-19psyntax: Remove stale analyze-variable caseAndy Wingo1-69/+61
* module/ice-9/psyntax.scm (analyze-variable): Remove "bare" case, long gone. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18psyntax: Separate core expanders from their installationAndy Wingo1-721/+758
* module/ice-9/psyntax.scm (expand-let, expand-letrec, ...): Name these expanders, then install them. Allows for better code evolution and decreases the indent. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18psyntax: Remove pre-3.0 hack about syntax transformer bindings.Andy Wingo1-38/+34
* module/ice-9/psyntax.scm (resolve-identifier): Remove "transformer is a pair" case. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18psyntax: Simplify to first-order bindings. NFCAndy Wingo1-80/+82
* module/ice-9/psyntax.scm (no-source, make-empty-ribcage): Make normal bindings, not macros.
2024-11-18psyntax: Match when rebuilding macro outputAndy Wingo1-80/+169
* module/ice-9/psyntax.scm (expand-macro): Use match. (eval-local-transformer): Use unless for side effect. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18psyntax: Simplify locally-bound-identifiersAndy Wingo1-78/+121
* module/ice-9/psyntax.scm (locally-bound-identifiers): Simplify to use match and scope. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18psyntax: Simplify id-var-nameAndy Wingo1-103/+201
* module/ice-9/psyntax.scm (id-var-name): No need for `search` to return the marks. Simplify to use scope instead of repeating, and use match. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-18psyntax: Fix bug introduced in 029540948367fe522f9a105f403c12Andy Wingo1-59/+55
* module/ice-9/psyntax.scm (analyze-variable): Fix erroneous pattern matching. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-15psyntax: Use new `match' instead of cdadringAndy Wingo1-143/+225
* module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/psyntax.scm: Use `match' more. Also use more first-order definitions. NFC.
2024-11-15psyntax: Use new `match' instead of cdadringAndy Wingo1-71/+124
* module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/psyntax.scm: Use `match' more. NFC.
2024-11-15psyntax: Add simple pattern matcherAndy Wingo1-38/+40
* module/ice-9/psyntax.scm (simple-match1, simple-match-pat, simple-match-patv, match): Add simple pattern matcher. * module/ice-9/psyntax-pp.scm: Regenerate. Just different renumbering of temps.
2024-11-15psyntax: Inline the single use of define-structureAndy Wingo1-49/+48
* module/ice-9/psyntax.scm (define-structure): Remove, inline into use. No predicate needed. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14psyntax: Functional annotation of function namesAndy Wingo1-57/+51
* module/ice-9/psyntax.scm (maybe-name-value): Return a fresh lambda instead of mutating the given lambda. (define-expansion-accessors): No need to define setters.
2024-11-14psyntax: Clean up use of fx+, etcAndy Wingo1-67/+63
* module/ice-9/psyntax.scm (fx+, fx-, fx=): Remove. Replace uses with 1+, 1-, =. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14psyntax: Rename top-level-eval, local-evalAndy Wingo1-11/+11
* module/ice-9/psyntax.scm (top-level-eval, local-eval): Rename from top-level-eval-hook, local-eval-hook. Adapt callers. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14psyntax: Use vectors instead of gensyms for labels, marksAndy Wingo1-53/+59
* module/ice-9/psyntax.scm (gen-unique): Instead of making a string with an embedded hex counter, make a vector. A little less work than making a string, and slightly smaller binaries. (gen-label, gen-mark): Use gen-unique. (resolve-identifier): Adapt case that recognizes labels denoting lexicals to be less strict. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14psyntax: Remove useless gen-label invocationsAndy Wingo1-47/+45
* module/ice-9/psyntax.scm (expand-top-sequence): Remove needless gen-label uses, and replace one use with gen-lexical (which is what is needed). * module/ice-9/psyntax-pp.scm: Regenerate.
2024-11-14psyntax: Clean up lexical gensym creationAndy Wingo1-63/+61
* module/ice-9/psyntax.scm (gen-lexical): Add a nice comment. Rename from build-lexical-var, and remove unused src argument. (gen-var, generate-temporaries): Use gen-lexical. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-02-20Macro-introduced top-level vars scope to their module even if unboundAndy Wingo1-49/+43
* module/ice-9/psyntax.scm (analyze-variable): Previously, a reference to a top-level variable in a module other than the current module would be silently rewritten to reference the current module, if the variable was unbound in its original module. This was a hack from the early days of when we extended psyntax to know about the module system. Fix to properly use the scope of the introduced binding instead of the scope of the macro use site. * test-suite/tests/syntax.test ("macro-introduced cross-module unbound identifiers"): Add test. * module/ice-9/psyntax-pp.scm: Regenerate.
2024-02-20Regenerate psyntax-pp.scmAndy Wingo1-3376/+2864
* module/ice-9/psyntax-pp.scm (syntax?): Regenerate. With the modified pretty-printer, things are a bit different.
2022-03-07psyntax: Honor source properties for things other than syntax objects.Ludovic Courtès1-75/+80
Commit 54bbe0b2846c5b1aa366c91d679ba724869c8cda inadvertently led psyntax to dismiss source location info for data returned by read hash extensions, because read hash extensions return plain data with associated source properties, even when called from 'read-syntax'. This change reverts part of this commit to restore that behavior. Fixes <https://issues.guix.gnu.org/54003>. * module/ice-9/psyntax.scm (datum-sourcev): New procedure. (source-annotation): Fall back to 'datum-sourcev'. * module/ice-9/psyntax-pp.scm: Regenerate. * test-suite/tests/compiler.test ("psyntax")["syntax-source with read-hash-extend"]: New test.
2022-02-07psyntax: Pass source vectors to tree-il constructors.Ludovic Courtès1-83/+53
Avoiding systematic conversion from source vectors to property alists saves 20% on the final heap size of a process doing: (compile-file FILE #:optimization-level 1) where FILE is large. * module/language/tree-il.scm (tree-il-src/ensure-alist): New procedure with setter. Export as 'tree-il-src'. * module/ice-9/psyntax.scm (build-void, build-call) (build-conditional, build-lexical-reference, build-lexical-assignment) (build-global-reference, build-global-assignment) (build-global-definition, build-simple-lambda, build-case-lambda) (build-lambda-case, build-primcall, build-primref) (build-data, build-sequence, build-let, build-named-let) (build-letrec, expand-body): Remove (sourcev->alist src) calls. * module/ice-9/psyntax-pp.scm: Regenerate. * module/language/tree-il/analyze.scm (shadowed-toplevel-analysis): Use 'tree-il-src' instead of accessing the 'src' slot directly. * module/system/vm/assembler.scm (link-debug): Adjust so PC can be followed by a vector or an alist.
2022-02-01Avoid source properties in psyntaxAndy Wingo1-104/+121
* module/ice-9/psyntax.scm (source-annotation): Only return source properties from syntax objects. (source-wrap): Don't look for source properties. (expand-macro): Rebuild source properties on macro output via source-wrap, not source properties. Only annotate head of a chain of pairs. (strip): Here's the only use of set-source-properties!: when stripping a syntax object to a datum. (macroexpand): If the input expression is not a syntax object, eagerly extract its source properties. (datum->syntax): Fix case in which source is given as an alist. * module/ice-9/psyntax-pp.scm: Regenerate.
2022-01-13Avoid quadratic behavior in id-var-nameAndy Wingo1-54/+60
* module/ice-9/psyntax.scm (id-var-name): Avoid list-ref. * module/ice-9/psyntax-pp.scm: Regenerate.
2021-04-29Fix syntax-violation, which was passing vectors instead of alistsAndy Wingo1-1/+2
* module/ice-9/psyntax.scm (syntax-violation): Pass source as an alist. A sourcev would be better but it's incompatible. * module/ice-9/psyntax-pp.scm: Regenerate.
2021-03-03Read-in-scheme replaces boot "read" definitionAndy Wingo1-1/+1
Instead of defining a separate module, given that "read" calls are quite all over the place, we're just going to replace the boot "read" binding with read.scm. This way, we'll be able to remove support for reader options in the boot reader, as it will only ever be used for a finite set of files. * NEWS: Update. * module/Makefile.am (ice-9/boot-9.go): Depend on read.scm. (SOURCES): * am/bootstrap.am (SOURCES): Don't build a ice-9/read.go, as we include it. * module/ice-9/boot-9.scm (read-syntax): Define here, as "include" now uses it. (read-hash-procedures, read-hash-procedure, read-hash-extend): New procedures. Will replace C variants. (read, read-syntax): Include read.scm to define these. * module/ice-9/psyntax-pp.scm (include): Regenerate. * module/ice-9/psyntax.scm (include): Use read-syntax, so we get better source information. * module/ice-9/read.scm (let*-values): New local definition, to avoid loading srfi-11. (%read): Use list->typed-array instead of u8-list->bytevector. * module/language/scheme/spec.scm: Remove (ice-9 read) import; read-syntax is there in the boot environment
2021-02-25Psyntax uses sourcev internallyAndy Wingo1-101/+154
* module/ice-9/psyntax.scm: Use the vector representation of source properties internally. We have to convert to alists when going to Tree-IL, but this will be in harmony with syntax objects once the reader switches to vectors too. * module/ice-9/psyntax-pp.scm: Regenerate.
2021-02-25Ensure that (syntax ()) results in ()Andy Wingo1-34/+39
* module/ice-9/psyntax.scm: Add a special case for (). There are already special cases for pairs, vectors, etc; the issue is that with read-syntax, the () might be come into psyntax as an annotated syntax object, which here we would want to strip, to preserve the invariant to psyntax users that all lists are unwrapped.
2021-02-24Fix module scoping for datum->syntax with no identifierAndy Wingo1-85/+87
* module/ice-9/psyntax.scm: With the new behavior of datum->syntax which allows #f for the lexical context, we have the question of what module to attach to these newly created syntax objects. In that case we'll mark down #f as the module, indicating that we know nothing. We have to extend a number of other cases to default to the expander's idea of the current module, if a syntax object has no module scope. Also, change datum->syntax to attach the empty wrap, not the top wrap. Attaching the top wrap leads to multiply applying the top mark, as you recurse into subexpressions.
2021-02-24Remove top-marked? optimization from psyntaxAndy Wingo1-104/+95
* module/ice-9/psyntax.scm (strip): It used to be that terms in the source program could have a "top" mark, and when stripping marks we'd stop recursing when we see an expression with the top mark. This had the good effect that source programs could contain quoted syntax objects, or quoted objects with shared structure -- in theory anyway. In practice the compiler didn't support objects with shared structure. Anyway when we switch to "read-syntax", quoted expressions can contain syntax objects introduced by the reader, which naturally we would want to strip away in a (quote FOO) form. Therefore we remove the top-marked? optimization.
2021-02-24Add quote-syntaxAndy Wingo1-31/+39
* module/ice-9/psyntax.scm (quote-syntax): New core form. Usually the expander will unwrap all syntax objects from the input term. However sometimes you want to preserve a syntax object, as a datum. That's when you want quote-syntax. * module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/local-eval.scm (identifier-syntax-from-box): Use quote-syntax instead of our datum->syntax trick, which relied on psyntax's special treatment of the top mark.
2021-02-21Implement read-syntaxAndy Wingo1-4/+4
* doc/ref/api-macros.texi (Syntax Case): Update documentation for datum->syntax. * module/ice-9/psyntax.scm (datum->syntax): Use #:source keyword for source location info instead of an optional, and allow an alist. * module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/read.scm (%read, read): Refactor to allow read and read-syntax to share an implementation. (read-syntax): New function.
2021-02-21Document datum->syntax extensionsAndy Wingo1-54/+55
* doc/ref/api-macros.texi (Syntax Case): Document that template-id can be false, and document srcloc. * module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/psyntax.scm (syntax?): Allow the lexical context to be null. Allow srcloc to be a source properties alist. Inspired by Racket.
2021-02-21Adapt uses of make-syntax to preserve syntaxAndy Wingo1-55/+72
* module/ice-9/psyntax.scm (datum->syntax): Add an additional optional argument, to allow callers to provide source annotation information. * module/ice-9/psyntax-pp.scm: Regenerate.
2021-02-21psyntax preserves source via syntax objectsAndy Wingo1-69/+63
* module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/psyntax.scm (wrap, source-wrap): Preserve source via syntax objects.
2021-02-20Syntax objects have "source" fieldAndy Wingo1-3/+4
* libguile/syntax.c (scm_make_syntax): Add optional "source" argument. Note that this function is internal. (scm_syntax_source): New function, replacing definition in boot-9.scm. * libguile/syntax.h: Add new declarations. * module/ice-9/psyntax-pp.scm: * module/ice-9/psyntax.scm (source-annotation): For syntax objects, the source annotation comes direct from the syntax object. * module/system/vm/assembler.scm (link-data, intern-constant): Write 5-word syntax objects.
2020-03-07psyntax: Preserve source location information for top-level references.Ludovic Courtès1-42/+45
Fixes <https://bugs.gnu.org/38388>. * module/ice-9/psyntax.scm (expand-expr): In 'build-global-reference' call, pass S when (source-annotation (car e)) returns #f. * module/ice-9/psyntax-pp.scm: Regenerate.
2020-03-05psyntax: 'include' no longer rejects relative file names.Ludovic Courtès1-1/+1
Fixes a regression introduced in commit fd2ffc649c2d08639c2ac41c25e4ebdbeb4b151d whereby including a relative file name would result in: ice-9/psyntax.scm:3254:24: attempt to include relative file name but could not determine base dir * module/ice-9/psyntax.scm (call-with-include-port)[syntax-dirname]: Lookup 'filename (symbol), not filename (identifier). * module/ice-9/psyntax-pp.scm: Regenerate.
2020-01-12Support R7RS define-libraryAndy Wingo1-42/+39
* module/Makefile.am (ice-9/boot-9.go, NOCOMP_SOURCES): Add r7rs-libraries. * module/ice-9/boot-9.scm ("ice-9/r7rs-libraries"): Include file. * module/ice-9/psyntax.scm (call-with-include-port): New definition. (include): Use call-with-include-port. * module/ice-9/psyntax-pp.scm: Regenerate. * module/ice-9/r7rs-libraries.scm: New file. * module/scheme/base.scm (r7:include, r7:include-ci): Fix mistaken use of core "include". Use include-ci from core. (features): Remove features that are already part of core. * NEWS: Update.
2019-08-25Allow mixed local definitions and expressionsAndy Wingo1-168/+195
This change to the expander allows mixed local definitions and expressions. The expansion turns: (let () (a) (define (b) 42) (b) (b)) into: (let () (letrec* ((t0 (begin (a) (if #f #f))) (b (lambda () 42))) (b))) Which is to say, expressions that precede definitions are expanded as definitions of a temporary via (begin EXP (if #f #f)). * module/ice-9/psyntax.scm (expand-body): Allow mixed definitions and expressions. * module/ice-9/psyntax-pp.scm: Regenerate. * test-suite/tests/syntax.test: Add a couple tests and update for new error messages.
2019-08-18Add "mod" field to tree-il toplevel ref, set, defineAndy Wingo1-71/+82
Add "mod" field to <toplevel-ref>, <toplevel-set>, and <toplevel-define>, indicating the expander's idea of what the current module is when a toplevel variable is accessed or created. This will help in later optimizations. * libguile/expand.c (TOPLEVEL_REF, TOPLEVEL_SET, TOPLEVEL_DEFINE) (expand, expand_define, expand_set_x, convert_assignment): * libguile/expand.h (SCM_EXPANDED_TOPLEVEL_REF_FIELD_NAMES): (SCM_MAKE_EXPANDED_TOPLEVEL_REF, SCM_EXPANDED_TOPLEVEL_SET_FIELD_NAMES): (SCM_MAKE_EXPANDED_TOPLEVEL_SET, SCM_EXPANDED_TOPLEVEL_DEFINE_FIELD_NAMES): (SCM_MAKE_EXPANDED_TOPLEVEL_DEFINE): * module/ice-9/compile-psyntax.scm (translate-literal-syntax-objects): * module/ice-9/psyntax-pp.scm: * module/ice-9/psyntax.scm: * module/language/tree-il.scm: * module/language/tree-il.scm (parse-tree-il, make-tree-il-folder): (pre-post-order): * module/language/tree-il/analyze.scm (goops-toplevel-definition): (macro-use-before-definition-analysis, proc-ref?, format-analysis): * module/language/tree-il/compile-cps.scm (convert): * module/language/tree-il/debug.scm (verify-tree-il): * module/language/tree-il/effects.scm (make-effects-analyzer): * module/language/tree-il/fix-letrec.scm (free-variables): * module/language/tree-il/peval.scm (peval): * test-suite/tests/tree-il.test: Adapt uses.
2019-02-22Fix race when expanding syntax-parameterize and define-syntax-parameterAndy Wingo1-103/+103
* libguile/macros.c (scm_i_make_primitive_macro): Give primitive macros a primitive-macro macro-type. * module/ice-9/psyntax.scm (put-global-definition-hook) (get-global-definition-hook): Inline into uses. (make-binding): Change format of lexically defined or rebound syntax parameters to just be the transformer, not a list of the transformer. (resolve-identifier, expand-install-global, expand-body) (syntax-parameterize): Adapt to use the variable object (box) holding the top-level syntax parameter as the "key" for lookups into the lexical environment, instead of a fresh object associated with the syntax transformer. * module/ice-9/psyntax-pp.scm: Regenerate. Fixes #27476, a horrible race when one thread is expanding a syntax-parameterize form including uses, and another thread is expanding the corresponding define-syntax-parameter. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27476#102.
2018-01-22Use make-struct/simple in psyntaxAndy Wingo1-22/+18
* module/ice-9/psyntax.scm (define-expansion-constructors): Use make-struct/simple, so we can inline allocations. * module/ice-9/psyntax-pp.scm: Regenerate.
2017-09-22Merge stable-2.2 into masterAndy Wingo1-23/+33
This commit resolves conflicts by removing the deprecated make-struct.