1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

41 commits

Author SHA1 Message Date
Andy Wingo
60d852248f <lambda-case> must have list of optargs
Before, the optional args in a lambda-case could be #f or a list of
symbols.  However the list of symbols is entirely sufficient; no
optional args means a null list.  Change everywhere that produces
lambda-case, matches on lambda-case, and reads deserialized lambda-case.
2024-08-29 09:53:37 +02:00
Morgan Smith
f27e8b855f
Fix typos throughout codebase.
* NEWS:
* doc/ref/api-control.texi:
* doc/ref/api-data.texi:
* doc/ref/api-debug.texi:
* doc/ref/api-deprecated.texi:
* doc/ref/api-evaluation.texi:
* doc/ref/api-foreign.texi:
* doc/ref/api-i18n.texi:
* doc/ref/api-io.texi:
* doc/ref/api-languages.texi:
* doc/ref/api-macros.texi:
* doc/ref/api-memory.texi:
* doc/ref/api-modules.texi:
* doc/ref/api-options.texi:
* doc/ref/api-peg.texi:
* doc/ref/api-procedures.texi:
* doc/ref/api-scheduling.texi:
* doc/ref/api-undocumented.texi:
* doc/ref/api-utility.texi:
* doc/ref/expect.texi:
* doc/ref/goops.texi:
* doc/ref/misc-modules.texi:
* doc/ref/posix.texi:
* doc/ref/repl-modules.texi:
* doc/ref/scheme-ideas.texi:
* doc/ref/scheme-scripts.texi:
* doc/ref/srfi-modules.texi:
* gc-benchmarks/larceny/dynamic.sch:
* gc-benchmarks/larceny/twobit-input-long.sch:
* gc-benchmarks/larceny/twobit.sch:
* libguile/gc.h:
* libguile/ioext.c:
* libguile/list.c:
* libguile/options.c:
* libguile/posix.c:
* libguile/threads.c:
* module/ice-9/boot-9.scm:
* module/ice-9/optargs.scm:
* module/ice-9/ports.scm:
* module/ice-9/pretty-print.scm:
* module/ice-9/psyntax.scm:
* module/language/elisp/parser.scm:
* module/language/tree-il/compile-bytecode.scm:
* module/srfi/srfi-37.scm:
* module/srfi/srfi-43.scm:
* module/statprof.scm:
* module/texinfo/reflection.scm:
* test-suite/tests/eval.test:
* test-suite/tests/fluids.test:
Fix typos.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-05-06 11:51:53 +02:00
Andy Wingo
711077586b peval avoids introducing 'throw
* module/language/tree-il/peval.scm (peval): Introduce raise-type-error
for dynwind unwinder thunk check.
* module/language/tree-il/compile-cps.scm (raise-type-error):
* module/language/tree-il/compile-bytecode.scm (canonicalize): Handle
raise-type-error, as it can be in Tree-IL now.
2023-11-23 12:11:22 +01:00
Andy Wingo
d08cc4f6e2 Allow string->utf8 to constant-fold
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*primitive-accessors*): Add string->utf8, utf8->string, and
string-utf8-length.
(primitive-module): New public function, moved here from (language
tree-il compile-bytecode).

* module/language/tree-il/compile-bytecode.scm: Use primitive-module
from (language tree-il primitives).

* module/language/tree-il/peval.scm (peval): A bugfix: load primitives
from their proper module.  Allows bytevector primitives to fold.

* module/language/cps/guile-vm/reify-primitives.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm
* module/language/tree-il/primitives.scm:
* module/language/tree-il/cps-primitives.scm:
* module/language/tree-il/effects.scm (make-effects-analyzer):
Add string->utf8, utf8->string, and string-utf8-length.

* module/language/tree-il/compile-cps.scm (string->utf8)
(string-utf8-length, utf8->string): New custom lowerers, including type
checks and an unboxed result for string-utf8-length.

* module/system/vm/assembler.scm:
* libguile/intrinsics.h:
* libguile/intrinsics.c: Because string-utf8-length returns an unboxed
value, we need an intrinsic for it; go ahead and add an intrinsic for
string->utf8 and utf8->string too, as we will likely be able to use
these in the future.
2023-11-15 10:44:21 +01:00
Andy Wingo
6756aeff95 Better compilation for symbol->string
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add symbol->string
intrinsic.
* module/language/cps/guile-vm/reify-primitives.scm (compute-known-primitives):
* module/language/tree-il/compile-bytecode.scm (+):
* module/language/tree-il/compile-cps.scm (symbol->string):
* module/language/tree-il/cps-primitives.scm (symbol->string):
* module/language/cps/effects-analysis.scm (symbol->string):
* module/language/cps/types.scm (symbol->keyword):
* module/system/vm/assembler.scm (symbol->string): Add the necessary
code to compile symbol->string.
2023-09-15 10:18:50 +02:00
Andy Wingo
1f70d597db Allow functions to mark themselves as maybe-unused
* module/language/tree-il/analyze.scm (<reference-graph>): Oh my
goodness, constructor args were reversed relative to field order.
Constructor use was consistent but it was terribly confusing; fixed and
updated uses.
(unused-toplevel-analysis): Add ability for functions to mark themselves
as "maybe-unused"; such functions won't cause unused toplevel warnings.

* module/language/tree-il/compile-bytecode.scm (sanitize-meta):
(compile-closure):
* module/language/tree-il/compile-cps.scm (sanitize-meta): Prevent
maybe-unused from being needlessly written out to the binary.
2023-08-24 11:43:15 +02:00
Andy Wingo
2cd8b4160c Use tree-il-srcv instead of tree-il-src
This prevents eager conversion to alists.
2023-06-19 13:53:01 +02:00
Ludovic Courtès
e2797f529b Baseline compiler no longer crashes on (not (list 1 2)).
Fixes <https://bugs.gnu.org/58217>.

* module/language/tree-il/compile-bytecode.scm (canonicalize)
[finish-conditional](predicate?): Do not assume 'lookup-primitive'
returns true.
* test-suite/tests/compiler.test ("regression tests")
["(not (list 1 2))"]: New test.
2022-10-01 16:00:05 +02:00
Ludovic Courtès
74abae04aa Baseline compiler no longer swaps rsh/lsh when transforming ash calls.
Reported by Marius Bakke <marius@gnu.org>
at <https://issues.guix.gnu.org/50696>.

Previously, the baseline compiler would incorrectly emit a right shift
when for, say, (ash x 2), and a left shift for (ash x -2).

* module/language/tree-il/compile-bytecode.scm (canonicalize): When Y is
negative, emit 'rsh', not 'lsh'.
* test-suite/tests/numbers.test ("ash at -O1"): New test.
2021-09-20 23:27:39 +02:00
Ludovic Courtès
330c6ea83f Fix 'ash' primcall match clause in baseline compiler.
Previously the pattern would only match when the two 'src' values were
the same, which is not the case for example when running on the
interpreter.

* module/language/tree-il/compile-bytecode.scm (canonicalize): In 'ash
primcall pattern, rename second 'src' to 'src*'.
2021-09-20 23:24:24 +02:00
Andy Wingo
83023160b1 Simplify module variable lookup slow-path
* libguile/intrinsics.h:
* libguile/intrinsics.c (lookup_bound_public, lookup_bound_private): Two
new intrinsics.
(scm_bootstrap_intrinsics): Wire them up.
* libguile/jit.c (compile_call_scm_from_scmn_scmn):
(compile_call_scm_from_scmn_scmn_slow):
(COMPILE_X8_S24__N32__N32__C32): Add JIT support for new instruction
kind.
* libguile/vm-engine.c (call-scm<-scmn-scmn): New instruction, takes
arguments as non-immediate offsets, to avoid needless loads and register
pressure.
* module/language/cps/effects-analysis.scm: Add cases for new
primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add new
primcalls.
* module/language/cps/reify-primitives.scm (cached-module-box): If the
variable is bound, call lookup-bound-public / lookup-bound-private as
appropriate instead of separately resolving the module, name, and doing
the bound check.
* module/language/tree-il/compile-bytecode.scm (emit-cached-module-box):
Use new instructions.
* module/system/vm/assembler.scm (define-scm<-scmn-scmn-intrinsic):
(lookup-bound-public, lookup-bound-private): Add assembler support.
2021-04-26 09:48:52 +02:00
Andy Wingo
d238566d0e CPS compiler reduces eq? on constant to eq-constant?
* module/language/cps/compile-bytecode.scm (compile-function): Expect
  eq-constant? instead of eq-null?, etc.
* module/language/cps/effects-analysis.scm: Likewise.
* module/language/cps/reify-primitives.scm (reify-primitives): For
  eq-constant?, reify a $const unless the constant is an immediate whose
  encoding fits in 16 bits.
* module/language/cps/type-fold.scm (materialize-constant): Helper to
  make a constant from a type, min, and max.
  (fold-eq-constant?): New helper.
  (eq-constant?): New folder.
  (undefined?): Define specifically.
  (define-nullish-predicate-folder): Renamd from
  define-special-immediate-predicate-folder.  Use only for null?, false,
  and nil?.
  (*branch-reducers*): New mechanism.  Reduce eq? to eq-constant? if
  possible.
  (local-type-fold): Refactor to use materialize-constant, and to allow
  reducing branches.
* module/language/cps/types.scm (constant-type): Return three values
  instead of a type entry.
  (constant-type-entry): New function that returns a type entry.  Adapt
  callers.
  (infer-constant-comparison): New helper.
  (eq-constant?): New inferrer.
  (undefined?): New inferrer.
* module/language/tree-il/compile-bytecode.scm (eq-constant?): Fix
  truncate-bits signed arg.
  (define-immediate-type-predicate): Adapt to visit-immediate-tags
  change.
* module/language/tree-il/compile-cps.scm (convert): Convert eq? to
  constant to eq-constant?.  Advantaged is that it gets fixnums and
  chars in addition to special immediates.
* module/language/tree-il/cps-primitives.scm (define-immediate-type-predicate):
  Adapt to allow #f as pred.
* module/system/base/types/internal.scm (immediate-tags): Use #f as pred
  for false, nil, etc.
  (immediate-bits->scm): Adapt.
* module/system/vm/assembler.scm (emit-eq-null?, emit-eq-nil?)
  (emit-eq-false?, emit-eq-true?, emit-unspecified?, emit-eof-object?):
  Remove specialized emitters.
* module/system/vm/assembler.scm (define-immediate-tag=?-macro-assembler):
  Allow for pred to be #f.
* module/system/vm/disassembler.scm (define-immediate-tag-annotation):
  Adapt to pred being #f.
2020-08-03 22:19:18 +02:00
Andy Wingo
1ee99d97db Baseline compiler emits eq-immediate? as appropriate
* module/language/tree-il/compile-bytecode.scm (eq?): Define
  eq-immediate? as immediate emitter.
  (canonicalize): Don't fuss so much about eq?; only if commutation is
  needed.  (Perhaps a more generic commutation pass is needed.)
  (compile-closure): Add support for emit/immediate for branches.
2020-08-03 22:19:18 +02:00
Andy Wingo
f13b27a4cc Improve code generation for eq? on immediates
* module/language/tree-il/compile-bytecode.scm (canonicalize):
* module/language/tree-il/compile-cps.scm (canonicalize): Specialize
  eq-false? and similar predicates.
2020-07-30 16:30:23 +02:00
Andy Wingo
498428fbef Add with-lexicals helper; fix bug in (equal? #t (foo) #t)
* module/language/tree-il.scm (with-lexicals): New public helper.
* .dir-locals.el (with-lexicals): Add indentation rule.
* module/language/tree-il/compile-bytecode.scm (canonicalize): Use
  with-lexicals.
* module/language/tree-il/compile-cps.scm (canonicalize): Use
  with-lexicals from tree-il.
* module/language/tree-il/primitives.scm (chained-comparison-expander):
  Remove duplicate expander definitions for <, <=, and so on.
* module/language/tree-il/primitives.scm (maybe-simplify-to-eq): Avoid
  inadvertent code duplication by using with-lexicals.
  (expand-chained-comparisons): Likewise.
  (call-with-prompt): Simplify to use with-lexicals.
2020-05-13 14:51:56 +02:00
Andy Wingo
32eef3dd14 Slight optimization to baseline compiler
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  for-value-at and for-values-at take indexes instead of environments to
  denote destination.
2020-05-13 09:04:16 +02:00
Andy Wingo
44ad8fbde5 Baseline FIXME's are done :)
* module/language/tree-il/compile-bytecode.scm: Remove FIXME comments.
2020-05-11 22:03:08 +02:00
Andy Wingo
b02a889659 Baseline compiler emits source locations
* module/language/tree-il/compile-bytecode.scm (compile-closure): Emit
  source annotations where we have them.
2020-05-11 16:53:23 +02:00
Andy Wingo
f66111a203 Baseline O(1) access to frame-base env
* module/language/tree-il/compile-bytecode.scm (compile-closure): No
  need to search for frame-base.
2020-05-11 16:43:08 +02:00
Andy Wingo
b35fd53664 Emit handle-interrupts in baseline compiler
* module/language/tree-il/compile-bytecode.scm (compile-closure): Handle
  interrupts before calls, returns, and tail calls.
2020-05-11 16:15:24 +02:00
Andy Wingo
7f4bbc3dba Improve tail recursion in compiler
* module/language/tree-il/compile-bytecode.scm (compile-closure): Make
  it so that for-tail is actually tail-recursive.  Likewise improve tail
  recursion for the other helpers.
2020-05-11 14:48:45 +02:00
Andy Wingo
73a23027f5 Fix module capture for closures in <fix>
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  Capture closures for <fix> if needed.
2020-05-11 14:36:00 +02:00
Andy Wingo
4c3c35c536 Fix "cons" compilation in baseline compiler in some cases
* module/language/tree-il/compile-bytecode.scm (emit-cons): Fix for case
  where car is dst but cdr isn't.
2020-05-11 13:32:39 +02:00
Andy Wingo
3b6023d66d Baseline compiler: add pop-fluid primitive.
* module/language/tree-il/compile-bytecode.scm (pop-fluid): New
  primitive.
2020-05-11 13:32:19 +02:00
Andy Wingo
527262fef0 Fix baseline compilation error for make-struct/simple
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  $allocate-struct takes an SCM.
2020-05-11 13:31:40 +02:00
Andy Wingo
c0a27de50d Fix baseline miscompilation of <
* module/language/tree-il/compile-bytecode.scm: Fix < miscompilation.
2020-05-11 13:18:50 +02:00
Andy Wingo
73ac53af73 Fix free var computation in baseline compiler for lexical set!
* module/language/tree-il/compile-bytecode.scm (split-closures): Adjoin
  lexical being set to free vars.
2020-05-11 11:39:53 +02:00
Andy Wingo
2e6f2feefc Fix baseline canonicalization of reifying prompts
* module/language/tree-il/compile-bytecode.scm (canonicalize): Fix arg
  order to make-prompt.
2020-05-11 11:05:06 +02:00
Andy Wingo
f9c9e71046 Fix compilation of prompt in tail context
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  Compile body of prompt in values-at context at the frame base, not the
  current env.
2020-05-11 10:57:29 +02:00
Andy Wingo
b99a63447b Fix kw initializer bug in baseline compiler
* module/language/tree-il/compile-bytecode.scm (compile-closure): The
  first sym has index 1, not 0, because of the closure.
2020-05-11 10:45:29 +02:00
Andy Wingo
dd4dc1f6c4 Use lookup, lookup-bound in baseline compiler
* module/language/tree-il/compile-bytecode.scm (emit-box-set!): Fix to
  reference by SCM, not word.
  (emit-box-ref): New helper.
  (emit-cached-module-box, emit-cached-toplevel-box, emit-toplevel-box):
  Add bound? arg.  Before these could produce #f instead of a variable,
  and unbound variable errors weren't any good as they didn't have the
  variable name.
  (compile-closure): Use more box-ref and box-set!.  Pass bound? arg to
  the helpers.
2020-05-11 10:34:25 +02:00
Andy Wingo
d6b6392cfb Rename "lookup" intrinsic to "module-variable"
It can return #f, unlike scm_(module_)?lookup.

* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (module_variable, scm_bootstrap_intrinsics):
  Rename.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (current-module):
* module/language/cps/reify-primitives.scm (reify-lookup)
  (compute-known-primitives):
* module/language/tree-il/compile-bytecode.scm (emit-cached-module-box)
  (emit-cached-toplevel-box, emit-toplevel-box):
* module/language/tree-il/compile-cps.scm (toplevel-box):
* module/system/vm/assembler.scm (module-variable): Adapt users.
2020-05-11 09:46:40 +02:00
Andy Wingo
04e3cece45 Fix baseline compiler bugs
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix
  FP-relative computation for "receive" target.  Fix value-at syntax in
  conditional.
2020-05-09 22:23:00 +02:00
Andy Wingo
4311dc9858 Define new "lowering" phase in compiler
* module/language/cps/compile-bytecode.scm (compile-bytecode):
* module/language/tree-il/compile-bytecode.scm (compile-bytecode):
* module/language/tree-il/compile-cps.scm (compile-cps): Rely on
  compiler to lower incoming term already.
* module/language/tree-il/optimize.scm (make-lowerer): New procedure.
* module/system/base/compile.scm (compute-lowerer): New procedure,
  replaceing add-default-optimizations.
  (compute-compiler): Lower before running compiler.
* module/system/base/language.scm (<language>): Change
  optimizations-for-level field to "lowerer".
* module/scripts/compile.scm (%options, compile): Parse -O0, -O1 and so
  on to #:optimization-level instead of expanding to all the
  optimization flags.
* module/language/cps/optimize.scm (lower-cps): Move here from
  compile-bytecode.scm.
  (make-cps-lowerer): New function.
* module/language/cps/spec.scm (cps): Declare lowerer.
2020-05-08 17:07:56 +02:00
Andy Wingo
116f94d661 Add language-specific analysis pass to compiler infrastructure
* module/system/base/compile.scm (compute-analyzer): Compute analyzer to
  run on expressions before the compiler runs.
  (add-default-optimizations): Flesh out; still a stub.a
  (read-and-compile, compile, compile-and-load, compile-file): Default
  warning and optimization levels.
  (default-warning-level): New parameter, defaulting to 1.
  (default-optimization-level): New parameter, defaulting to 2.
  Currently unused.
* module/system/base/language.scm (<language>): Add
  optimizations-for-level and analyzer fields.
* module/language/tree-il/compile-bytecode.scm (compile-bytecode):
* module/language/tree-il/compile-cps.scm (optimize-tree-il): No need to
  run warnings passes here; compilers infrastructure will run them.
* module/language/tree-il/spec.scm (tree-il): Define make-analyzer as
  analyzer.
* module/language/tree-il/analyze.scm (make-analyzer): New exported
  procedure.
  (%warning-passes): New private variable.
* .dir-locals.el: Add with-test-prefix/c&e indent mode.
* test-suite/tests/cross-compilation.test:
* test-suite/tests/optargs.test:
* test-suite/tests/tree-il.test: Adjust to disable default warnings.
2020-05-08 15:39:41 +02:00
Andy Wingo
728de16911 Fix prompt compilation
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix
  emit-prompt invocation.
2020-05-04 22:56:23 +02:00
Andy Wingo
7a1b7bc485 Fix baseline compilation of let-values and prompt
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix
  fold invocation for visit-values-handler.
2020-05-04 22:37:49 +02:00
Andy Wingo
cfdaf35d73 Fix baseline compilation of conditionals
* module/language/tree-il/compile-bytecode.scm (canonicalize): Don't add
  an extra false? around predicates.
  (compile-closure): Fix predicate comparison instructions.
2020-05-04 22:28:34 +02:00
Andy Wingo
6b2d56ce15 Avoid shuffle-down for tail calls
* module/language/tree-il/compile-bytecode.scm (compile-closure): We can
  emit the precise move sequence and just do a reset-frame once, so go
  ahead and do that.
2020-05-04 21:58:10 +02:00
Andy Wingo
f0a9e537a0 Debugging names in baseline compiler; emit/immediate? fixes
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  Provide names for locals, including the closure.  Fix emission of
  primitives with immediate args.
2020-05-04 16:20:06 +02:00
Andy Wingo
121ab14439 Add baseline compiler
* module/language/tree-il/compile-bytecode.scm: New file.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Add new file.
2020-05-04 15:23:04 +02:00