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

2484 commits

Author SHA1 Message Date
Ian Price
84a410dbd2 Fix code generated for `while'.
* module/language/lua/compile-tree-il.scm (while-loop->tree-il):
  Generate `letrec' instead of `let'.
  Generate valid `lambda' expression.
2013-09-09 17:03:52 +01:00
Ian Price
b3a7711ba0 Add missing `make-sequence' procedure.
* module/language/lua/compile-tree-il.scm (make-sequence): New procedure.
2013-09-09 17:03:52 +01:00
Ian Price
ced883f7df Use make-application' instead of removed make-call'.
* module/language/lua/compile-tree-il.scm: Rename.
2013-09-09 17:03:52 +01:00
Ian Price
ddb685ee52 Compile Lua's ... form.
* module/language/lua/compile-tree-il.scm (compile): Add clause for
  ast-variable-arguments.
* module/language/lua/parser.scm (define-ast, make-parser): Add
  vararg-gensym field to functions, gensym field to variable-arguments.
  Propagate *vararg-gensym* from functions to variable-arguments.
* test-suite/tests/lua-eval-2.test ("lua-eval"): Check for #nil
2013-09-09 17:01:24 +01:00
Phil
f4c44a3ba7 Add some documentation. Function calls now properly handle multiple
values resulting from a function call as the last argument.

doc/ref/api-languages.texi: Add a small blurb about Lua.

module/language/lua/compile-tree-il.scm: Function calls now properly
handle multiple values resulting from a function call as the last
argument.
2013-09-09 17:01:24 +01:00
Phil
faa16f9989 module/language/lua/parser.scm: Rename #:dots to #:varargs 2013-09-09 17:01:24 +01:00
Phil
becaec9a4e Fix and/or double evaluation. Add math.modf, math.fmod.
* module/language/lua/compile-tree-il.scm: Fix and/or double evaluation.

* module/language/lua/notes.org: Add file describing known issues.

* module/language/lua/parser.scm: (token-type): Recognize and/or.

* module/language/lua/standard/math.scm: Add modf, fmod implementations.

* test-suite/tests/lua-eval-3.test: Add another test file for basic
  language features.
2013-09-09 17:01:24 +01:00
Andy Wingo
8c91ae59f9 lua code returning via normal path
* module/language/lua/compile-tree-il.scm (compile): Get more lua code
  returning via the normal path.
2013-09-09 17:01:24 +01:00
Andy Wingo
3043dc0ef7 lua/runtime tweaks
* module/language/lua/runtime.scm: Various indentation and idiom
  tweaks.
2013-09-09 17:01:24 +01:00
Andy Wingo
04175c7dda lua/lexer tweaks
* module/language/lua/lexer.scm: Some tweaks and reindentations. Remove
  the define/init lexer interface; I don't like separating declaration
  and initialization.

* module/language/lua/parser.scm:
* test-suite/tests/lua-lexer.test: Adapt to lexer interface change.
2013-09-09 17:01:24 +01:00
Andy Wingo
d87639dfe4 lua/compile-tree-il tweaks
* module/language/lua/compile-tree-il.scm: Reflow a bit, and a number of
  small rewrites. Added some FIXMEs.
2013-09-09 17:01:23 +01:00
Andy Wingo
ae037892f0 remove true? and false?; lua's truthiness and falsehood is guile's.
* module/language/lua/runtime.scm (true?, false?): Remove, now that #nil
  is false.

* module/language/lua/compile-tree-il.scm: Don't emit calls to true? or
  false?.
2013-09-09 17:01:23 +01:00
Andy Wingo
48f7c66a40 lua/parser tweaks
* module/language/lua/parser.scm (define-record, define-ast): Simplify
  these macros.
  (make-parser): A number of small idiomatic changes.
2013-09-09 17:01:23 +01:00
Andy Wingo
a0cecd8ff2 lua/common cleanup
* module/language/lua/common.scm: Remove `or-eqv?'. Make a bit more
  idiomatic.

* module/language/lua/compile-tree-il.scm:
* module/language/lua/lexer.scm:
* module/language/lua/parser.scm:
* module/language/lua/runtime.scm: Replace or-eqv? instances with memq
  or memv.
2013-09-09 17:01:23 +01:00
Andy Wingo
32c58e2edd syntax-error throws to syntax-error
* module/language/lua/common.scm (syntax-error): Throw to
  'syntax-error.
2013-09-09 17:01:23 +01:00
No Itisnt
a30c18c22a add lua language implementation
What is missing:

+ Functions: module, getfenv, setfenv, math.modf, table.sort

+ Parser: needs to be more flexible

+ Compiler: needs more extensive work to properly handle all possible
cases of variable arguments, multiple returns, and loops

+ Language: Variable arguments and unpacking of multiple returns. (For
example we need to be able to handle something as complex as
print(unpack({...})), which is easy with Lua's explicit stack but will
require lots of tree-il gymnastics, or perhaps modifications to better
allow different calling conventions. (For instance -- how would we
support Python or Ruby, where keyword arguments are gathered into a
hashtable and passed as a single argument?)

What is there:

A fair shot at supporting Lua 5.1, not quite a drop-in replacement, but
not far from that goal either.
2013-09-09 17:01:23 +01:00
Andy Wingo
8ac8e2dfeb Add contification pass
* module/Makefile.am:
* module/language/cps/contification.scm: New pass.

* module/language/cps/compile-rtl.scm (optimize): Wire it into the
  compiler.
2013-08-31 09:40:56 +02:00
Andy Wingo
6e8ad82335 Add CPS -> RTL compiler
* module/Makefile.am:
* module/language/cps/compile-rtl.scm:
* module/language/cps/dfg.scm:
* module/language/cps/slot-allocation.scm: New modules.

* module/language/cps/spec.scm: Register the compiler.

* test-suite/Makefile.am:
* test-suite/tests/rtl-compilation.test: Add tests.
2013-08-31 09:40:56 +02:00
Andy Wingo
934e6b9515 Add pass to reify primcalls without corresponding VM ops
* module/Makefile.am:
* module/language/cps/reify-primitives.scm: New pass.
2013-08-31 09:40:56 +02:00
Andy Wingo
026b561154 Add arity-adapting module
* module/Makefile.am:
* module/language/cps/arities.scm: New module.  Adapts call and return
  arities, especially for primcalls.
2013-08-31 09:40:56 +02:00
Andy Wingo
045392f1b2 Add CPS primitives info module
* module/Makefile.am:
* module/language/cps/primitives.scm: New file.
2013-08-31 09:40:56 +02:00
Andy Wingo
43f768f48d RTL language
* module/Makefile.am
 * module/language/rtl.scm:
 * module/language/rtl/spec.scm: Add a stub RTL language.
2013-08-31 09:40:56 +02:00
Andy Wingo
4b8de65e9d Add closure conversion
* module/Makefile.am
* module/language/cps/closure-conversion.scm: New module, implementing a
  closure conversion pass.
2013-08-31 09:40:56 +02:00
Andy Wingo
4fefc3a867 (compile foo #:to 'cps)
* module/language/tree-il/compile-cps.scm: New module implementing CPS
  conversion of Tree-IL.

* module/Makefile.am:
* module/language/tree-il/spec.scm:
* module/language/cps/spec.scm: Integrate CPS in the build and language
  system.
2013-08-31 09:40:56 +02:00
Andy Wingo
80b01fd086 Add CPS language
* module/Makefile.am:
* module/language/cps.scm:
* module/language/cps/verify.scm: Add CPS language.

* .dir-locals.el: Add indentation rules for some CPS forms.
2013-08-31 09:40:56 +02:00
Andy Wingo
93009a7aca ,xx for RTL images
* module/scripts/disassemble.scm (disassemble):
* module/system/vm/disassembler.scm (disassemble-file): Factor
  disassemble-file out.

* module/system/repl/command.scm (disassemble-file): Map ,xx to
  disassemble RTL images.
2013-08-29 20:50:19 +02:00
Andy Wingo
610295ec9d add ability to disassemble ELF images
* module/scripts/disassemble.scm (disassemble): Update to work with
  RTl (and only RTL, as that's the future).

* module/system/vm/debug.scm (for-each-elf-symbol): New public
  interface.
  (debug-context-from-image): New helper.
  (find-debug-context): Use the helper.

* module/system/vm/disassembler.scm (disassemble-image): New public
  interface.
2013-08-29 20:44:55 +02:00
Andy Wingo
c96933fd54 Export the assembler procedures
* module/system/vm/assembler.scm (define-assembler):
  (define-macro-assembler): Export the assemblers.
2013-08-24 15:41:09 +02:00
Andy Wingo
70a2043143 RA == MVRA in disassembler
* module/system/vm/disassembler.scm: Modify call disassembler to assume
  RA == MVRA.
2013-08-24 15:38:27 +02:00
Andy Wingo
8fa7288928 assembler: give proper permissions to .data section
* module/system/vm/assembler.scm (link-data): Give stringbufs the
  "shared" flag already, so we don't attempt to set it at runtime.  Give
  .data sections the SHF_WRITE flag.
2013-08-24 15:28:03 +02:00
Andy Wingo
72bb47ae4c compile-file adds #:to-disk? #t to opts
* module/system/base/compile.scm (compile-file): Pass #:to-disk? as an
  option to indicate that the result will be being loaded from disk.
  Perhaps a linker might want to page-align in that case.

* module/language/elisp/compile-tree-il.scm (process-options!): Accept
  and ignore the #:to-file compiler option.
2013-08-24 15:27:57 +02:00
Mark H Weaver
62d3430cb6 Convert branchable primitives into binary operations only.
* module/language/tree-il/primitives.scm (maybe-simplify-to-eq): Wrap
  within another lambda, binding the primitive name.  If there are less
  than two arguments, expand to constant #t.  If there are more than two
  arguments, convert into a conjunction of binary applications.
  (expand-chained-comparisons): New procedure.
  (*primitive-expand-table*): Add entries for (< <= = >= > eq?).
2013-08-24 15:18:32 +02:00
Mark H Weaver
453acfacf4 Merge remote-tracking branch 'origin/stable-2.0' 2013-08-23 22:36:02 -04:00
Mark H Weaver
0ac084bf2b Fix 'define-public' from (ice-9 curried-definitions).
* module/ice-9/curried-definitions.scm (cdefine, cdefine*): Simplify,
  and improve error reporting by making the patterns more strict.
  (define-public): Fix bug in generated 'export' form.
2013-08-23 02:00:08 -04:00
Mark H Weaver
df3acd296e Improve error checking in 'define-public' and 'module-add!'.
* module/ice-9/boot-9.scm (module-add!): Check that the symbol argument
  is actually a symbol.
  (define-public): Expand into 'define' in such a way that curried
  definitions will immediately fail.
2013-08-19 20:02:50 -04:00
Ian Price
20d28792b3 `write-request-line' always prints a path component.
* module/web/http.scm (write-request-line): Always write "/" when path
  is empty, regardless of query.
* test-suite/tests/web-http.test ("write-request-line"): Add test.
2013-08-19 10:43:02 +01:00
Mark H Weaver
521c542199 Merge remote-tracking branch 'origin/stable-2.0' 2013-08-15 04:09:04 -04:00
Mark H Weaver
8d5d0425ce Improve run-time error reporting in (ice-9 match).
* module/Makefile.am: match.go depends on match.upstream.scm.

* module/ice-9/match.scm (error): Accept any number of arguments.

* module/ice-9/match.upstream.scm (match-next): Call 'error' in non-tail
  context, and include the value that failed to match in the call.
2013-08-15 04:07:55 -04:00
Mark H Weaver
79a6c3be6a Merge remote-tracking branch 'origin/stable-2.0' 2013-08-12 21:36:45 -04:00
Mark H Weaver
71673fba93 Common numeric operations are left-to-right associative.
* module/language/tree-il/primitives.scm (define-primitive-expander):
  Use 'match-lambda*' instead of 'case-lambda' for pattern matching.
  (*primitive-expand-table*): In primitive expanders for '+', '*', '-',
  '/', 'logior', and 'logand', assume conventional left-to-right
  associativity.
2013-08-12 20:03:41 -04:00
Mark H Weaver
73b98028f0 Numerical comparisons are not negatable.
* module/language/tree-il/primitives.scm (*negatable-primitives*):
  Remove (< <= > >=) from the list of negatable primitives.
2013-08-12 18:08:59 -04:00
Mark H Weaver
1160e2d94e Merge remote-tracking branch 'origin/stable-2.0' 2013-08-11 22:46:22 -04:00
Mark H Weaver
1e5c32054e Adapt ecmascript compiler to tree-il prompt changes, again.
* module/language/ecmascript/compile-tree-il.scm (with-return-prompt):
  The body of an escape-only prompt is no longer a thunk.  Adapt.
2013-08-11 17:18:09 -04:00
Andy Wingo
af95414f1d Various RTL VM and calling convention tweaks
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Allow for
  five-word instructions, and for new instruction word types.

* libguile/vm-engine.c (RETURN_ONE_VALUE): Instead of returning the
  value in the fixed part of the call frame, return it in the same place
  multiple-value returns go: from slot 1.
  (BR_ARITHMETIC): Allow arithmetic tests to be negated.
  (rtl_vm_engine): Change calling convention to use the same location
  for single and multiple-value returns.  Renumber all instructions.

  (halt, halt/values): Fold into a single instruction (halt).
  (call): Take the location of the procedure instead of the location of
  the call frame.  Also take the number of args, and reset the sp before
  jumping to the procedure, so as to indicate the number of arguments.
  (call/values): Remove, as the new calling convention has RA == MVRA.
  (tail-call): Require the procedure to be shuffled down already, and
  take "nlocals" as an arg instead of "nargs".
  (receive, receive-values): New instructions, for receiving returned
  values from calls.
  (return-values): Rename from return/values.  Remove "values".
  (alloc-frame): Rename from reserve-locals.
  (reset-frame): New instruction.
  (drop-locals): Remove.
  (br-if-=, br-if-<, br-if-<=): Allow these instructions to be
  negatable.
  (br-if->, br-if->=): Remove.  Probably a bad idea, given NaN.
  (box-ref): Don't bother trying to do a reverse lookup -- the
  toplevel-box, module-box, and resolve instructions should handle
  that.
  (resolve): Add arg to check that the variable is bound.
  (toplevel-box, module-box): New instructions, replacing toplevel-ref,
  toplevel-set, module-ref, and module-set.

* libguile/vm.c (rtl_boot_continuation_code, rtl_values_code): Adapt to
  instruction set changes.

* module/Makefile.am: Make the assembler and disassembler dependent on
  vm-operations.h.

* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm: Adapt to instruction changes and
  new instruction word kinds.

* test-suite/tests/rtl.test: Adapt to instruction set changes.
2013-08-11 16:45:31 +02:00
Andy Wingo
99983d544a Inline escape-only prompt bodies in the Tree-IL
* module/language/scheme/decompile-tree-il.scm (do-decompile):
* module/language/tree-il/analyze.scm (analyze-lexicals):
* module/language/tree-il/canonicalize.scm (canonicalize):
* module/language/tree-il/compile-glil.scm (flatten-lambda-case):
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/peval.scm (peval):
* test-suite/tests/peval.test ("partial evaluation"):  Partially revert
  178a40928, so that escape-only prompts explicitly inline their bodies.
2013-08-11 16:45:31 +02:00
Andy Wingo
c1bff87998 remove peval abort-in-tail-position optimization
* module/language/tree-il/peval.scm (peval): Remove abort optimization;
  the CPS compiler will do much better here, and it is complicating
  things in the meantime.
2013-08-11 16:45:31 +02:00
Mark H Weaver
fa102e73c3 Fix numerator and denominator handling of signed zeroes and infinities.
* libguile/numbers.c (scm_numerator, scm_denominator): Handle signed
  zeroes and infinities in accordance with the corresponding R6RS flonum
  procedures.

* module/rnrs/arithmetic/flonums.scm (flnumerator, fldenominator):
  Remove special handling of infinities.

* test-suite/tests/numbers.test (numerator, denominator): Add tests.
  Convert existing tests to use 'pass-if-equal'.

* test-suite/tests/r6rs-arithmetic-flonums.test (flnumerator): Fix
  broken test of (flnumerator -0.0).
2013-08-09 06:09:56 -04:00
Mark H Weaver
d9b312af56 Decompiler: fix handling of empty 'case-lambda' expressions.
* module/language/scheme/decompile-tree-il.scm (choose-output-names):
  A <lambda> with no <lambda-case> decompiles into a 'case-lambda'
  primitive.  Ensure that 'case-lambda' is not shadowed by a lexical.
2013-08-07 05:54:15 -04:00
Mark H Weaver
5270bb5bdb Adapt ecmascript compiler to recent tree-il changes for prompts.
* module/language/ecmascript/compile-tree-il.scm (with-return-prompt):
  Adapt to the changes in 178a40928a.
  Prompt tree-il nodes now contain an explicit 'escape-only?' flag, and
  the body and handler are now both lambdas.
2013-08-07 03:13:11 -04:00
Mark H Weaver
6dce942c46 String ports use UTF-8; ignore %default-port-encoding.
* libguile/strports.c (scm_mkstrport): Use UTF-8; ignore
  %default-port-encoding.  Rename 'str_len' and 'c_pos' to
  'num_bytes' and 'c_byte_pos'.  Interpret 'pos' argument
  as a character index instead of a byte index.

* module/ice-9/boot-9.scm (%cond-expand-features): Add srfi-6 to the
  list of core features.

* module/srfi/srfi-6.scm (open-input-string, open-output-string): Simply
  re-export these, since the core versions are now compliant.

* doc/ref/api-io.texi (String Ports): Remove text that describes
  non-compliant behavior of string ports with regard to encoding.

* doc/ref/srfi-modules.texi (SRFI-0): Add srfi-6 to the list of
  core features.
  (SRFI-6): Remove text that mentions non-compliant behavior of
  core string ports.

* module/ice-9/format.scm (format):
* module/ice-9/pretty-print.scm (truncated-print):
* module/rnrs/io/ports.scm (open-string-input-port,
  open-string-output-port):
* test-suite/test-suite/lib.scm (format-test-name):
* test-suite/tests/chars.test ("combining accent is pretty-printed",
  "combining X is pretty-printed"):
* test-suite/tests/ecmascript.test (eread, eread/1):
* test-suite/tests/rdelim.test:
* test-suite/tests/reader.test (read-string):
* test-suite/tests/regexp.test:
* test-suite/tests/srfi-105.test (read-string): Don't set
  %default-port-encoding before creating string ports.

* benchmark-suite/benchmarks/ports.bm (%latin1-port): Use
  'set-port-encoding!' to set the string port encoding.
  (%utf8/ascii-port, %utf8/wide-port, "rdelim"): Don't set
  %default-port-encoding before creating string ports.

* test-suite/tests/r6rs-ports.test ("lookahead-u8 non-ASCII"): Don't set
  %default-port-encoding before creating string ports.
  ("put-bytevector with UTF-16 string port", "put-bytevector with
  wrong-encoding string port"): Use 'set-port-encoding!' to set the
  string port encoding.

* test-suite/tests/print.test (tprint): Use 'set-port-encoding!' to set
  the string port encoding.
  ("truncated-print"): Use 'pass-if-equal'.

* test-suite/tests/ports.test ("encoding failure leads to exception",
  "%default-port-encoding is honored", "peek-char [latin-1]", "peek-char
  [utf-8]", "peek-char [utf-16]"): Remove tests.
  ("%default-port-encoding is ignored", "peek-char"): Add tests.
  ("suitable encoding [latin-1]", "suitable encoding [latin-3]",
  "wrong encoding, error", "wrong encoding, substitute",
  "wrong encoding, escape"): Use 'set-port-encoding!' to set the
  string port encoding.
  ("%default-port-encoding, wrong encoding"): Rewrite to use
  a file port instead of a string port.
2013-08-07 01:22:22 -04:00