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

4467 commits

Author SHA1 Message Date
Andy Wingo
d66c1c67a0 Include nfree in closure-ref, closure-set primcall params
* module/language/cps/closure-conversion.scm (convert-one): Add nfree to
the param.  This will help the wasm target.
* module/language/cps/effects-analysis.scm (closure-ref, closure-set!):
* module/language/cps/lower-primcalls.scm (closure-ref,closure-set!):
Adapt.
2023-07-04 11:01:50 +02:00
Andy Wingo
018c5b9ad9 Add wasm32 and wasm64 CPU types
* module/system/base/target.scm (cpu-endianness): wasm targets are
little-endian.
2023-06-22 20:11:29 +02:00
Andy Wingo
d2784ea1af Include optimizations when targetting hoot runtime
* module/language/cps/optimize.scm (optimize-hoot-backend-cps): There
are a couple optimizations we need to clean up after tailification, so
include those here.
2023-06-22 20:07:17 +02:00
Andy Wingo
23d4263c1a Add unify-returns pass for hoot targets; wire up hoot backend
* module/language/cps/optimize.scm (target-runtime): New function.
(make-backend-cps-lowerer): For hoot, choose different backend passes.
* module/language/cps/unify-returns.scm: New file.
2023-06-22 16:28:28 +02:00
Andy Wingo
311c69e6fc Add tailify pass
* am/bootstrap.am (SOURCES): Add tailify.scm.
* module/language/cps/tailify.scm: New file.
2023-06-22 16:21:22 +02:00
Andy Wingo
171072ec5a Add new $calli expression type.
* module/language/cps.scm ($calli): New expression type, calls a label
as a value.  Adapt all callers.
2023-06-22 16:21:22 +02:00
Andy Wingo
a1eb526b0c Add indirect-tail-call VM instruction
* libguile/vm-engine.c (indirect_tail_call): New instruction.
* libguile/jit.c (compile_indirect_tail_call):
(compile_indirect_tail_call_slow): Add JIT support.
* module/system/vm/assembler.scm (system):
* module/system/vm/disassembler.scm (instruction-has-fallthrough?):
(stack-effect-parsers): Add assembler support.
2023-06-22 16:21:22 +02:00
Andy Wingo
896960dade Add representations for new primcalls
* module/language/cps/utils.scm (compute-var-representations): Add
representations for vector-length and so on.
2023-06-22 16:19:15 +02:00
Andy Wingo
85f85a0fc0 Tree-IL-to-CPS lowers to high-level object reprs: vectors
* module/language/tree-il/compile-cps.scm: Lower to allocate-vector,
vector-ref/immediate, and so on.
2023-06-22 16:01:44 +02:00
Andy Wingo
069ed42f50 Tree-IL-to-CPS lowers to high-level object reprs: strings
* module/language/tree-il/compile-cps.scm: Lower to string-length,
string-ref, et al.
2023-06-22 16:01:44 +02:00
Andy Wingo
d0677a362d Tree-IL-to-CPS lowers to high-level object reprs: bytevectors
* module/language/tree-il/compile-cps.scm: Lower to bv-length,
bv-contents.
2023-06-22 16:01:44 +02:00
Andy Wingo
e6bd13ea1e Tree-IL-to-CPS lowers to high-level object reprs: structs
* module/language/tree-il/compile-cps.scm: Lower to allocate-struct,
struct-ref, and so on.
2023-06-22 16:01:44 +02:00
Andy Wingo
4fb4bebe41 Tree-IL-to-CPS lowers to high-level object reprs: pairs
* module/language/tree-il/compile-cps.scm: Lower to cons, car, set-car!,
etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
5c5af6bc78 Tree-IL-to-CPS lowers to high-level object reprs: atomic boxes
* module/language/tree-il/compile-cps.scm: Lower to make-atomic-box,
atomic-box-ref, and so on.
2023-06-22 16:01:44 +02:00
Andy Wingo
2b88333426 Tree-IL-to-CPS lowers to high-level object representations: boxes
* module/language/tree-il/compile-cps.scm: Lower to box, box-ref, and
box-set!.
2023-06-22 16:01:44 +02:00
Andy Wingo
e4f9b203f7 Closure conversion produces high-level object representations
* module/language/cps/closure-conversion.scm (convert-one): Build
closures with make-closure, cons, and so on; leave lowering to scm-ref
to the backend.
2023-06-22 16:01:44 +02:00
Andy Wingo
a80a5ade78 Contification uses 'cons primcall
* module/language/cps/contification.scm (apply-contification): Reify
'cons instead of using the lower-level scm-set! etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
26b43f35c5 DCE ignores setters to dead objects
* module/language/cps/dce.scm (compute-live-code): Add the new
higher-level object mutators.
2023-06-22 16:01:44 +02:00
Andy Wingo
125cb9fa6d Remove useless code in CSE
* module/language/cps/cse.scm (eliminate-common-subexpressions-in-fun):
Defs must be a list.
2023-06-22 16:01:44 +02:00
Andy Wingo
2534326e5e Add CSE auxiliary definitions for cons, set-car! etc
* module/language/cps/cse.scm (eliminate-common-subexpressions-in-fun):
Add cons, set-car!, etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
e7e625b773 Fix effects analysis bug for synthesized definitions at allocations
* module/language/cps/effects-analysis.scm (compute-known-allocations):
For a primcall that allocates, sometimes we will synthesize auxiliary
definitions as part of CSE, for example to indicate that if (cons x y)
is bound to z, that a later call to (car z) should give x unless there
might be an intervening set-car!.  We had a bug in which aux definitions
attached to allocations were being incorrectly associated with the first
operand.  Probably this is a bug in other contexts but it really starts
to hit with the high-level constructors, e.g. `box`.
2023-06-22 16:01:44 +02:00
Andy Wingo
98178ac308 Add effects analysis for new high-level object accessors
* module/language/cps/effects-analysis.scm: Add car, box-ref, etc to
effects analysis.
2023-06-22 16:01:44 +02:00
Andy Wingo
a35cae5697 Add support for higher-level object representations in type analysis
* module/language/cps/types.scm: Add inferrers for vector-ref, car,
etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
eb6d5abcbe Move f64->scm lowering to lower-primcalls
* module/language/cps/lower-primcalls.scm (f64->scm): Move here...
* module/language/cps/reify-primitives.scm (reify-primitives): from
here.  Seems a more fitting place.
2023-06-22 16:01:44 +02:00
Andy Wingo
a5b245d2d0 Wire in lower-primitives pass
* module/language/cps/optimize.scm (lower-cps/generic): Rename from
lower-cps; these are the lowerings that apply to everyone.
(select-opts-for-optimization-level): Factor out of make-cps-lowerer.
(make-backend-cps-lowerer): New procedure.  For the Guile VM backend, we
have a few mandatory passes, including the new lower-primitives.
(make-cps-lowerer): Apply backend-specific lowering pass.
2023-06-22 16:01:44 +02:00
Andy Wingo
b974405bce New CPS pass: lower-primcalls
This pass will implement the specialized lowering of object accessors to
Guile's VM primitives.

* am/bootstrap.am (SOURCES): Add new file.
* module/language/cps/lower-primcalls.scm: New file.
2023-06-22 16:01:44 +02:00
Andy Wingo
19c3bdc5ca Fix target-max-size-t/scm to not be a fraction (oops)
* module/system/base/target.scm (target-max-size-t/scm): Use floor/
instead of /.
2023-06-22 16:01:44 +02:00
Andy Wingo
aa2cfe7cf6 Consider $code to make 'ptr representation
* module/language/cps/utils.scm (compute-var-representations): For the
wasm target, these values are (ref $kvarargs), not i64.  Will need to
distinguish from bytevector pointers at some point, though.
2023-06-19 13:53:46 +02:00
Andy Wingo
db826ab909 Fix bug in compilation of rsh/lsh
* module/language/cps/compile-bytecode.scm (compile-function):
The rsh/lsh patterns would never match.  I think these would end up
dispatching through emit-text though.
2023-06-19 13:53:01 +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
Andy Wingo
b0a390db06 Excise use of record-case
This macro expands to field accessors, which in the case of tree-il-src
will force an eager conversion of the source info to alists.
2023-06-19 13:53:01 +02:00
Andy Wingo
02dfb6e776 Fix exn dispatch for exns within pre-unwind handlers
* libguile/exceptions.c (exception_epoch_fluid): Rename from
active_exception_handlers_fluid.
(scm_dynwind_throw_handler): Increment exception epoch instead of
resetting active exception handlers.
(scm_init_exceptions): Update.
* module/ice-9/boot-9.scm  (with-exception-handler): Rework to associate
an "epoch" fluid with each exception handler.
(with-throw-handler): Establish a new epoch, during the execution of a
throw handler.
(raise-exception): Rework to avoid capturing a list of exception
handlers, and to use epochs as a way to know which handlers have already
been examined and which are on the dispatch stack.
* test-suite/tests/exceptions.test ("throwing within exception
handlers"): New test.
2023-06-08 10:26:16 +02:00
Andy Wingo
ee18ca9a35 Deprecate (ice-9 lineio)
* module/ice-9/lineio.scm: Deprecate.
2023-06-08 10:21:28 +02:00
Andy Wingo
5af66570bb Fix allow-newline? in call-with-truncating-output-string
* module/ice-9/pretty-print.scm (call-with-truncating-output-string):
Actually detect newlines.
2023-06-08 10:21:28 +02:00
Andy Wingo
0e4334406a truncated-print: use call-with-truncating-output-string
* module/ice-9/pretty-print.scm (truncated-print): Use new
call-with-truncating-output-string, to allow for early bailout when
printing large records.
2023-06-08 10:21:28 +02:00
Andy Wingo
379a9a64c6 Inline generic-write into pretty-print
* module/ice-9/pretty-print.scm (pretty-print): Inline generic-write
into its only caller.
2023-06-08 10:21:28 +02:00
Andy Wingo
75f96e825c pretty-print: width arg is never false
* module/ice-9/pretty-print.scm (generic-write): width is never false.
2023-06-08 10:21:28 +02:00
Andy Wingo
29a9f26a36 Rewrite pretty-print to rely on port-column, abort early
* module/ice-9/pretty-print.scm (call-with-truncating-output-string):
New function.
* module/ice-9/pretty-print.scm (generic-write): Rewrite so that instead
of keeping track of the column, we just use port-column on the port.
Also, when checking if a possibly-improper list can print on one line,
use new call-with-truncating-output-string so as to always abort early,
even for long bytevectors.
2023-06-08 10:21:28 +02:00
Andy Wingo
f320ce8979 Modernize soft ports
* doc/ref/api-io.texi (Soft Ports): Update docs.
* module/ice-9/boot-9.scm (make-soft-port): Don't eagerly load soft
ports.
* module/ice-9/soft-ports.scm (deprecated-make-soft-port): Rename from
make-soft-port.
(make-soft-port): New interface.
2023-06-08 10:21:28 +02:00
Andy Wingo
075599e5b0 Implement R6RS custom textual ports
* module/ice-9/textual-ports.scm (custom-textual-port-read+flush-input):
(custom-textual-port-write):
(custom-textual-port-seek):
(custom-textual-port-close):
(custom-textual-port-random-access?):
(make-custom-textual-input-port):
(make-custom-textual-output-port):
(make-custom-textual-input/output-port): New procedures.
* doc/ref/api-io.texi (Ports): Update docs.
* doc/ref/r6rs.texi (rnrs io ports): Mention custom textual port
interfaces.
* module/rnrs/io/ports.scm: Re-export custom textual port interfaces
from (ice-9 textual-ports).
* test-suite/tests/r6rs-ports.test: Add minimal tests for textual ports.
2023-06-08 10:21:02 +02:00
Andy Wingo
5bdc663af9 Rewrite soft ports in Scheme
This also makes soft ports suspendable.

* am/bootstrap.am (SOURCES): Add (ice-9 soft-ports).
* libguile/init.c (scm_i_init_guile): No need to init vports.
* libguile/vports.c: Call out to (ice-9 soft-ports).
* libguile/vports.h: Remove internal scm_init_vports.
* module/ice-9/boot-9.scm (the-scm-module): Import (ice-9 soft-ports).
Really this enlarges the boot closure a bit, so we should probably
refactor.
* module/ice-9/soft-ports.scm: New file.
2023-06-08 09:03:10 +02:00
Andy Wingo
bf4e8f911e Use custom binary output ports for make-chunked-output-port
* module/web/http.scm (make-chunked-output-port): Use custom binary
output ports.
2023-06-08 09:03:10 +02:00
Andy Wingo
0e305e6bfd Rewrite custom binary ports in Scheme, in terms of custom ports
* libguile/r6rs-ports.c: Call out to Scheme instead of defining here.
* libguile/r6rs-ports.h: Put custom binary port decls together, to
deprecate later.
* module/ice-9/binary-ports.scm: Re-implement custom binary ports in
terms of custom ports.
2023-06-08 09:03:10 +02:00
Andy Wingo
1852fbfef9 Add "custom ports"
Custom ports are a kind of port that exposes the C port type interface
directly to Scheme.  In this way the full capability of C is available
to Scheme, and also the read and write functions can be tail-called from
Scheme (via port-read / port-write).

* libguile/custom-ports.c:
* libguile/custom-ports.h:
* module/ice-9/custom-ports.scm: New files.
* libguile/init.c:
* libguile/Makefile.am:
* am/bootstrap.am: Add to the build.
* doc/ref/api-io.texi: Update the manual.
2023-06-08 09:03:10 +02:00
Andy Wingo
03344ce431 pretty-print: inline some handling of read macros
* module/ice-9/pretty-print.scm (generic-write): Not really sure why
read macros are duplicated, but this is a refactor to use more match and
less cadr.
2023-06-08 08:32:25 +02:00
Andy Wingo
ec3bf4e2ba pretty-print: inline genwrite:newline-str
* module/ice-9/pretty-print.scm (genwrite:newline-str): Remove.
(generic-write): Just use "\n".
2023-06-08 08:32:25 +02:00
Andy Wingo
f74565defd pretty-print: Use string-concatenate-reverse
* module/ice-9/pretty-print.scm (generic-write): Use
string-concatenate-reverse instead of locally-defined
reverse-string-append.
(reverse-string-append): Remove.
2023-06-08 08:32:25 +02:00
Christopher Baines
cba2e7e3fe
Fix some invalid unicode handling issues with suspendable ports.
Fixes <https://bugs.gnu.org/62290>.

Based on the implementation in ports.c.  I don't understand what this
code is really doing, but the suspendable ports implementation differs
from the similar C code for a couple of inequalities.

* module/ice-9/suspendable-ports.scm (decode-utf8, bad-utf8-len): Flip a
couple of inequalities.
* test-suite/tests/ports.test ("string ports"): Add additional invalid
UTF-8 test case.
* NEWS: Update.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2023-03-20 23:23:29 +01:00
Daniel Llorens
f0df1ed0fd Fix no-clause case-lambda in peval
This is checked by optargs.test, which 3b47f87618
broke.

* module/language/tree-il/peval.scm (peval): Account for no clause (= no body)
  case-lambda.
2023-03-17 21:17:10 +01:00
Daniel Llorens
3b47f87618 peval reduces some inlined case-lambda calls
* module/language/tree-il/peval.scm (peval): Reduce multiple case lambda
  in <call> trees according to the number of arguments. Do not try to
  reduce case-lambda using keyword arguments.
* test-suite/tests/peval.test: Tests.
2023-02-27 11:53:48 +01:00