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

704 commits

Author SHA1 Message Date
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
Andy Wingo
34ed9dfd1f compile-bytecode uses target-endianness
* module/language/assembly/compile-bytecode.scm (compile-bytecode):
  Use target-endianness, from (system base target).
2011-05-31 11:18:28 +02:00
Andy Wingo
8f6a4b248b fix some duplication in object tables
* module/language/glil/compile-assembly.scm (build-object-table): Don't
  add the same value to an object table twice.
2011-05-08 22:55:05 +02:00
Andy Wingo
cb7523c26d compile-assembly: cleanup
* module/language/glil/compile-assembly.scm: Clean up code for
  subprograms (not needed, we just cache the glil) and object alists
  (replaced by constants tables).
2011-05-08 16:38:32 +02:00
Andy Wingo
f5695488b9 compile-assembly: use file-level constants table
* module/language/glil/compile-assembly.scm (compile-assembly): Rework
  to handle toplevel-specific code generation here, instead of in
  glil->assembly.  Specifically, here we build a global constant table,
  and arrange for it to be the objtable of the toplevel thunk.

  (compile-program): New helper, compiles a <glil-program> and returns
  just the (load-program ...) form.

  (compile-objtable): New helper, generates assembly to build an object
  table, using some other constants table, and possibly recursing to
  `compile-program' for cached GLIL programs.

  (glil->assembly): Simplify, removing the toplevel? argument, and
  replacing the object alist with an objtable computed in a previous
  pass.  Adapt to the new form of the objtable, and to use
  compile-program and compile-objtable.
2011-05-08 16:37:47 +02:00
Andy Wingo
7e7b8991b2 compile-assembly: add dump-constants, a new helper
* module/language/glil/compile-assembly.scm (dump-constants): New
  helper.  Generates bytecode that will result in a vector for the
  global object table being pushed on the stack.  The items in the
  global object table will share state as much as possible.
2011-05-08 16:31:18 +02:00
Andy Wingo
57b8eca691 compile-assembly: add build-constant-store, build-object-table
* module/language/glil/compile-assembly.scm (immediate?): New helper.
  (build-constant-store): New helper.  Walks the GLIL tree and builds up
  a constant table, as a vhash.
  (build-object-table): Another helper, builds a constant table for a
  given GLIL program.
2011-05-08 16:15:25 +02:00
Andy Wingo
6994fa9fef compile-assembly: make-meta refactor
* module/language/glil/compile-assembly.scm (make-meta): Avoid going
  through the compiler.
2011-05-08 16:13:41 +02:00
Andy Wingo
55fb5058a8 compile-assembly: add traversal helpers
* module/language/glil/compile-assembly.scm (vhash-fold-right2):
  (fold2, vector-fold2): Add some traversal helpers that we'll use in
  the next commit.
2011-05-08 16:09:22 +02:00
Andy Wingo
89f9dd7065 speed up compile-bytecode
* module/language/assembly/compile-bytecode.scm (compile-bytecode):
  Rewrite to fill a bytevector directly, instead of using bytevector
  ports.  `write-bytecode' itself is still present and almost the same
  as before; it's just that `write-byte' et al now inline the effect of
  writing a byte to a binary port.

* test-suite/tests/asm-to-bytecode.test (comp-test): Refactor to use
  public interfaces.
2011-05-05 11:43:12 +02:00
Andy Wingo
81f529091b silly "optimization" in (language assembly)
* module/language/assembly.scm (byte-length): Silly, minor tweak: put
  the fixed-length instruction case first.  Seems to shave some 10% off
  the time compiling psyntax.scm (when the whole rest of the system is
  compiled, of course).
2011-05-05 11:43:12 +02:00
Andy Wingo
3936cebc77 fix analyze.scm literal string warnings
* module/language/tree-il/analyze.scm (const-fmt): Return any literal
  value, not just strings.  The string case is checked later.
2011-04-14 16:53:18 +02:00
Andy Wingo
56e313894b don't warn about non-literal fmt strings for e.g. (_ "foo")
* module/language/tree-il/analyze.scm (const-fmt, format-analysis):
  Allow format strings to be gettexted, using the conventional _ name.
2011-04-14 16:04:18 +02:00
Andy Wingo
fb6df3ea13 fix error message on ,disassemble "non-procedure"
* module/language/objcode/spec.scm (decompile-value): Don't assume that
  `error' will handle format strings appropriately.
* module/system/repl/command.scm (disassemble): A more human error when
  you disassemble a non-procedure.

Bug reported by Andrew Horton.
2011-03-29 12:38:18 +02:00
Andy Wingo
9dadfa47b0 fix prompt in fix in single-value context compilation
* module/language/tree-il/compile-glil.scm (flatten): When compiling a
  <prompt> in push context with an RA, after the body returns normally,
  jump to that RA instead of to our POST label (which in that case does
  not need to be emitted).  Fixes a tail <prompt> in a push <fix>.

* test-suite/tests/control.test ("prompt in different contexts"): Add
  more test cases.
2011-03-27 15:00:18 +02:00
Andy Wingo
62f528e929 tree-il->scheme fix
* module/language/tree-il.scm (tree-il->scheme): Fix <prompt> to Scheme
  serialization.
2011-03-27 14:44:20 +02:00
Andy Wingo
df12979562 fix-letrec tweaks
* module/language/tree-il/fix-letrec.scm (partition-vars): Previously,
  for letrec* we treated all unreferenced vars as complex, because of
  orderings of effects that could arise in their definitions.  But we
  can actually keep simple and lambda vars as unreferenced, as their
  initializers cannot cause side effects.
  (fix-letrec!): Remove letrec* -> letrec code, as it's unneeded.
2011-03-09 22:38:11 +01: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
1e1808c920 Use vhash-delq' in (language tree-il analyze)'.
* module/language/tree-il/analyze.scm (unbound-variable-analysis): Use
  `vhash-delq' instead of `vhash-delete'.
2011-02-22 00:32:42 +01:00
Andy Wingo
6854c32480 core modules use (ice-9 binary-ports) instead of (rnrs io ports)
* module/language/assembly/compile-bytecode.scm:
* module/language/elisp/lexer.scm:
* module/web/request.scm:
* module/web/response.scm:
* module/web/server.scm:
* module/web/uri.scm: Use ice-9 binary-ports.
2011-02-18 16:01:25 +01:00
Andy Wingo
6c51a40ace read-enable 'positions by default
* libguile/read.c (scm_read_opts): Default "positions" to #t.  The
  compiler was already turning it on anyway, and this allows
  primitive-load without --auto-compile to also propagate source
  information through the expander, for better errors and to let macros
  know their source.

* module/language/scheme/spec.scm: No need to enable positions here
  now.
2011-02-13 15:06:11 +01:00
Andy Wingo
a75ea65896 fix memq/memv inlining
* module/language/tree-il/inline.scm (boolean-value): Add a case for
  applications of primitives, and move the memq/memv->bool code here.
  (inline!): We were inlining (memq 'a '(a b c)) => #t, and not the list
  tail, which was an embarrassing bug.  Fixed by moving this code to the
  boolean-value function.  Thanks to Mark Harig for the report.
2011-02-07 21:58:51 +01:00
Noah Lavine
84816b3aae Parse Decimal Numbers
* module/language/ecmascript/parse.scm: handle numbers with leading
    decimals correctly.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-01-26 23:47:29 +01:00
Noah Lavine
326298206a Fix Hex Constants
* module/language/ecmascript/tokenize.scm: hexadecimal constants can
    now use 'X' in addition to 'x'.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-01-26 23:45:33 +01:00
Noah Lavine
110f652127 Ecmascript Syntax
* module/language/ecmascript/tokenize.scm: an unbreakable space
      counts as whitespace.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-01-26 23:31:12 +01:00
Noah Lavine
eacbe34618 Ecmascript Syntax Fix
* module/language/ecmascript/parse.scm: allow empty function bodies.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-01-26 23:30:44 +01:00
Ludovic Courtès
bc03d89fa2 Remove unexpected non-ASCII character.
* module/language/tree-il/fix-letrec.scm: Replace U+2019 with an ASCII
  quote.  The iconv implementation on FreeBSD would immediately notice
  and bail out when reading it under a US-ASCII locale.
2011-01-23 23:43:50 +01:00
Noah Lavine
b1846b7fb3 Add ECMAScript Unicode literal support
* module/language/ecmascript/tokenize.scm: add unicode literals

* test-suite/tests/ecmascript.test ("parser"): Add new tests for Latin-1
  and Unicode escapes in string literals.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-01-17 23:03:32 +01:00
Ludovic Courtès
8a41c56af1 Tiny style improvement in the ECMAScript compiler.
Followup to 8891bd1b16 ("Fix ECMAScript
object creation.").

* module/language/ecmascript/compile-tree-il.scm (comp): Use `@implv'
  for `new-object'.  Suggested by Kan-Ru Chen <kanru@kanru.info>.
2011-01-05 22:22:15 +01:00
Noah Lavine
8891bd1b16 Fix ECMAScript object creation.
* module/language/ecmascript/compile-tree-il.scm (compile-tree-il):
  generate correct tree-il for construction of new objects.
* test-suite/tests/ecmascript.test (ecompile): Add pattern with EXPECTED
  omitted.
  ("compiler"): test whether we generate new objects correctly.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-01-04 18:36:58 +01:00
Andy Wingo
e01163b5f1 rename make-undefined-fluid to make-unbound-fluid
* libguile/fluids.c (scm_make_unbound_fluid): Rename from
  scm_make_undefined_fluid.

* libguile/fluids.h:
* module/language/elisp/runtime.scm: Update referrers.
2010-12-17 13:10:03 +01:00
Andy Wingo
9582b26c62 add return/values hack to compile-glil for lua
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Add a hack
  like 'return but for multiple values, for lua.
2010-12-10 18:04:06 +01:00
Andy Wingo
84b67e1971 fix self-tail-calls for lexical procs with optional, rest, or kwargs
* module/language/tree-il/compile-glil.scm (flatten-lambda): Don't emit
  a self-label, because when we can't match the args for a lexical call,
  we have no space to shuffle args and jump.
  (flatten): Apply the self-tail-call optimization to optional args
  too, but only if the procedure is fix-allocated. If we can't apply the
  optimization, use the normal tail-call sequence.

* test-suite/tests/optargs.test ("lambda* inits"): Add tests.
2010-12-10 16:07:58 +01:00
Andy Wingo
3b24aee6e3 clarify compile-glil error messages
* module/language/tree-il/compile-glil.scm (vars->bind-list, flatten):
  Make internal self-checking error messages more clear, for
  implementors of other languages.
2010-12-09 21:53:46 +01:00
Brian Templeton
c6920dc8ba lexical function binding for elisp
* module/language/elisp/compile-tree-il.scm (access-variable)
  (reference-variable, set-variable!): Handle globally-bound non-special
  variables.

  (bind-lexically?): Create lexical bindings for flet and flet*.

* module/language/elisp/runtime.scm (reference-variable, set-variable!):
  Handle globally-bound non-special variables.

  (built-in-func): Set the variable directly instead of storing the
  function in a fluid.

* module/language/elisp/runtime/subrs.scm (funcall): Call apply
  directly.

* test-suite/tests/elisp-compiler.test ("Function Definitions")["flet
  and flet*"]:

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:03 +01:00
Brian Templeton
3f70b2dc5c use unbound fluids instead of `void' sentinel value
* module/language/elisp/compile-tree-il.scm (reference-with-check)
  (compile-without-void-checks, want-void-check?): Remove.

  (compile-function, compile-pair): Use `reference-variable' instead of
  `reference-with-check'.

  (compile-defvar): Only set `sym' if `sym' is not bound to a bound
  fluid, rather than requiring that its value be `void'.

  (process-options!): Remove `#:disable-void-check' option handling.

* module/language/elisp/runtime.scm (void)
  (reference-variable-with-check): Remove.

  (ensure-fluid!): Use an undefined fluid as the initial value for
  global variables.

* module/language/elisp/runtime/function-slot.scm (without-void-checks):
  Don't import or re-export.

* module/language/elisp/runtime/macros.scm (prog1, cond, or, dolist):
  Don't use `without-void-checks'.

* module/language/elisp/runtime/subrs.scm (symbol-value)
  (symbol-function, apply): Use `reference-variable' instead of
  `reference-variable-with-check'.

  (makunbound, fmakunbound, boundp, fboundp): Unset the variable's fluid
  (or the variable itself, if it isn't bound to a fluid).

* test-suite/tests/elisp-compiler.test ("Variable
  Setting/Referencing")["disabled void check (all)", "disabled void
  check (symbol list)", "without-void-checks"]: Remove.

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:03 +01:00
Brian Templeton
67cb2c2761 function's argument can be a symbol
* module/language/elisp/compile-tree-il.scm (compile-function): the form
  `(function SYMBOL)' evaluates to the functional value of SYMBOL

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:03 +01:00
Brian Templeton
b41a673d26 allow (setcar nil nil)' and (setcdr nil nil)'
* module/language/elisp/runtime/subrs.scm (setcar, setcdr): Allow
  setting the car or cdr of `nil' to `nil'.

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:03 +01:00
Brian Templeton
b7966c10ef support "#'" syntax for function expressions
* module/language/elisp/lexer.scm (lex):
* module/language/elisp/parser.scm (get-expression): Support sharpsign
  single-quote syntax as an abbreviation for `function' expressions.

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:02 +01:00
Brian Templeton
f5742cf042 setq can take any number of arguments
* module/language/elisp/compile-tree-il.scm (compile-setq): Return nil
  if called with no arguments, and set the last variable to nil if its
  value is omitted.

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:02 +01:00
Brian Templeton
0dbfdeefc6 use correct names for quasiquotation operators
Use #{`}#, #{,}# and #{,@}# as the quasiquote, unquote and
unquote-splicing operators, respectively. Previously they were named
escaping.

* module/language/elisp/compile-tree-il.scm (unquote?): Change "\," to
  "#{,}#".
  (unquote-splicing): Change "\,@" to "#{,@}#".
  (#{compile-`}#): Rename from #{compile-\`}#.
* module/language/elisp/runtime/function-slot.scm: Import #{compile-`}#
  instead of #{compile-\`}#, and re-export as #{`}# instead of as
  #{\`}#.
* module/language/elisp/parser.scm (quotation-symbols):
* test-suite/tests/elisp-compiler.test ("Eval", "Quotation"):
* test-suite/tests/elisp-reader.test ("Parser"): Change "\`", "\,", and
  "\,@" to "#{`}#", "#{,}#" and "#{,@}#", respectively.
2010-12-07 13:21:02 +01:00
Brian Templeton
44ae163d2c store special operators in the function slot
If the function slot of a symbol contains a pair with `special-operator'
in the car and a procedure in the cdr, the procedure is called to
compile the form to Tree-IL. This is similar to other Emacs Lisp
implementations, in which special operators are subrs.

* module/language/elisp/compile-tree-il.scm: Restructured to store
  special operator definitions in the function slot. Import `(language
  elisp runtime)' for `defspecial'. Export special operators so that
  `(language elisp runtime function-slot)' can re-export them.

  (backquote?): Removed; the backquote symbol is defined as a special
  operator, so it's no longer used in `compile-pair'.

  (is-macro?, get-macro): Replaced by `find-operator'.
  (find-operator): New procedure.

  (compile-progn, compile-if, compile-defconst, compile-defvar,
  compile-setq, compile-let, compile-lexical-let, compile-flet,
  compile-let*, compile-lexical-let*, compile-flet*,
  compile-without-void-checks, compile-with-always-lexical,
  compile-guile-ref, compile-guile-primitive, compile-while,
  compile-function, compile-defmacro, compile-defun, #{compile-`}#,
  compile-quote): New special operators with definitions taken from the
  pmatch form in `compile-pair'. There is no special operator `lambda';
  it is now a macro, as in other Elisp implementations.

  (compile-pair): Instead of directly compiling special forms, check for
  a special operator object in the function slot.

* module/language/elisp/runtime.scm: Export `defspecial'.
  (make-id): New function.
  (built-in-macro): Prefix macros with `macro-'.
  (defspecial): New syntax.

* module/language/elisp/runtime/function-slot.scm: Import and re-export
  special operators. Rename imported special operators and macros to
  remove prefixes. Re-export new macro `lambda'.

* module/language/elisp/runtime/macros.scm (macro-lambda): New Elisp
  macro.
2010-12-07 13:21:02 +01:00
Brian Templeton
2ce5e74073 make user-defined macros available at runtime
* module/language/elisp/compile-tree-il.scm (ensuring-globals): New
  procedure.
  (define-macro!): Remove.
  (compile-pair) <defmacro>: Make macro available at runtime, not only
  during compilation.
  (compile-tree-il): Use `ensuring-globals'.
2010-12-07 13:21:02 +01:00
Brian Templeton
65b46b7241 allow fluid macro bindings
* module/language/elisp/compile-tree-il.scm (define-macro!, get-macro):
  Allow fluid macro bindings.
2010-12-07 13:21:02 +01:00
Brian Templeton
9efe5b230d new `load' subr
* module/language/elisp/runtime/subrs.scm: Define new subr `load'.
* module/language/elisp/runtime/function-slot.scm: Re-export `load'.
2010-12-07 13:21:02 +01:00
Brian Templeton
3829919663 Ignore #:warnings compiler option
* module/language/elisp/compile-tree-il.scm (process-options!): Ignore
  #:warnings compiler option.
2010-12-07 13:21:02 +01:00
Brian Templeton
1dfe593954 handle EOF correctly in parser and lexer
* module/language/elisp/lexer.scm (lex, get-lexer/1): Return a valid
  token at EOF.
* module/language/elisp/parser.scm (get-expression): Raise an error if
  EOF is reached.
  (read-elisp): If at EOF, return the EOF object instead of attempting
  to read an expression.

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:02 +01:00
Brian Templeton
8295b7c4e5 store macro definitions in the function slot
Guile Emacs Lisp previously kept macros in a separate macro slot; now
macros are stored as macro objects in the function slot for
compatibility with other implementations.

* module/language/elisp/compile-tree-il.scm (macro-slot): Remove.
  (is-macro?): Check that the argument is a symbol. Now-unnecessary
  check removed in `compile-tree-il'.
  (macro?, define-macro!, get-macro): Store macro definitions in the
  function slot, not in a separate macro slot.
* module/language/elisp/runtime.scm (built-in-macro): Wrap the macro
  function in a macro object (i.e., cons the symbol `macro' onto it).
* module/language/elisp/runtime/function-slot.scm: Move contents to
  "subrs.scm". Re-export function and macro definitions instead of
  defining functions directly in this module.
* module/language/elisp/runtime/macro-slot.scm: Move contents to
  "macros.scm" and remove.
* module/language/elisp/runtime/macros.scm: New file containing macro
  definitions from "macro-slot.scm".
* module/language/elisp/runtime/subrs.scm: New file containing function
  definitions from "function-slot.scm".

Signed-off-by: Andy Wingo <wingo@pobox.com>
2010-12-07 13:21:02 +01:00
Brian Templeton
6e9ebc9179 use existing bindings record for defmacro
* module/language/elisp/compile-tree-il.scm (compile-pair): Use existing
  bindings record during macro definition.
2010-12-07 13:21:02 +01:00