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.
* module/language/tree-il/analyze.scm (shadowed-toplevel-analysis): New
variable.
* module/language/tree-il/compile-cps.scm (%warning-passes): Add it.
* module/system/base/message.scm (%warning-types): Add it.
* test-suite/tests/tree-il.test ("warnings")["shadowed-toplevel"]: New
test prefix.
* module/ice-9/boot-9.scm (%auto-compilation-options): Add it.
* doc/ref/api-evaluation.texi (Compilation): Add 'shadowed-toplevel' and
'macro-use-before-definition'.
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add new define!
intrinsic.
* module/language/cps/compile-bytecode.scm (compile-function): Adapt
compilation for define! to take two arguments.
* module/language/cps/effects-analysis.scm (current-module): Update
define! for two arguments.
* module/language/tree-il/compile-cps.scm (convert): When reifying
"define", grab the current module.
* module/system/vm/assembler.scm (define!): Define assembler as
intrinsic.
* module/language/cps/effects-analysis.scm (string-ref): Remove effects
declaration, given that the primitive is exploded now.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
Add string-set!.
* libguile/vm-engine.c (string-set!): Disable opcode.
* module/language/cps/types.scm (string-ref, string-set!): Remove type
checker and inferrers for string-ref and string-set!, as both are
exploded. In the case of string-set! there are still type-check
effects in the intrinsic call but they can't be elided by the checker,
as we don't track when strings are read-only.
* module/language/tree-il/compile-cps.scm (ensure-char): New helper.
(string-set!): New primcall exploded converter.
* module/language/cps/types.scm (annotation->type):
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
Add case for string memory kinds. Remove special type and effect
inferrers for string-length.
* module/language/cps/slot-allocation.scm (compute-var-representations):
Remove string-length.
* module/language/tree-il/compile-cps.scm (ensure-string): New helper.
(string-length): Add custom converter.
* module/language/cps/effects-analysis.scm (&memory-kind-mask): Add
&bitmask, for the bitmask in vtables.
(annotation->memory-kind): Add 'bitmask case.
* module/language/tree-il/compile-cps.scm (ensure-struct-index-in-range):
(prepare-struct-scm-access): New helpers.
(struct-ref/immediate, struct-set!/immediate): New exploded lowering
routines.
(struct-ref, struct-set!): New lowering routines that just do a call.
(canonicalize): Remove struct-ref hack; lowering procedures will
handle it.
* module/language/tree-il/cps-primitives.scm (bytevector-length): Define
struct-set! as returning a value.
* module/language/cps/compile-bytecode.scm (compile-function): Fix
emitters for u64-set! et al.
* module/language/tree-il/compile-cps.scm (bytevector-set-converter):
New helper. Lower bytevector setters to pointer ops.
* module/language/tree-il/compile-cps.scm (bytevector-ref-converter):
Take kind as tag, not boolean. Support floats. Adapt and add
lowerers for float-ref procedures.
* module/language/cps/compile-bytecode.scm (compile-function): Fix
emitters for u16-ref et al.
* module/language/tree-il/compile-cps.scm (bytevector-ref-converter):
(define-bytevector-ref-converter, define-bytevector-ref-converters):
New helpers. Use to define lowerers for bv-s32-ref et al.
* module/language/tree-il/compile-cps.scm (ensure-struct): New helper.xo
(struct-vtable): New lowering procedure.
* module/language/cps/types.scm (annotation->type): Add struct.
(scm-ref/tag, scm-set!/tag): Fix to get type from annotation.
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
Add struct.
* module/language/tree-il/compile-cps.scm
(emit-initializations-as-loop): New helper.
(make-vector): Use new helper.
(make-vector/immediate): Emit a loop if the number of words is greater
than or equal to 32. An arbitrary limit that could be adjusted later.
* module/language/tree-il/cps-primitives.scm (allocate-vector)
(vector-init!): Declare these primitives which later go away when
lowering to CPS.
* module/language/tree-il/compile-cps.scm (vector-init!): New
converter.
(allocate-vector): New converter.
* module/language/cps.scm ($branch): Refactor to be its own CPS term
type, not relying on $continue to specify a continuation (which before
was only for the false case) or a source location. Update allllllll
callers.
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
case where $prim could continue to $kreceive; this isn't possible.
However when reifying an unknown primcall, always add a $kreceive, as
the continuation has to be $kargs.
* module/language/tree-il/compile-cps.scm (convert): Unknown primcalls
convert as calls. With this change, all primcalls should continue to
$kargs, with the exception of 'throw.
* module/language/tree-il/compile-cps.scm (build-list): New helper.
(convert, canonicalize): Canonicalize "list" earlier. Allow sinking
of any initializer that can't capture the continuation, not just in
cases where all initializers have this property. Reify a cons chain
internally as appropriate.
* module/language/tree-il/cps-primitives.scm: New file,
replacing (language cps primitives). Lists known primitives and their
relation to Tree-IL explicitly, instead of assuming that any Tree-IL
primcall that shares a name with a bytecode instruction is a CPS
primcall.
* module/language/cps/verify.scm: Remove use of (language cps
primitives) and primcall arity checking. Would be nice to add this
back at some point.
* module/language/tree-il/compile-cps.scm (convert): Refactor to use new
tree-il-primitive->cps-primitive+nargs+nvalues helper.
* module/Makefile.am:
* am/bootstrap.am: Adapt.
This will allow individual primcall converters to define ad-hoc
conversion routines.
* module/language/tree-il/compile-cps.scm (convert-primcall/default)
(convert-indexed-getter, convert-indexed-setter)
(convert-indexed-getter/tag, convert-indexed-setter/untag)
(convert-scm-u64->scm-primcall, convert-scm-u64-scm-primcall)
(convert-scm-u64->f64-primcall, convert-scm-u64-f64-primcall)
(convert-scm-u64->u64-primcall, convert-scm-u64-u64-primcall)
(convert-scm-u64->s64-primcall, convert-scm-u64-s64-primcall)
(convert-*->u64-primcall, convert-scm->u64-primcall)
(convert-u64->scm-primcall): Define some primcall converter helpers.
(*primcall-converters*, define-primcall-converter)
(define-primcall-converters): Define converters for a number of
primcalls.
(convert-primcall*, convert-primcall): Interface to primcall
converters.
(convert): Pass most primcalls through convert-primcall, unless we
know already that they don't need instruction explosion or
boxing/unboxing.
* module/language/tree-il/compile-cps.scm (init-default-value): Use
undefined? predicate instead of reifying an unbound value in the CPS
term.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
for the special immediate predicates. Evidently we aren't emitting
these yet!
* module/language/cps/compile-bytecode.scm (compile-function): Add
support for emitting <= via < and jge / jnge.
* module/language/cps/effects-analysis.scm: Declare effects for <= and
f64-<=.
* module/language/cps/primitives.scm (*comparisons*): Add <=, f64-<=.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Specialize <= to < for integer comparisons. Specialize to f64-<= for
f64 ops.
* module/language/cps/type-fold.scm (<=): Add folder.
* module/language/cps/types.scm (infer-<=): Add inferrer.
* module/language/tree-il/compile-cps.scm (canonicalize): Canonicalize
<= and >= to <=, so that nans are handled correctly.
* module/language/tree-il/compile-cps.scm (adapt-arity): Allow k to be
$kargs for the 1-valued case.
(convert): For single-valued continuations where the definition is
clearly single-valued, avoid making a needless $kreceive and extra
"rest" binding that will just be filled with () and have to be
eliminated later.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*, *effect+exception-free-primitives*): Detect
use of exact-integer?.
* module/language/tree-il/compile-cps.scm (canonicalize): Compile
exact-integer? to a fixnum?-or-bignum? check.
* module/language/cps/type-fold.scm (u64->scm, scm->u64): Fix
type-safety by adding casts.
* module/language/tree-il/compile-cps.scm (convert, canonicalize):
Simplify rsh and lsh compilation by not trying to avoid scm->u64 in
the early stages of the compiler.
* module/language/cps/effects-analysis.scm: Remove case for "ash".
* module/language/cps/types.scm (ash): Remove.
* module/language/tree-il/compile-cps.scm (convert, canonicalize):
Convert "ash" to "lsh"/"rsh" early on.
* module/system/base/target.scm (target-fixnum?): New procedure.
* module/language/tree-il/compile-cps.scm (canonicalize): Convert <=,
>=, and > primcalls to <.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/effects-analysis.scm: Remove superfluous
primcalls.
* module/language/cps/specialize-numbers.scm
(specialize-u64-scm-comparison): Only emit < primcalls for ordered
comparisons.
(specialize-scm-u64-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
Remove support for >=, <=, and the like.
* module/language/cps/type-fold.scm: Remove folders for <= and so on.
* module/language/cps/types.scm (define-=-inferrer, define-<-inferrer):
New helpers; use them for all = and < variants. Remove checkers and
inferrers for <= and the like.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
unnecessary cases.
* libguile/throw.h (scm_ithrow, scm_throw): Mark as SCM_NORETURN.
* libguile/throw.c (scm_throw, scm_ithrow): Adapt to not return.
* libguile/vm-engine.c (throw, throw/value, throw/value+data): New
instructions.
* libguile/vm.c (vm_throw, vm_throw_with_value)
(vm_throw_with_value_and_data): New helpers.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
for new instructions.
* module/language/cps/prune-bailouts.scm (prune-bailouts): More simple,
now that there are no $kreceives in play.
* module/language/cps/reify-primitives.scm (reify-clause): Update
reification of no-clause functions to use new throw op.
* module/language/tree-il/compile-cps.scm (convert): Convert invocations
of the variable-arity 'throw primitive from Tree-IL to the new
fixed-arity CPS instructions.
* module/system/vm/assembler.scm (emit-throw/value*)
(emit-throw/value+data*, emit-throw): Export new instructions.
* module/system/vm/disassembler.scm (code-annotation): Add annotation.