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

147 commits

Author SHA1 Message Date
Andy Wingo
b88fef5519 fix invalid transformation of (values x) -> x, (+ x) -> x, etc
* module/language/tree-il/primitives.scm (+, *, cons*): In the case of
  just one argument (the identity case), expand to (values x) instead of
  just x.  Fixes values truncation in that case.
  (values): Likewise remove (values x) -> x translation, as the compiler
  will do it for us, and this fixes (values (values 1 2)).

* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Handle
  `values' in a push context here.

* test-suite/tests/tree-il.test ("values"): Add some tests.
2011-06-17 19:42:55 +02:00
Andy Wingo
a881a4ae3b add <primcall> to tree-il
* libguile/expand.c:
* libguile/expand.h (SCM_EXPANDED_PRIMCALL_TYPE_NAME):
  (SCM_EXPANDED_PRIMCALL_FIELD_NAMES):
  (SCM_EXPANDED_PRIMCALL_SRC):
  (SCM_EXPANDED_PRIMCALL_NAME):
  (SCM_EXPANDED_PRIMCALL_ARGS):
  (SCM_MAKE_EXPANDED_PRIMCALL): Add "primcall" Tree-IL type.

* doc/ref/compiler.texi (Tree-IL): Update docs.

* libguile/memoize.c (memoize): Memoizer for primcalls.

* module/ice-9/psyntax.scm: Build primcalls, sometimes.  Also change
  build-primref to just make a primitive-ref.

* module/language/tree-il.scm: Add primcall to the exports, parsers,
  serializers, etc.

* module/language/tree-il/analyze.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/fix-letrec.scm:
* module/language/tree-il/inline.scm:
* module/language/tree-il/primitives.scm:
* module/language/elisp/compile-tree-il.scm: Add primcall support.

* test-suite/tests/tree-il.test: Use primcalls sometimes.
2011-06-02 17:45:58 +02:00
Andy Wingo
7081d4f981 rename <application> to <call>
* doc/ref/compiler.texi (The Scheme Compiler): Update docs.

* libguile/expand.h:
* libguile/expand.c:
* module/language/tree-il.scm: Rename <application> to <call>.  Change
  the external representation from (apply proc arg ...) to (call proc
  arg ...).

* libguile/memoize.c:
* module/ice-9/psyntax-pp.scm:
* module/ice-9/psyntax.scm:
* module/language/brainfuck/compile-tree-il.scm:
* module/language/ecmascript/compile-tree-il.scm:
* module/language/elisp/compile-tree-il.scm:
* module/language/tree-il/analyze.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/fix-letrec.scm:
* module/language/tree-il/inline.scm:
* module/language/tree-il/primitives.scm:
* test-suite/tests/tree-il.test: Update all callers.
2011-06-02 13:42:55 +02:00
Ludovic Courtès
022ae742d1 Add tests for `-Wformat' and gettext.
* test-suite/tests/tree-il.test ("warnings")["non-literal format string
  using gettext", "one missing argument, gettext"]: New tests.
2011-04-14 23:14:14 +02:00
Ludovic Courtès
65ea26c582 Handle letrec*' like letrec' in simple cases.
* module/language/tree-il/fix-letrec.scm (fix-letrec!): When X is a
  `letrec*' with only lambdas and simple expressions, analyze it as if
  it were a `letrec'.
* test-suite/tests/tree-il.test ("letrec"): Add test for
  `(letrec* (x y) (xx yy) ((const 1) (const 2)) (lexical y yy))'.
2011-03-06 23:05:01 +01:00
Ludovic Courtès
a4060f6710 Add `*current-warning-prefix*'.
* module/system/base/message.scm (*current-warning-prefix*): New
  variable.
  (%warning-types): Honor `*current-warning-prefix*'.

* module/scripts/compile.scm (compile): Use an empty
  `*current-warning-prefix*'.

* module/system/repl/common.scm (repl-compile): Likewise.

* test-suite/tests/tree-il.test (call-with-warnings): Likewise.
2011-02-13 19:13:36 +01:00
Ludovic Courtès
3a1a883b63 Tweak -Wunused-variable' and -Wunused-toplevel' for special names.
* module/language/tree-il/analyze.scm (gensym?): New procedure.
  (unused-variable-analysis): Ignore variables whose name passes
  `gensym?' or is `_'.
  (unused-toplevel-analysis): Ignore variables whose name passes
  `gensym?'.

* test-suite/tests/tree-il.test ("warnings")["unused-variable"]("special
  variable names"): New test.
  ["unused-toplevel"]("special variable names"): New test.
2010-10-20 23:45:59 +02:00
Ludovic Courtès
8e6c15a6f0 Add warnings for obvious syntax errors in format strings.
* module/language/tree-il/analyze.scm (&syntax-error): New variable.
  (format-string-argument-count): Throw to &SYNTAX-ERROR when a syntax
  error in a format string is encountered.
  (format-analysis): Catch &SYNTAX-ERROR and convert as a warning of the
  appropriate type.

* module/system/base/message.scm (%warning-types)[format]: Handle
  `syntax-error' warnings.

* test-suite/tests/tree-il.test
  ("warnings")["conditionals"]("unterminated", "unexpected ~;",
  "unexpected ~]"): New tests.
  ["unterminated ~{...~}"]: New test.
2010-10-10 19:10:11 +02:00
Ludovic Courtès
60f01304ee Add new `format' warnings.
* module/language/tree-il/analyze.scm (format-analysis): Add new
  sub-warnings: `wrong-port', `wrong-format-string',
  `non-literal-format-string', and `wrong-num-args'.

* module/system/base/message.scm (%warning-types)[format]: Handle
  them.

* test-suite/tests/tree-il.test ("warnings")["wrong port arg",
  "wrong format string", "non-literal format string",
  "wrong number of args"]: New tests.
2010-10-10 19:10:11 +02:00
Ludovic Courtès
e06972410a Implement fancy format string analysis.
* module/language/tree-il/analyze.scm (format-string-argument-count):
  Return two values, the minimum and maximum number of arguments.
  Add support for most of `format' escapes, including conditionals.
  (format-analysis): Adjust accordingly.

* module/system/base/message.scm (%warning-types)[format]: Take two
  arguments, MIN and MAX, instead of EXPECTED.  Display warning
  accordingly.

* test-suite/tests/tree-il.test ("warnings")["format"]("~%, ~~, ~&, ~t,
  ~_, and ~\\n", "~{...~}", "~{...~}, too many args", "~@{...~}",
  "~@{...~}, too few args", "~(...~)", "~v", "~v:@y", "~*", "~?",
  "complex 1", "complex 2", "complex 3"): New tests.
  ("conditionals"): New test prefix.
2010-10-10 19:10:10 +02:00
Ludovic Courtès
75365375dd Add `-Wformat'.
* module/language/tree-il/analyze.scm (format-string-argument-count):
  New procedure.
  (format-analysis): New tree analysis.

* module/language/tree-il/compile-glil.scm (%warning-passes): Add
  `format'.

* module/system/base/message.scm (%warning-types): Add `format'.

* test-suite/tests/tree-il.test (%opts-w-format): New variable.
  ("warnings")["format"]: New test prefix.

* doc/ref/api-evaluation.texi (Compilation): Mention `format' warnings.
2010-10-08 16:25:57 +02:00
Andy Wingo
60d4b22448 compiler support for letrec*
* test-suite/tests/tree-il.test ("letrec"): Add some tests.
* module/language/tree-il/compile-glil.scm (flatten): Add support for
  compiling letrec* in its unoptimized form.

* module/language/tree-il/fix-letrec.scm (simple-expression?):
  Parameterize, so that letrec* will not treat `(car x)' as primitive
  (because it could raise an exception).
  (partition-vars): Lump unreferenced vars in with complex vars, when
  compiling letrec*.
  (fix-letrec!): No need to evaluate inits within a let for letrec*.
2010-06-17 13:43:26 +02:00
Andy Wingo
0e4b781898 add inliner cases for conditionals
* module/language/tree-il/inline.scm (boolean-value, inline!): Add a
  case for inlining conditional expressions.

* test-suite/tests/tree-il.test: Fix conditional tests to have a
  non-inlinable condition.
2010-06-11 16:58:31 +02:00
Andy Wingo
05c51bcff5 use anonymous mv-bind in compile-glil.scm; fix abort compilation bug
* module/language/tree-il/compile-glil.scm (flatten): Change to use the
  anonymous <glil-mv-bind> form when truncating to 0 or 1 values. In
  those cases, remove the <glil-unbind> statements. As a side effect,
  fixes compilation of abort in a "values" context.

  Thanks to Tristan Colgate for the bug report.

* test-suite/tests/tree-il.test: Update to expect anonymous mv-bind.
2010-03-03 21:01:05 +01:00
Ludovic Courtès
411313403c Evaluate the export' and re-export' forms at compile-time.
* module/ice-9/boot-9.scm (export, re-export): Evaluate at compile-time
  in addition to load/eval.

* test-suite/tests/tree-il.test ("warnings")["unused-toplevel"]("unused
  but define-public"): Remove throw to `unresolved'.
2010-01-11 18:31:02 +01:00
Ludovic Courtès
bcae9a98b0 Add `-Wunused-toplevel' compiler warning.
* module/language/tree-il/analyze.scm (<reference-dag>): New record
  type.
  (dag-reachable-nodes, dag-reachable-nodes*, unused-variable-analysis):
  New variables.
  (unbound-variable-analysis): Slightly simplify the `up' procedure.

* module/language/tree-il/compile-glil.scm (%warning-passes): Add
  `unused-toplevel'.

* module/system/base/message.scm (%warning-types): Likewise.

* test-suite/tests/tree-il.test (%opts-w-unused-toplevel): New variable.
  ("warnings")["unused-toplevel"]: New test prefix.
2010-01-11 01:21:13 +01:00
Andy Wingo
6f16379e9a allocate free variables inline to closures
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES)
  (SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET)
  (SCM_PROGRAM_NUM_FREE_VARIABLES):
* libguile/programs.c (scm_make_program, scm_program_num_free_variables)
  (scm_program_free_variable_ref, scm_program_free_variable_set_x):
  Allocate free variables inline with programs, instead of being in a
  vect. Should improve locality, and require fewer local variables in
  the VM.

* libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count
  variables.

* libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars
  and free_vars_count.
  (CHECK_FREE_VARIABLE): Update for inline free vars.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free
  vars.
  (make-closure, fix-closure): Take the closure vals as separate stack
  args, and copy or fix them inline into the appropriate closure.

* module/language/objcode/spec.scm (program-free-variables): Define a
  local version of this removed function.

* module/language/tree-il/compile-glil.scm (flatten): Adjust to not make
  a vector when making closures.

* module/system/vm/program.scm: Export program-num-free-variables,
  program-free-variable-ref, program-free-variable-set!, and remove
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update to not make vectors
  when making closures.
2010-01-09 16:43:26 +01:00
Andy Wingo
a5bbb22e83 rename goto/args and friends to tail-call, tail-apply, etc
* libguile/vm-i-system.c (tail-call, tail-call/nargs, tail-apply)
  (tail-call/cc): Rename these back to tail-* from goto/*. We should
  reserve the rename-then-goto name for when you actually do a rename
  and goto, not when you shuffle the stack.

* doc/ref/vm.texi:
* module/language/glil/decompile-assembly.scm:
* module/language/tree-il/compile-glil.scm:
* test-suite/tests/tree-il.test: Adapt all callers and documentation.
2010-01-03 14:49:40 +01:00
Andy Wingo
1e2a8edb8b Revert "implement #:predicate" and remove predicate from <lambda-case>
Turns out this was not a very useful idea, and semantically tricky to
boot.

This reverts commit 24bf130fd1, and makes
the following additional changes:

* module/ice-9/optargs.scm (parse-lambda-case, let-optional)
  (let-optional*, let-keywords, let-keywords*):
* module/language/tree-il.scm: (<lambda-case>, parse-tree-il)
  (unparse-tree-il, tree-il->scheme, tree-il-fold,
  make-tree-il-folder)
  (post-order!, pre-order!):
* module/language/tree-il/analyze.scm (analyze-lexicals):
* module/language/tree-il/compile-glil.scm (compile-glil):
* module/language/tree-il/inline.scm (inline!): Remove all traces of
  #:predicate from tree-il.

* module/ice-9/psyntax.scm (build-simple-lambda, build-lambda-case)
  (chi-lambda-case): Adapt to tree-il change.
* module/ice-9/psyntax-pp.scm: Regenerated.

* module/language/brainfuck/compile-tree-il.scm (compile-body):
* module/language/ecmascript/compile-tree-il.scm (comp, comp-body):
* test-suite/tests/tree-il.test: Adapt to tree-il change.

* doc/ref/api-procedures.texi (Case-lambda): Remove mention of
  #:predicate.
2009-11-15 21:02:26 +01:00
Ludovic Courtès
99480e1118 Add support for multiple arities in `arity-mismatch-analysis'.
* module/language/tree-il/analyze.scm (validate-arity)[arity]: Rename
  to...
  [arities]: ... this.  Return all the arities of PROC.
  Update caller accordingly.

* test-suite/tests/tree-il.test ("warnings")["arity
  mismatch"]("case-lambda", "case-lambda with wrong number of
  arguments", "case-lambda*", "case-lambda* with wrong arguments"): New
  tests.
2009-11-08 17:53:14 +01:00
Ludovic Courtès
bd36e90132 Add tests for `unbound-variable-analysis'.
* test-suite/tests/tree-il.test ("warnings")["unbound
  variable"]("optional arguments are visible", "keyword arguments are
  visible"): New tests.
2009-11-08 01:11:19 +01:00
Ludovic Courtès
af5ed54927 Add support for keyword arguments in `arity-mismatch-analysis'.
* module/language/tree-il/analyze.scm
  (validate-arity)[filter-keyword-args]: New procedure.
  [arity]: Get accurate arity for programs, return ALLOW-OTHER-KEYS? as
  an additional value.
  Update to `arity' change; use `filter-keyword-args'.

* test-suite/tests/tree-il.test ("warnings")["arity mismatch"]("keyword
  not passed and quiet", "keyword passed and quiet", "keyword passed to
  global and quiet", "extra keyword", "extra keywords allowed"): New
  tests.
2009-11-08 01:02:08 +01:00
Ludovic Courtès
ae03cf1f59 Add `arity-mismatch' warning type.
* module/language/tree-il/analyze.scm (<arity-info>): New record type.
  (validate-arity, arity-analysis): New variables.

* module/language/tree-il/compile-glil.scm (%warning-passes): Add
  `arity-mismatch'.

* module/system/base/message.scm (%warning-types): Likewise.

* test-suite/tests/tree-il.test (read-and-compile): Remove, as it's now
  public.
  (%opts-w-arity): New.
  ("warnings")["arity mismatch"]: New test prefix.
2009-11-07 18:48:56 +01:00
Andy Wingo
b0c8c187d9 separate "inits" field in <lambda-case>; compile fixes for inits, kwargs
* module/language/tree-il.scm (<lambda-case>): Add "inits" field, so we
  don't have to parse it out of opt and kw. Adapt the traversal
  procedures.
* module/language/tree-il/analyze.scm (analyze-lexicals): Analyze
  lexicals in the <lambda-case> init expressions as well. Fix keyword
  allocation.

* module/language/tree-il/compile-glil.scm (compile-glil): Adapt to
  make-lambda-case change.
  (flatten): Adapt to "inits" slot, actually init uninitialized args,
  and fix bugs related to keyword arguments.

* module/language/tree-il/inline.scm (inline!): Adapt a little bit --
  but with no effect.

* module/language/glil/compile-assembly.scm (glil->assembly): Flesh out
  <glil-kw-prelude> compilation some more. Add a "bound?" op for
  <glil-lexical>, which will push #t if the local is bound.

* module/ice-9/psyntax.scm (build-simple-lambda, build-lambda-case):
  Update for new signature of make-lambda-case.
* module/ice-9/psyntax-pp.scm: Regenerated.

* module/language/brainfuck/compile-tree-il.scm (compile-body):
* module/language/ecmascript/compile-tree-il.scm (comp):
* test-suite/tests/tree-il.test ("lambda"): Update for new lambda-case
  syntax.
2009-10-23 16:48:05 +02:00
Andy Wingo
899d37a6cf more work towards compiling and interpreting keyword args
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bumparoo
* libguile/vm-i-system.c (push-rest, bind-rest): Logically there are
  actually two rest binders -- one that pops, conses, and pushes, and
  one that pops, conses, and local-sets. The latter is used on keyword
  arguments, because the keyword arguments themselves have been shuffled
  up on the stack. Renumber ops again.

* module/language/tree-il/compile-glil.scm (flatten): Attempt to handle
  compilation of lambda-case with keyword arguments. Might need some
  help.

* module/ice-9/psyntax.scm (build-lambda-case): An attempt to handle the
  interpreted case correctly. This might need a couple iterations, but
  at least it looks like the compile-glil code.

* module/ice-9/psyntax-pp.scm: Regenerated.

* module/language/glil.scm (<glil>): Rename "rest?" to "rest" in
  <glil-opt-prelude> and <glil-kw-prelude>, as it is no longer a simple
  boolean, but if true is an integer: the index of the local variable to
  which the rest should be bound.

* module/language/glil/compile-assembly.scm (glil->assembly): Adapt to
  "rest" vs "rest?". In the keyword case, use "bind-rest" instead of
  "push-rest".

* test-suite/tests/tree-il.test: Update for opt-prelude change.
2009-10-23 15:20:22 +02:00
Andy Wingo
8a4ca0ea3b tree-il support for case-lambda
* module/language/tree-il.scm (<lambda>, <lambda-case>): Split lambda
  into the lambda itself, denoting the procedure, and lambda-case,
  denoting a particular arity case. Lambda-case is fairly featureful,
  and has not yet been fully tested.
  (<let-values>): Use a <lambda-case> as the binding expression. Seems
  to suit the purpose well.
  Adapt parsers, unparsers, traversal operators, etc. Sometimes in this
  first version we assume there are no optional args, rest args, or a
  predicate.

* module/language/tree-il/analyze.scm (analyze-lexicals): Adapt for the
  new case-lambda regime. Fairly well commented. It actually simplifies
  things.
  (report-unused-variables): Update for new tree-il.

* module/language/tree-il/compile-glil.scm: Adapt for the new tree-il.
  There are some first stabs here at proper case-lambda compilation, but
  they are untested as of yet.

* module/language/tree-il/inline.scm (inline!): Rework so we can
  recurse on a single node; though these transformations are strictly
  reductive, so they should complete in bounded time. Simplify
  accordingly, and adapt to case-lambda. Oh, and we handle lambda->let
  in not just the nullary case.

* module/ice-9/psyntax.scm (build-simple-lambda, build-case-lambda)
  (build-lambda-case): New constructors. The idea is that after syntax
  expansion, we shouldn't have to deal with improper lists any more.
  Build-simple-lambda is a shortcut for the common case. The others are
  not fully exercised yet. Adapt callers.
  (syntax): Add some debugging in the lambda case. I don't fully
  understand this, but in practice we don't seem to see rest args here.
  (lambda): Inline chi-lambda-clause, and adapt for build-simple-lambda.
* module/ice-9/psyntax-pp.scm: Regenerated.

* test-suite/tests/tree-il.test: Update tests for new tree-il lambda
  format, and to expect post-prelude labels for all glil programs.
2009-10-23 15:10:25 +02:00
Andy Wingo
258344b4db flesh out glil support for optional and keyword arguments
* libguile/vm-i-system.c (bind-rest): Renamed from push-rest-list.
  (reserve-locals): Change so that instead of reserving space for some
  additional number of locals, reserve-locals takes the absolute number
  of locals, including the arguments.

* module/language/glil.scm (<glil-std-prelude>, <glil-opt-prelude>)
  (<glil-kw-prelude>): New GLIL constructs, to replace <glil-arity>.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  the new preludes. Some instructions are not yet implemented, though.

* module/language/tree-il/analyze.scm (analyze-lexicals): The nlocs for
  a lambda will now be the total number of locals, including arguments.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Update to
  write the new prelude.

* module/system/vm/program.scm (program-bindings-for-ip): If a given
  index doesn't have a binding at the ip given, don't cons it on the
  resulting list.

* test-suite/tests/tree-il.test: Update for GLIL changes.
2009-10-23 14:51:19 +02:00
Andy Wingo
56164a5a6c de-nargs struct scm_objcode; procedure-property refactor
* libguile/objcodes.h (struct scm_objcode): Remove nargs, nrest, and
  nlocs, as they are no longer needed. Also obviates the need for a
  padding word.

* libguile/procs.c (scm_thunk_p): Use scm_i_program_arity for programs.

* libguile/procprop.c (scm_i_procedure_arity): Use scm_i_program_arity
  for programs.
  (scm_procedure_properties, scm_set_procedure_properties_x)
  (scm_procedure_property, scm_set_procedure_property_x): Rework so that
  non-closure properties are stored directly in a weak hash, instead of
  needing a weak hash of "stand-in" closures to hold the properties. Fix
  docstrings also.

* libguile/root.h (scm_stand_in_procs): Remove from the scm_sys_protects
  set. Actually with libGC, we should be able to store the elements of
  scm_sys_protects directly as global variables.
* libguile/gc.c (scm_init_storage): Remove scm_stand_in_procs
  initialization.

* libguile/programs.c (scm_i_program_arity): New private accessor, tries
  to determine the "minimum arity" of a program.

* libguile/vm.c (really_make_boot_program): Adapt to changes in
  struct scm_objcode.

* module/language/assembly.scm (*program-header-len*, byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
  Adapt to changes in objcode.

* module/system/xref.scm (program-callee-rev-vars): Adapt to changes in
  assembly.

* module/language/glil.scm: Remove nargs, nrest, and nlocs from
  glil-program.

* module/language/glil/compile-assembly.scm (make-meta, glil->assembly):
* module/language/glil/decompile-assembly.scm (decompile-toplevel):
  (decompile-load-program): Adapt to changes in GLIL and assembly.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Adapt to
  changes in GLIL.

* test-suite/tests/asm-to-bytecode.test: Adapt to assembly and bytecode
  changes.
* test-suite/tests/tree-il.test: Adapt to GLIL changes.
2009-10-23 14:51:19 +02:00
Andy Wingo
55d9bc947e callees reserve their own local vars
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (reserve-locals): New instruction, to reserve
  space for local vars. Other ops renumbered.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
  reserve-locals instructions as necessary.

* test-suite/tests/tree-il.test: Update to expect reserve-locals as
  appropriate.
2009-10-23 14:51:18 +02:00
Andy Wingo
1e2a8c266d steps on the way to have the callee check the number of arguments
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/vm-i-system.c (assert-nargs-ee, assert-nargs-ge)
  (push-rest-list): New instructions, which for now don't actually do
  anything. Renumber the rest of the ops in this file.

* module/language/glil.scm (<glil-arity>): New GLIL type, an entity that
  checks the number of args for a block, optionally consing a rest list,
  and either branching or erroring if the arity doesn't match.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  <glil-arity> to assembly. Some of these VM ops are not implemented --
  notably the branching case.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
  <glil-arity>.

* test-suite/tests/tree-il.test: Update.
2009-10-23 14:51:17 +02:00
Ludovic Courtès
b6d2306d40 Have `-Wunbound-variable' account for GOOPS top-level definitions.
* module/language/tree-il/analyze.scm (goops-toplevel-definition): New
  procedure.
  (report-possibly-unbound-variables): Check for GOOPS top-level
  definitions.

* test-suite/tests/tree-il.test ("warnings")["GOOPS definitions are
  visible"]: New test.
2009-10-22 00:37:36 +02:00
Ludovic Courtès
f67ddf9dbf Add compiler warning for possibly unbound variables.
* module/language/tree-il/analyze.scm (<toplevel-info>): New record
  type.
  (env-module, report-possibly-unbound-variables): New procedures.

* module/language/tree-il/compile-glil.scm (%warning-passes): Add
  `unbound-variable'.

* module/system/base/message.scm (%warning-types): Likewise.

* test-suite/tests/tree-il.test (read-and-compile, %opts-w-unbound):
  New.
  ("warnings")["unbound variable"]: New test prefix.
2009-10-06 23:41:39 +02:00
Andy Wingo
b7946e9ec6 push new frame on stack before procedure & args
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump

* libguile/vm-engine.c (vm_engine): Push a frame corresponding to the
  mv-call.

* libguile/vm-i-system.c: Renumber ops.
  (new-frame): New op, pushes a frame.
  (call, mv-call): No need to shuffle args, though we do need to pop the
  frame in the non-vm call case.
  (goto/args): Inconsequential tweaks.
  (call/cc): Push a frame if needed.

* module/language/tree-il/compile-glil.scm (flatten): Emit `new-frame'
  as appropriate.

* test-suite/tests/tree-il.test: Fix to expect new-frame.
2009-08-20 18:52:50 +02:00
Andy Wingo
aaae0d5ab3 "fix" <let>-bound lambda expressions too
* module/language/tree-il/compile-glil.scm (compile-glil): Compute
  warnings before optimizing, as unreferenced variables will be
  optimized out.

* libguile/_scm.h: Fix C99 comment.

* module/language/tree-il/fix-letrec.scm (partition-vars): Also analyze
  let-bound vars.
  (fix-letrec!): Fix a bug whereby a set! to an unreffed var would be
  called for value, not effect. Also "fix" <let>-bound lambda
  expressions -- really speeds up pmatch.

* test-suite/tests/tree-il.test ("lexical sets", "the or hack"): Update
  to take into account the new optimizations.
2009-08-12 21:29:08 +02:00
Andy Wingo
7382f23e58 add1 and sub1 instructions
* libguile/vm-i-scheme.c: Add add1 and sub1 instructions.
* module/language/tree-il/compile-glil.scm: Compile 1+ and 1- to add1
  and sub1.

* module/language/tree-il/primitives.scm (define-primitive-expander):
  Add support for `if' statements in the consequent.
  (+, -): Compile (- x 1), (+ x 1), and (+ 1 x) to 1- or 1+ as
  appropriate.
  (1-): Remove this one. Seems we forgot 1+ before, but we weren't
  compiling it nicely anyway.

* test-suite/tests/tree-il.test ("void"): Fix expected compilation of (+
  (void) 1) to allow for add1.
2009-08-05 11:55:42 +02:00
Ludovic Courtès
4b856371b3 Add unused variable analysis in the tree-il->glil compiler.
* module/language/tree-il/analyze.scm (<binding-info>): New record type.
  (report-unused-variables): New procedure.

* module/language/tree-il/compile-glil.scm (%warning-passes): New
  variable.
  (compile-glil): Honor `#:warnings' from OPTS.

* test-suite/tests/tree-il.test (call-with-warnings): New procedure.
  (%opts-w-unused): New variable.
  ("warnings"): New test prefix.
2009-07-31 00:49:22 +02:00
Ludovic Courtès
f4aa0f104b Add tree-il-fold', a purely functional iterator on tree-il'.
* module/language/tree-il.scm (tree-il-fold): New procedure.

* test-suite/tests/tree-il.test ("tree-il-fold"): New test prefix.
2009-07-31 00:49:22 +02:00
Andy Wingo
476e357281 remove all mentions of "external" from the compiler and related code
With this, GHIL is effectively bitrotten. I need to port the ECMAScript
compiler to tree-il, then I'll remove it.

* module/language/assembly.scm (byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
  (disassemble-free-vars, code-annotation):
* module/language/glil.scm (<glil-program>, <glil-local>)
  (<glil-exteral>, parse-glil, unparse-glil):
* module/language/glil/compile-assembly.scm (make-meta):
  (compile-assembly, glil->assembly):
* module/language/glil/decompile-assembly.scm (decompile-toplevel):
  (decompile-load-program):
* module/language/objcode/spec.scm (decompile-value):
* module/language/tree-il/compile-glil.scm (flatten-lambda):
* module/system/vm/frame.scm (frame-binding-ref):
  (frame-binding-set!):
* module/system/vm/program.scm (binding:boxed?):
* module/system/vm/trace.scm (trace-next):
* test-suite/tests/asm-to-bytecode.test ("compiler"):
* test-suite/tests/tree-il.test: Remove all mentions of "external", and
  of <glil-local>. Docs updates will come soon.
2009-07-23 17:15:17 +02:00
Andy Wingo
57ab0671d7 rename "closure-ref" to "free-ref"; s/vars/variables/ in some names
* libguile/programs.h:
* libguile/programs.c: (SCM_PROGRAM_FREE_VARIABLES): Rename from
  SCM_PROGRAM_FREE_VARS. Callers changed.
* libguile/programs.c (scm_make_program): Rename arg to
  "free_variables".
  (scm_program_free_variables): Rename from program-free-vars.

* libguile/vm-engine.h:
* libguile/vm-engine.c (VM_CHECK_FREE_VARIABLES): Rename from
  VM_CHECK_CLOSURE.
  (vm_engine, CACHE_PROGRAM): Rename closure and closure_count to free_vars and
  free_vars_vount.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Rename from CLOSURE_REF.
  (free-ref, free-boxed-ref, free-boxed-set): Rename from closure-ref,
  closure-boxed-ref, closure-boxed-set.
  (make-closure): Renamed from make-closure2.

* module/language/glil/compile-assembly.scm (glil->assembly): Hack to
  never write out the the old "make-closure" instruction. Will fix
  better later. Change to emit free-ref etc instead of closure-ref.

* module/language/tree-il/compile-glil.scm (flatten): Emit make-closure
  instead of make-closure2, now that the old make-closure is gone.

* module/system/vm/program.scm (system): Rename program-free-vars to
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update for make-closure.
2009-07-23 17:15:17 +02:00
Andy Wingo
66d3e9a32c compile lexical variable access and closure creation to the new ops
* module/language/glil.scm (<glil>): New GLIL type, <glil-lexical>,
  which will subsume other lexical types.
* module/language/glil/compile-assembly.scm: Compile <glil-lexical>.
  (make-open-binding): Change the interpretation of the second argument
  -- instead of indicating an "external" var, it now indicates a boxed
  var.
  (open-binding): Adapt to new glil-bind format.
* module/language/tree-il/analyze.scm: Add a lot more docs.
  (analyze-lexicals): Change the allocation algorithm and output format
  to allow the tree-il->glil compiler to capture free variables
  appropriately and to reference bound variables in boxes if necessary.
  Amply documented.

* module/language/tree-il/compile-glil.scm (compile-glil): Compile
  lexical variable access to <glil-lexical>. Emit variable capture and
  closure creation code here, instead of leaving that task to the
  GLIL->assembly compiler.

* test-suite/tests/tree-il.test: Update expected code emission.
2009-07-23 17:00:56 +02:00
Neil Jerram
53befeb700 Change Guile license to LGPLv3+
(Not quite finished, the following will be done tomorrow.
   module/srfi/*.scm
   module/rnrs/*.scm
   module/scripts/*.scm
   testsuite/*.scm
   guile-readline/*
)
2009-06-17 00:22:09 +01:00
Andy Wingo
e0c90f9084 fix tree-il test to work if source info happens to be present
* module/language/tree-il/compile-glil.scm (flatten-lambda): Fix source
  emission.

* test-suite/tests/tree-il.test (strip-source): Strip source info on
  tree-il before compiling, so we don't get extraneous source info in the
  glil. Make check passes!
2009-05-22 13:00:23 +02:00
Andy Wingo
0f423f20aa fix apply and call/cc in drop contexts
* module/language/tree-il/compile-glil.scm (flatten): Actually apply only
  needs one arg after the proc. And shit, call/cc and apply in drop
  contexts also need to be able to return arbitrary numbers of values;
  work it by trampolining through their applicative (non-@) definitions.
  Also, simplify the single-valued drop case to avoid the
  truncate-values.

* module/language/tree-il/inline.scm (call/cc):
* module/language/tree-il/optimize.scm (*interesting-primitive-names*):
  Define call/cc as "interesting". Perhaps we should be hashing on value
  and not on variable.

* test-suite/tests/tree-il.test ("application"): Fix up test for new,
  sleeker output. (Actually the GLIL is more verbose, but the assembly is
  better.)
  ("apply", "call/cc"): Add some more tests.
2009-05-21 21:13:24 +02:00
Andy Wingo
30a5e062d0 procedures in "drop" contexts can return unspecified values
* module/language/tree-il/compile-glil.scm (flatten): For applications in
  "drop" context, allow the procedure to return unspecified values
  (including 0 values).

* test-suite/tests/tree-il.test ("application"): Adapt test.

* module/srfi/srfi-18.scm (wrap): Clarify.

* test-suite/tests/srfi-18.test: Fix so that the expression importing
  srfi-18 is expanded before the tests. However the tests are still
  failing, something about 0-valued returns...
2009-05-21 17:22:58 +02:00
Andy Wingo
5af166bda2 don't allocate too many locals for expansions of `or'
* module/language/tree-il/analyze.scm (analyze-lexicals): Add in a hack
  to avoid allocating more locals than necessary for expansions of `or'.
  Documented in the source.

* test-suite/tests/tree-il.test: Add a test case.
2009-05-20 12:46:23 +02:00
Andy Wingo
a1a482e0e9 and, or, cond etc use syntax-rules, compile scheme through tree-il
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
  bound. Used by local-ref and external-ref in paranoid mode.

* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
  switching to use psyntax as the first pass of the compiler, and perhaps
  soon of the interpreter too, we need to make sure it expands out all
  forms to primitive expressions. So define expanders for these derived
  syntax forms, as in the R5RS report.

* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
  expanded.

* module/ice-9/psyntax.scm (build-void): New constructor, for making
  undefined values.
  (build-primref): Add in a hack so that primitive refs in the boot
  module expand out to toplevel refs, not module refs.
  (chi-void): Use build-void.
  (if): Define an expander for if that calls build-conditional.

* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
  so as not to depend on binding order for the result of
  (current-module).

* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
  primary intermediate language. Not yet fully tested, but at least it
  can compile psyntax-pp.scm.

* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
  count towards a function's nlocs.

* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
  Define a "compilation module" fluid.
  (flatten-lambda): Fix a call to make-glil-argument. Fix bug in
  heapifying arguments.
  (flatten): Fix number of arguments passed to apply instruction. Add a
  special case for `(values ...)'. If inlining primitive-refs fails,
  try expanding into toplevel-refs if the comp-module's variable is the
  same as the root variable.

* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
  src variable for <module-ref>.

* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
  closure test case.
2009-05-20 11:15:22 +02:00
Andy Wingo
ce09ee1989 add tree-il->glil compilation test suite
* module/language/tree-il.scm (parse-tree-il): Fix a number of bugs.
  (unparse-tree-il): Apply takes rest args now.

* module/language/tree-il/analyze.scm (analyze-lexicals)
  (analyze-lexicals): Heap vars shouldn't increment the number of locals.

* module/language/tree-il/optimize.scm (resolve-primitives!): Don't
  resolve public refs to primitives, not at the moment anyway.

* test-suite/Makefile.am (SCM_TESTS): Add tree-il test.

* test-suite/lib.scm (pass-if, expect-fail, pass-if-exception)
  (expect-fail-exception): Rewrite as syntax-rules macros. In a very
  amusing turn of events, it turns out that bindings introduced by
  hygienic macros are not visible inside expansions produced by
  defmacros. This seems to be expected, so go ahead and work around the
  problem.

* test-suite/tests/srfi-31.test ("rec special form"): Expand in eval.

* test-suite/tests/syntax.test ("begin"): Do some more expanding in eval,
  though all is not yet well.

* test-suite/tests/tree-il.test: New test suite, for tree-il->glil
  compilation.
2009-05-18 23:45:35 +02:00