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

17420 commits

Author SHA1 Message Date
Andy Wingo
e676e48047 Adapt stime.c to gnulib updates
* libguile/stime.c: Rely on gnulib to provide time.h and strptime.
  (timet): Remove this internal define; replaced with time_t.
  (scm_from_struct_tm): Rename from filltime.  Take the zone to set as
  an SCM.
  (scm_to_timezone, scm_struct_tm_zone_name): New helpers.
  (scm_to_struct_tm_and_timezone): Rename from bdtime2c and parse out a
  timezone_t as well.
  (scm_localtime): Use localtime_rz to avoid having to call tzset.
  (scm_gmtime): Use gmtime_r.
  (scm_mktime): Use mktime_z.
  (scm_strftime): Use the timezone_t argument to nstrftime.  Use
  nstrftime with a NULL buffer to measure how big of a buffer to
  allocate.
  (scm_strptime): Use scm_from_struct_tm.
2015-10-25 10:43:26 +00:00
Andy Wingo
f63093c801 Add strptime gnulib module.
* lib/Makefile.am:
* lib/strcasecmp.c:
* lib/strings.in.h:
* lib/strncasecmp.c:
* lib/strptime.c:
* m4/gnulib-cache.m4:
* m4/gnulib-comp.m4:
* m4/strcase.m4:
* m4/strings_h.m4:
* m4/strptime.m4: Import strptime module from gnulib.
2015-10-25 10:36:09 +00:00
Andy Wingo
2adc01ba51 Add time_rz gnulib module.
* lib/Makefile.am:
* m4/gnulib-cache.m4: The module was already available, but list it
  explicitly :)
2015-10-23 16:09:28 +00:00
Andy Wingo
1c9e23c090 Bootstrap makefile tweaks
* bootstrap/Makefile.am (.scm.go): Fix -L options to point to /module.
  (SOURCES): Move up psyntax-pp.scm.  Sadly a bug while I was developing
  the bootstrap makefile meant that there was a stale psyntax-pp.go from
  module/ that the build was picking up, leading to invalid
  bootstrap timing measurements.
2015-10-23 16:49:02 +02:00
Andy Wingo
5f4ac529e1 Use a bootstrapped -O0 compiler to compile the -O2 Guile
This reduces total build time to around 30 minutes or so.

* Makefile.am (SUBDIRS): Visit bootstrap/ before module/.

* bootstrap/Makefile.am: New file.

* configure.ac: Generate bootstrap/Makefile.

* meta/uninstalled-env.in (top_builddir): Add bootstrap/ to the
  GUILE_LOAD_COMPILED_PATH.

* module/Makefile.am: Simplify to just sort files in alphabetical order;
  since bootstrap/ was already compiled, we don't need to try to
  optimize compilation order.  Although the compiler will get faster as
  more of the compiler itself is optimized, this isn't a significant
  enough effect to worry about.
2015-10-23 13:29:03 +00:00
Andy Wingo
f169be9fc8 Wire up `guild compile -O0 foo.scm'
* module/scripts/compile.scm (%options): Resurrect -O option and make it
  follow GCC, more or less.  The default is equivalent to -O2.

* module/language/cps/compile-bytecode.scm (lower-cps):
* module/language/cps/optimize.scm (optimize-higher-order-cps): Move
  split-rec to run unconditionally for now, as closure conversion fails
  without it.
  (define-optimizer): Only verify the result if we are debugging, to
  save time.
  (cps-default-optimization-options): New exported procedure.

* module/language/tree-il/optimize.scm
  (tree-il-default-optimization-options): New exported procedure.
2015-10-22 17:44:17 +00:00
Andy Wingo
2d4da30fde Update Gnulib to v0.1-603-g1d16a7b 2015-10-22 13:34:00 +00:00
Andy Wingo
139ef2d17c Minor NEWS update. 2015-10-22 13:03:51 +00:00
Andy Wingo
8832e8b68c Small subr-call refactor
* libguile/gsubr.c (scm_apply_subr): New internal helper.
* libguile/vm-engine.c (subr-call): Call out to scm_apply_subr.
* doc/ref/vm.texi (subr-call): Don't specify how the foreign pointer is
  obtained.
2015-10-22 12:13:37 +00:00
Andy Wingo
9144f50c31 subr-call implementation simplification
* libguile/vm-engine.c (subr-call): Reference args from SP, not FP.
2015-10-22 11:35:07 +00:00
Andy Wingo
467e587d68 Update VM documentation for new stack layout
* doc/ref/vm.texi: Update for new stack layout.
* module/system/vm/disassembler.scm (code-annotation): Print the frame
  sizes after alloc-frame, reset-frame, etc to make reading the
  disassembly easier.
2015-10-22 11:02:18 +00:00
Andy Wingo
f03960412e Add stack size computation to disassembler
* module/system/vm/disassembler.scm (define-stack-effect-parser)
  (stack-effect-parsers, instruction-stack-size-after): New stack size
  facility.
  (define-clobber-parser, clobber-parsers, instruction-slot-clobbers):
  Take incoming and outgoing stack sizes as arguments to interpret
  SP-relative clobbers.

* module/system/vm/frame.scm (compute-frame-sizes): New helper that
  computes frame sizes for each position in a function.
  (compute-killv): Adapt to compute the clobbered set given the computed
  frame sizes.
2015-10-21 15:02:28 +02:00
Andy Wingo
4afb46f859 Minor assembler cleanups
* module/system/vm/assembler.scm (shuffling-assembler): Minor renames.
2015-10-21 15:02:08 +02:00
Andy Wingo
70c317ab51 SP-relative local addressing
* libguile/vm-engine.c: S24/S12/S8 operands addressed relative to the
  SP, not the FP.  Cache the SP instead of a FP-relative locals
  pointer.  Further cleanups to follow.

* libguile/vm.c (vm_builtin_call_with_values_code): Adapt to mov operand
  addresing change.

* module/language/cps/compile-bytecode.scm (compile-function): Reify
  SP-relative local indexes where appropriate.

* module/system/vm/assembler.scm (emit-fmov*): New helper, exported as
  emit-fmov.
  (shuffling-assembler, define-shuffling-assembler): Rewrite to shuffle
  via push/pop/drop.
  (standard-prelude, opt-prelude, kw-prelude): No need to provide for
  shuffling args.

* test-suite/tests/rtl.test: Update.

* module/language/cps/slot-allocation.scm: Don't reserve slots 253-255.
2015-10-21 11:49:20 +02:00
Andy Wingo
9b1ac02a85 Fix boot closure wrong-num-args error
* libguile/eval.c (prepare_boot_closure_env_for_eval): Fix issue if
  fixed closure is called with wrong number of arguments during
  bootstrap.
2015-10-21 11:49:20 +02:00
Andy Wingo
0da0308b84 Prepare for SP-addressed locals
* libguile/vm-engine.c: Renumber opcodes, and take the opportunity to
  fold recent additions into more logical places.  Be more precise when
  describing the encoding of operands, to shuffle local references only
  and not constants, immediates, or other such values.
  (SP_REF, SP_SET): New helpers.
  (BR_BINARY, BR_ARITHMETIC): Take full 24-bit operands.  Our shuffle
  strategy is to emit push when needed to bring far locals near, then
  pop afterwards, shuffling away far destination values as needed; but
  that doesn't work for conditionals, unless we introduce a trampoline.
  Let's just do the simple thing for now.  Native compilation will use
  condition codes.
  (push, pop, drop): Back from the dead!  We'll only use these for
  temporary shuffling though, when an opcode can't address the full
  24-bit range.
  (long-fmov): New instruction, like long-mov but relative to the frame
  pointer.
  (load-typed-array, make-array): Don't use a compressed encoding so
  that we can avoid the shuffling case.  It would be a pain, given that
  they have so many operands already.

* module/language/bytecode.scm (compute-instruction-arity): Update for
  new instrution word encodings.

* module/system/vm/assembler.scm: Update to expose some opcodes
  directly, without the need for shuffling wrappers.  Adapt to
  instruction word encodings change.

* module/system/vm/disassembler.scm (disassembler): Adapt to instruction
  coding change.
2015-10-21 11:49:20 +02:00
Andy Wingo
72353de77d Replace dynamic link on stack with previous frame size
* libguile/frames.h (SCM_FRAME_DYNAMIC_LINK)
  (SCM_FRAME_SET_DYNAMIC_LINK): Instead of storing the absolute value of
  the previous FP, store its offset from the current FP.  This allows us
  to avoid relinking when composing continuations or when relocating the
  stack.

* libguile/frames.c (scm_frame_dynamic_link, scm_c_frame_previous): No
  need to relocate the dynamic link.

* libguile/vm.c (vm_return_to_continuation_inner):
  (vm_reinstate_partial_continuation_inner, vm_expand_stack_inner):
  Don't relocate the frame pointer chain.
  (scm_i_vm_mark_stack): Terminate when FP is above stack_top, not when
  0.
  (make_vm): Init FP to stack_top.
2015-10-21 11:49:20 +02:00
Andy Wingo
8f027385db Rename union scm_vm_stack_element members
* libguile/frames.h (union scm_vm_stack_element): Rename members from
  scm, ip, etc to as_scm, as_ip, etc.  Adapt users.
2015-10-21 11:49:20 +02:00
Andy Wingo
30c06bfbb3 Remove sp from scm_vm_cont
* libguile/vm.h (struct scm_vm_cont): Remove "sp" member; it's always
  the same as stack_bottom.

* libguile/vm.c (scm_i_vm_cont_to_frame, scm_i_vm_capture_stack):
  (vm_return_to_continuation_inner):
* libguile/stacks.c (scm_make_stack):
* libguile/continuations.c (scm_i_continuation_to_frame): Adapt.
2015-10-21 11:49:20 +02:00
Andy Wingo
aa9f6b0082 VM caches address of local 0 instead of FP
* libguile/vm-engine.c (vm_engine): Cache the address of local 0 instead
  of the FP.  This makes locals access a bit cheaper, but we still have
  to negate the index.  The right fix is to index relative to the SP
  instead.  That's a more involved change, so we punt until later.
2015-10-21 11:49:20 +02:00
Andy Wingo
0007507340 VM stack grows downward
Adapt VM stack to grow downward.  This will make native compilation look
more like the VM code, as we will be able to use native CALL
instructions, taking proper advantage of the return address buffer.

* libguile/continuations.c (scm_i_continuation_to_frame): Record offsets
  from stack top.

* libguile/control.c (scm_i_prompt_pop_abort_args_x): Adapt for reversed
  order of arguments, and instead of relying on the abort to push on the
  number of arguments, make the caller save the stack depth, which
  allows us to compute the number of arguments ourselves.
  (reify_partial_continuation, scm_c_abort): Adapt to reversed stack
  order.

* libguile/dynstack.c (scm_dynstack_wind_prompt): Since we wind the
  stack in a downward direction, subtract the reloc instead of adding
  it.

* libguile/dynstack.h (SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY): Remove flag;
  instead rely on prompt-establishing code to save the stack depth.

* libguile/eval.c (eval): Remove extraneous "volatile" declarations for
  variables that are not re-set between the setjmp and any longjmp.
  Adapt to save stack depth before instating the prompt.

* libguile/foreign.c (scm_i_foreign_call): Adapt to receive arguments in
  reverse order.

* libguile/frames.c (frame_stack_top, scm_i_frame_stack_top): Adapt to
  compute stack top instead of stack bottom.
  (scm_c_frame_closure): Adapt to stack growth change.
  (scm_frame_num_locals, scm_frame_local_ref, scm_frame_set_x): Use
  union data type to access stack.
  (RELOC): Reformat.
  (scm_c_frame_previous): Adapt to stack growth change.

* libguile/frames.h: Adapt stack diagram to indicate that the stack
  grows up.
  (union scm_vm_stack_element): New data type used to access items on
  the stack.
  (SCM_FRAME_PREVIOUS_SP)
  (SCM_FRAME_RETURN_ADDRESS, SCM_FRAME_SET_RETURN_ADDRESS)
  (SCM_FRAME_DYNAMIC_LINK, SCM_FRAME_SET_DYNAMIC_LINK)
  (SCM_FRAME_LOCAL, SCM_FRAME_NUM_LOCALS): Adapt to stack representation
  change.
  (SCM_FRAME_SLOT): New helper.
  (SCM_VM_FRAME_FP, SCM_VM_FRAME_SP): Adapt to stack growth change.

* libguile/stacks.c (scm_make_stack): Record offsets from top of stack.

* libguile/throw.c (catch): Adapt to scm_i_prompt_pop_abort_args_x
  change.

* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
  (FRAME_LOCALS_COUNT_FROM): Adapt to stack growth change.
  (LOCAL_ADDRESS): Use SCM_FRAME_SLOT to get the address as the proper
  data type.
  (RETURN_ONE_VALUE, RETURN_VALUE_LIST): Adapt to stack growth change.
  (apply): Shuffling up the SMOB apply args can cause the stack to
  expand, so use ALLOC_FRAME instead of RESET_FRAME.
  (vm_engine): Adapt for stack growth change.

* libguile/vm.c (vm_increase_sp, vm_push_sp, vm_restore_sp): Adapt to
  stack representation change.
  (scm_i_vm_cont_to_frame): Adapt to take offsets from the top.
  (scm_i_vm_capture_stack): Adapt to capture from the top.
  (vm_return_to_continuation_inner): Adapt for data type changes.
  (vm_return_to_continuation): Likewise, and instead of looping, just
  splat the saved arguments on with memcpy.
  (vm_dispatch_hook): Adapt to receive arguments in the reverse order.
  Adapt callers.
  (vm_abort): There is never a tail argument.  Adapt to stack
  representation change.
  (vm_reinstate_partial_continuation)
  (vm_reinstate_partial_continuation_inner): Adapt to stack growth
  change.
  (allocate_stack, free_stack): Adapt to data type change.
  (expand_stack): Don't try to mremap(), as you can't grow a mapping
  from the bottom.  Without knowing that there's a free mapping space
  right below the old stack, which there usually isn't on Linux, we have
  to copy.  We can't use MAP_GROWSDOWN because Linux is buggy.
  (make_vm): Adapt to stack representation changes.
  (return_unused_stack_to_os): Round down instead of up, as the stack
  grows down.
  (scm_i_vm_mark_stack): Adapt to walk up the stack.
  (scm_i_vm_free_stack): Adapt to scm_vm changes.
  (vm_expand_stack_inner, reset_stack_limit, vm_expand_stack): Adapt to
  the stack growing down.
  (scm_call_n): Adapt to the stack growing down.  Don't allow argv to
  point into the stack.

* libguile/vm.h (struct scm_vm, struct scm_vm_cont): Adapt to hold the
  stack top and bottom.
2015-10-21 11:49:20 +02:00
Andy Wingo
d7199da8c9 Fix prompt miscompilation
* module/language/cps/compile-bytecode.scm (compile-function): Fix
  miscompilation when the handler body is forwarded.
2015-10-21 11:49:20 +02:00
Andy Wingo
a0a8741608 Minor VM documentation updates
* doc/ref/vm.texi (Why a VM?, Variables and the VM): Minor updates.
2015-10-21 11:49:20 +02:00
Mark H Weaver
315adb6347 Fix typo in CPS conversion.
Fixes <http://bugs.gnu.org/21614>.
Reported by tantalum <sph@posteo.eu>.

* module/language/tree-il/compile-cps.scm (convert): Add missing 'cps'
  argument to the continuation passed to 'convert-arg'.
2015-10-06 10:09:12 -04:00
Andy Wingo
73f6146bd8 Minor CPS documentation cleanups
* doc/ref/compiler.texi (Continuation-Passing Style): Minor cleanups.
2015-09-18 10:13:35 +02:00
Andy Wingo
d701e8a3d3 Update CPS language documentation
* doc/ref/compiler.texi (Continuation-Passing Style): Update to latest
  CPS language.
2015-09-17 20:14:35 +02:00
Andy Wingo
78fdc3e673 Remove unused (language tree-il inline) module.
* module/language/tree-il/inline.scm: Remove.
* module/Makefile.am (TREE_IL_LANG_SOURCES): Remove inline.scm.
2015-09-17 12:45:36 +02:00
Mark H Weaver
00884bb79f Allow decoding of UTF-8 containing U+FFFD, the replacement character.
* libguile/strings.c (scm_from_utf8_stringn): Use 'u8_mbtoucr' and check
  for a decoding error by its 'nbytes' return value.  Previously we used
  'u8_mbtouc' and improperly assumed that a U+FFFD character indicated a
  decoding error.
* libguile/symbols.c (utf8_string_equals_wide_string): Likewise.
* test-suite/tests/bytevectors.test (exception:decoding-error): New
  variable.
  ("2.9 Operations on Strings"): Add tests.
2015-08-13 01:31:36 -04:00
Andy Wingo
48412395c6 Add closure effects
* module/language/cps/effects-analysis.scm: Add closure effects, to
  enable hoisting/CSE of free-ref/free-set!.
2015-07-27 15:19:45 +02:00
Andy Wingo
90c11483e6 Better codegen for $values terms that don't shuffle
* module/language/cps/compile-bytecode.scm (compute-forwarding-labels):
  Analyze forwarding labels before emitting code.  This lets us elide
  conts that cause no shuffles, allowing more fallthrough.
2015-07-27 14:53:59 +02:00
Andy Wingo
3b60e79879 Loop peeling
* module/language/cps/peel-loops.scm: New pass.  Only enabled if the
  loop has one successor.

* module/language/cps/optimize.scm: Peel instead of doing LICM on
  higher-order CPS, then LICM on first-order CPS.

* module/Makefile.am: Wire up new pass.
2015-07-27 13:45:23 +02:00
Andy Wingo
4792577ab8 solve-flow-equations tweak
* module/language/cps/utils.scm (solve-flow-equations): Revert to take
  separate in and out maps.  Take an optional initial worklist.

* module/language/cps/slot-allocation.scm: Adapt to solve-flow-equations
  change.
2015-07-27 13:25:38 +02:00
Andy Wingo
ce2888701c Simplify rotate-loops.scm
* module/language/cps/rotate-loops.scm: Clean up unused code.
2015-07-27 12:59:09 +02:00
Andy Wingo
e54fbff185 Loop inversion with multiple exits
* module/language/cps/rotate-loops.scm (rotate-loop): Instead of
  restricting rotation to loops with just one exit node, restrict to
  loops with just one exit successor.
2015-07-25 11:03:59 +02:00
Andy Wingo
ee85e2969f Rotate comparisons down to loop back-edges
* module/language/cps/rotate-loops.scm: New pass.
* module/Makefile.am:
* module/language/cps/optimize.scm: Wire up the new pass.
2015-07-24 16:51:04 +02:00
Andy Wingo
bf6930b3f6 Eliminate trampoline gotos when possible in compile-bytecode
* module/language/cps/compile-bytecode.scm (compile-function): Eliminate
  trampoline jumps for conditional branches that don't shuffle.
2015-07-24 16:51:04 +02:00
Andy Wingo
bcfa9fe70e Small expression-effects tweak
* module/language/cps/effects-analysis.scm (expression-effects):
  Closures with zero free vars don't allocate.
2015-07-24 16:51:04 +02:00
Andy Wingo
ec9554d138 Loop-invariant code motion
* module/language/cps/licm.scm: New pass.
* module/language/cps/optimize.scm: Wire up new pass.
* module/Makefile.am: Add new file.
2015-07-24 16:50:58 +02:00
Andy Wingo
bebc70c8b1 Move solve-flow-equations to utils
* module/language/cps/slot-allocation.scm (compute-lazy-vars):
  (compute-live-variables):  Adapt to solve-flow-equations interface
  change.

* module/language/cps/utils.scm (solve-flow-equations): Move here.  Use
  an init value instead of an init map.
2015-07-24 11:40:00 +02:00
Andy Wingo
b40fac1e98 Factor out compute-effects/elide-type-checks from dce.scm
* module/language/cps/type-checks.scm: New module.
* module/language/cps/dce.scm: Use new module.
* module/Makefile.am: Add new module.
2015-07-24 11:39:18 +02:00
Andy Wingo
4aabc205cc Add missing files
Last commit meant to rename files, not delete them.  Whoops!
2015-07-22 18:27:37 +02:00
Andy Wingo
aa7f0e25ac Rename CPS2 to CPS 2015-07-22 17:19:04 +02:00
Andy Wingo
0d4c937722 Remove CPS1 language
* module/language/cps.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dfg.scm:
* module/language/cps/renumber.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/spec.scm:
* module/language/cps/verify.scm:
* module/language/cps2/compile-cps.scm: Delete.
* module/Makefile.am: Remove deleted files.
2015-07-22 17:15:06 +02:00
Andy Wingo
39777b11b3 Compile CPS2 directly to bytecode
* module/language/cps2/spec.scm (cps2): Compile directly to bytecode.
2015-07-22 17:01:53 +02:00
Andy Wingo
910054bfbc Slot allocation and bytecode compilation from CPS2.
* module/language/cps2/compile-bytecode.scm: New file.
* module/language/cps2/slot-allocation.scm: New file.
* module/Makefile.am: Add new files.
2015-07-22 17:01:19 +02:00
Andy Wingo
16d92c566f Fix CPS2 compute-successors
* module/language/cps2/utils.scm (compute-successors): Propagate $kfun
  to $ktail so that we don't leave off the tail if the body iloops.
2015-07-22 17:00:34 +02:00
Andy Wingo
2df454b95b intset-intersect bugfix
* module/language/cps/intset.scm (intset-intersect): Remove new-leaf
  procedure, inlining to single call site.  An empty intersection
  properly produces #f so that the set can be pruned.
2015-07-22 16:59:47 +02:00
Andy Wingo
ff2beb186e Fix bad return shuffles for multiply-used $kreceive conts
* module/language/cps2/reify-primitives.scm (uniquify-receive):
  (reify-primitives): Ensure that $kreceive conts can have only one
  predecessor.  Otherwise return shuffles are incorrectly allocated.
2015-07-21 17:48:22 +02:00
Andy Wingo
08cf30f2a0 Fix error printing some wrong-num-args backtraces
* module/system/repl/debug.scm (print-frame): Pass #:top-frame? #t for
  the top frame.

* module/system/vm/frame.scm (available-bindings): Be permissive and
  allow #:top-frame? #f even when the IP is at the start of the
  function.
2015-07-20 16:24:49 +02:00
Andy Wingo
f63b2e4814 More slot-allocation simplification
* module/language/cps/slot-allocation.scm (allocate-slots): Remove
  unreachable clause.
2015-07-20 10:57:52 +02:00