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

4452 commits

Author SHA1 Message Date
Andy Wingo
68776b1d94 parse division vs regexps properly
* module/language/ecmascript/tokenize.scm (make-tokenizer/1): Whoops, fix
  the cases in which we detect that division is valid.
2009-02-22 17:37:59 +01:00
Andy Wingo
e05320fa54 compile for-in
* module/language/ecmascript/base.scm (prop-keys): New method, returns
  the list of keys of props of this instance.

* module/language/ecmascript/impl.scm: Refactor the global object into a
  special kind of module object. Provide a prop-keys implementation for
  module objects.

* module/language/ecmascript/compile-ghil.scm (comp): Compile for-in.

* module/language/ecmascript/impl.scm: Reshuffly things, and implement
  make-enumerator, a helper for use in for-in statements.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix parsing of
  for (var foo in bar) {}...
2009-02-22 16:01:11 +01:00
Andy Wingo
bb67fe27ab fix "for" compilation
* module/language/ecmascript/compile-ghil.scm (comp): Whoops, fix `for'
  compilation.
2009-02-22 12:07:09 +01:00
Andy Wingo
143177ed9e add scheme integration to js via `require'
* module/language/ecmascript/impl.scm: Add <js-module-object>, that wraps
  a module. Add js-require, a javascript-happy function that returns an
  object that wraps a Guile module. Bind it to `require' in the default
  environment.
2009-02-22 11:55:20 +01:00
Andy Wingo
a3e34104db ecmascript tokens have source info
* module/language/ecmascript/tokenize.scm: Attach source information to
  tokens. We have to enhance the lalr parser to actually let this
  information propagate through, though...
2009-02-22 11:37:55 +01:00
Andy Wingo
0b229e81a7 throw SyntaxError on bad syntax
* module/language/ecmascript/parse.scm (syntax-error):
* module/language/ecmascript/tokenize.scm (syntax-error): Throw an error
  on bad syntax.
2009-02-22 11:20:15 +01:00
Andy Wingo
af6c20b731 more arithmetic on non-numbers
* module/language/ecmascript/compile-ghil.scm (comp): Convert to number
  on unary +.

* module/language/ecmascript/impl.scm: Define -, *, /, <, <=, >=, >
  operations on non-numbers.
2009-02-22 11:06:13 +01:00
Andy Wingo
8c306808c2 + for strings, global js object, new Foo() works
* module/language/ecmascript/array.scm (*array-prototype*): Declare the
  constructor.

* module/language/ecmascript/base.scm (pput, pdel): Remove some needless
  checks.
  (new): Move definition of new here, and use the constructor.

* module/language/ecmascript/compile-ghil.scm (compile-ghil): Add a stub
  so that when we load a compiled JS program, we make sure the runtime
  has been booted.

* module/language/ecmascript/function.scm (js-constructor): Export a
  js-constructor method instead of a new method.

* module/language/ecmascript/impl.scm (<js-global-object>): Define a new
  class for the global "this" object, wrapping bindings from the current
  module.
  (init-js-bindings!): Define the dozen or so global properties, in the
  current module.
  (+): Define addition operations for non-numbers. This is efficient
  because the generics are only dispatched if the fast-path fails.
2009-02-22 10:51:49 +01:00
Andy Wingo
aec8febc46 compile ecmascript's parser. yay! instant load-time!
* module/language/ghil/compile-glil.scm (codegen): If there are more than
  255 arguments, make a list and use apply instead of calling directly.

* module/language/Makefile.am: Now we can compile parse.scm. Yay!

* module/language/scheme/compile-ghil.scm: Add a note.

* module/language/ecmascript/compile-ghil.scm: Add a note.
2009-02-21 20:28:29 +01:00
Andy Wingo
594d9d4c48 be smarter about allocating local variables, reusing slots if possible
* module/language/Makefile.am: OK, we can compile compile-ghil.scm now,
  thankfully.

* module/language/ecmascript/compile-ghil.scm (ormatch): New macro, a
  wrapper around pmatch to avoid some of the more egregious
  non-tail recursiveness.
  (comp): Use ormatch.

* module/language/ghil.scm (unparse-ghil): The body of bind and mv-bind
  is a single expression, not a list of expressions.

* module/language/ghil/compile-glil.scm (codegen): Be more clever when
  allocating "local" variables -- if a variable goes out of scope, its
  index can be re-used later.

* module/language/glil.scm (parse-glil, unparse-ghil): The "rest" of a
  mv-bind is a flag, not a list. The "ra" of an mv-call is a label, not a
  GLIL expression.

* module/language/objcode/spec.scm (collapse-locals, decompile-value):
  When decompiling a value, process the bindings list differently.
  Comments in the code.

* module/language/scheme/compile-ghil.scm (define-scheme-translator): Fix
  the generated error procedure.
  (let): Re-indent.
  (letrec): Re-indent.

* module/system/base/syntax.scm (record-case): If the body of a clause is
  null, fill it with the unspecified value.
2009-02-21 20:28:29 +01:00
Andy Wingo
81d677eb12 implement break and continue, work around overly recursive pmatch expansion
* libguile/vm-i-system.c (goto/args): On a tail call to a different
  procedure, init the locals to valid scheme values. Shouldn't matter for
  well-compiled scheme, but inspecting uninitialized locals could give
  garbage, or badly-compiled code could cause a crash.

* module/language/Makefile.am (NOCOMP_SOURCES): For the moment, don't
  compile compile-ghil.scm. I need to fix this.

* module/language/ecmascript/compile-ghil.scm (load-toplevel): Sigh, and
  disable stack checking in the evaluator too. Grr.
  (comp): Implement (unnamed) break and continue.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix var
  statements in `for' -- though it still doesn't work.
2009-02-21 20:28:28 +01:00
Ludovic Courtès
73f4d8d1d2 Add -o'/--output' option to "guile-tools compile".
* module/system/base/compile.scm (compile-file): Add optional
  OUTPUT-FILE argument.

* scripts/compile (fail): New procedure.
  (%options): Add `-o'/`--output' option.
  (compile): Handle `-o'.
2009-02-21 00:38:06 +01:00
Andy Wingo
3bef3ae428 implement do, while, for
* module/language/ecmascript/compile-ghil.scm (comp): Use ghil-bind when
  making temp vars, so that disassembly understands things. Implement do,
  while, and for.

* module/language/ecmascript/parse.scm (parse-ecmascript): Some tweaks.

* module/language/ecmascript/impl.scm (language): Export ->boolean.
2009-02-21 00:33:04 +01:00
Andy Wingo
b358fe6502 implement more operations
* module/language/ecmascript/base.scm: Implement some more robust
  property getters that convert strings to symbols. Implement
  has-property?.

* module/language/ecmascript/compile-ghil.scm (comp): Implement lots more
  mathematical operators. We now do all expressions; on to statements.

* module/language/ecmascript/impl.scm: Define some math helpers. They
  probably need to call ->number on some things.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix a typo.
2009-02-21 00:33:04 +01:00
Andy Wingo
45c10edb74 clean up ++ and -- a little bit
* module/language/ecmascript/compile-ghil.scm (comp): Define let1 and
  begin1 helpers. Use them in pre- and post- increment and decrement.
2009-02-21 00:33:04 +01:00
Andy Wingo
a287987818 implement ++, --, new, delete, void, typeof
* module/language/ecmascript/compile-ghil.scm (@impl): Implement with
  @implv.
  (comp): Implement ++ and -- (pre- and post-). Quite a pain. I'll be
  looking for ways to simplify this notation. Also implement new, delete,
  and void.

* module/language/ecmascript/impl.scm: Implement typeof.
2009-02-21 00:33:04 +01:00
Andy Wingo
785fb107ef handle "this" in ecmascript
* module/language/ecmascript/base.scm:
* module/language/ecmascript/compile-ghil.scm:
* module/language/ecmascript/impl.scm:
* module/language/ecmascript/parse.scm: Compile "method calls" in such a
  way that "this" gets propagated correctly.
2009-02-21 00:33:03 +01:00
Andy Wingo
e80ce73d20 implement more of the standard runtime
* module/language/Makefile.am:
* module/language/ecmascript/impl.scm:
* module/language/ecmascript/array.scm:
* module/language/ecmascript/base.scm:
* module/language/ecmascript/function.scm: Split out the runtime into
  different files. Implement more of the spec's runtime.
2009-02-21 00:33:03 +01:00
Ludovic Courtès
8f4e84855e Fix interpretation of `(ice-9 getopt-long)'.
* module/ice-9/getopt-long.scm (define-one-option-spec-field-accessor,
  define-one-option-spec-field-modifier): Eval-case for `load-toplevel'
  as well so that the interpreter can load this module.
2009-02-20 17:38:32 +01:00
Ludovic Courtès
d39b967642 Fix compilation of `(ice-9 getopt-long)'.
* module/ice-9/getopt-long.scm (option-spec-fields): Enclose in a
  `(load-toplevel compile-toplevel)' `eval-case'.
  (define-one-option-spec-field-accessor,
  define-one-option-spec-field-modifier): Enclose in a
  `compile-toplevel'-only `eval-case'.
2009-02-20 17:12:47 +01:00
Ludovic Courtès
03d6cddc55 Make the `module-defer-observers-mutex' recursive.
* module/ice-9/boot-9.scm (module-defer-observers-mutex): Made
  recursive.  See
  http://lists.gnu.org/archive/html/guile-devel/2009-02/msg00068.html
  for an example where it matters.
2009-02-20 14:23:55 +01:00
Andy Wingo
cdad2166e7 support foo["bar"] in addition to foo.bar
* module/language/ecmascript/parse.scm (parse-ecmascript): And update the
  function declaration forms for the new var syntax.

* module/language/ecmascript/compile-ghil.scm (comp): Support foo["bar"]
  in addition to foo.bar.

* module/language/ecmascript/impl.scm (pget, pput): Some fixes for when
  we get non-symbols -- it can happen, yo. I suppose we should allow for
  non-string keys too..
2009-02-19 17:25:52 +01:00
Andy Wingo
b72880eb17 implement object literals
* module/language/ecmascript/impl.scm:
* module/language/ecmascript/compile-ghil.scm (comp): Object literals.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix some
  object literal parsing.
2009-02-19 17:14:16 +01:00
Andy Wingo
984dce236b var at toplevel works too
* module/language/ecmascript/compile-ghil.scm (comp): Fix the var form at
  toplevel.
2009-02-19 16:59:21 +01:00
Andy Wingo
7fb4230060 property gets and puts implemented, yays
* module/language/ecmascript/compile-ghil.scm (@impl): Ok, don't recurse
  on args here.
  (comp): Implement property gets and puts and lexical assignment.
  (comp-body): Fix scanning of var forms.

* module/language/ecmascript/impl.scm (prop-attrs): Allow for the prop
  attr array to be #f.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix assignment
  parsing.
2009-02-19 16:40:22 +01:00
Andy Wingo
10e1bd278f add array support
* module/language/ecmascript/compile-ghil.scm (@impl): Whoops, fix this
  macro.
  (comp): Handle array literals.

* module/language/ecmascript/impl.scm: Add support for arrays.
2009-02-19 16:09:00 +01:00
Andy Wingo
131f7d6c71 further ecmascript work
* libguile/vm-i-system.c (drop, return): Declare drop and return as
  popping one arg from the stack.

* module/language/ghil/compile-glil.scm:
* module/language/glil/compile-assembly.scm (make-meta): Adjust so that
  we declare 'drop and 'return calls as popping one arg from the stack.

* module/language/ecmascript/compile-ghil.scm (comp, comp-body): Flesh
  out a bit more. Most significantly, scoping within functions obeys
  javascript semantics better, modulo bits about with() forms.

* module/language/ecmascript/impl.scm: Define some runtime helper
  routines.
* module/language/Makefile.am (SOURCES): Add impl.scm.

* module/language/ecmascript/parse.scm (parse-ecmascript): Minor tweaks.

* module/language/ecmascript/tokenize.scm (read-identifier): Identifiers
  now read as symbols, not strings.
2009-02-19 13:55:55 +01:00
Andy Wingo
8fa6886d7a add more ecmascript compilation -- functions work now
* module/language/ecmascript/parse.scm (parse-ecmascript): Lambdas always
  just have one member in their bodies.

* module/language/ecmascript/compile-ghil.scm (comp): Add some more silly
  compilers.
2009-02-18 01:18:18 +01:00
Ludovic Courtès
b912a1cd6b Add `load-unsigned-integer' instruction.
* libguile/vm-i-loader.c (load_unsigned_integer): New loader.

* module/language/assembly.scm (byte-length): Handle
  `load-unsigned-integer'.

* module/language/assembly/compile-bytecode.scm (write-bytecode):
  Likewise.

* module/language/glil/compile-assembly.scm (dump-object): Emit a
  `load-unsigned-integer' instruction for positive integers.  This fixes
  loading of integers greater than 2^31 - 1.

* testsuite/Makefile.am (vm_test_files): Add `t-literal-integers.scm'.

* doc/ref/vm.texi (Loading Instructions): Add `load-unsigned-integer'.
2009-02-18 00:54:05 +01:00
Andy Wingo
4e29767187 world's stupidest ecmascript compiler
* module/language/ecmascript/spec.scm: Add language spec for ecmascript.

* module/language/ecmascript/compile-ghil.scm: Add a stupid compiler.

* module/language/Makefile.am: Buildage.
2009-02-18 00:49:21 +01:00
Andy Wingo
5dcd3e4801 add ecmascript parser
* module/language/ecmascript/parse-lalr.scm: Add the Boucher/Bison lalr
  parser. This is from guile-lib, but with : changed to -> so as not to
  molest `prefix' keywords. Should probably be elsewhere.

* module/language/ecmascript/parse.scm: Add parser for ECMAScript. Rules
  from the spec, 3rd edition.

* module/language/ecmascript/tokenize.scm: Add ECMAScript tokenizer,
  hand-written. Neat stuff.

* module/language/Makefile.am: Autofoo.
2009-02-18 00:07:51 +01:00
Andy Wingo
3928db0087 lengths written out in native endianness
* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
  out the lengths that are mapped to struct scm_objcode using native
  endianness.
2009-02-17 23:32:39 +01:00
Andy Wingo
1005628ab5 better alignment
* module/language/assembly.scm (align-program): Whoops, align programs
  properly.

* module/language/glil/compile-assembly.scm (compile-assembly): Start
  with addr=-1, for the unserialized load-program byte.
  (glil->assembly): Align programs in all cases.
2009-02-14 22:55:26 +01:00
Ludovic Courtès
b96dac4d0e Change `compiled-file-name' to preserve the input file's directory.
* module/system/base/compile.scm (compiled-file-name): Prepend "(dirname
  file)" so that "guile-tools compile foo/bar.scm" produces
  "foo/bar.go", not "bar.go".
2009-02-14 22:17:47 +01:00
Andy Wingo
2cf1705c72 align programs on 8-byte boundaries
* module/language/assembly.scm (addr+): New helper.
  (align-program): New function, aligns a (load-program) form, currently
  to 8-byte boundaries.

* module/language/glil/compile-assembly.scm (<subprogram>): Record the
  object table and the program code separately, so that we can align the
  program after the object table has been written.
  (glil->assembly): Use addr+.
  (dump-object): Rework to fold `addr' through dumping of compound
  objects, so that procedures can be aligned properly.
2009-02-14 19:50:44 +01:00
Andy Wingo
194566b0ec re-enable assembly packing
* module/language/glil/compile-assembly.scm (glil->assembly): Enable
  assembly packing, for e.g. (make-int8:0).
2009-02-14 19:00:57 +01:00
Andy Wingo
81600208f4 a slight add-method speedup
* module/oop/goops.scm (add-method-in-classes!): Use memq instead of
  memv.
2009-02-14 00:47:56 +01:00
Andy Wingo
abd6af11cd generate the fixed-offset accessors at compile-time
* module/language/scheme/compile-ghil.scm (define-scheme-translator):
  Only add an else clause if the transformer didn't have one.

* module/oop/goops.scm (min-fixnum, max-fixnum): Define at compile-time
  as well.
  (@slot-ref, @slot-set!): Only define transformers for these at
  compile-time. Avoids loading up the compiler unnecessarily. Also, allow
  for the `n' to be determined lexically, in which case we dispatch to
  the primitive.
  (num-standard-pre-cache, define-standard-accessor-method)
  (bound-check-get, standard-get, standard-set): Rework the fixed-offset
  getters and setters so that they can be computed at compile-time.
  Accessors to fields with n > num-standard-pre-cache will be dispatched
  to the primitive instead of within the VM.
2009-02-14 00:24:32 +01:00
Andy Wingo
e177058bc4 don't re-enter the compiler during method dispatch
* libguile/goops.c (scm_make): In the pre-inst `make', default
  `procedure' to #f, and read a `make-procedure' instead of
  `compile-env'.

* libguile/goops.h (scm_si_make_procedure): This instead of
  scm_si_compile_env.

* module/oop/goops.scm (make-method): Remove this unused function. Users
  should use (make <method> ...) directly.
  (method): Capture `make-procedure' instead of `procedure' in the case
  that the body calls a next-method. Allows for the kind of
  "recompilation" that we were using before, but with closures instead of
  re-entering the compiler. Type-specific compilation is still
  interesting, but probably should be implemented in another way.
  (initialize): Default #:procedure to #f, and
  s/compile-env/make-procedure/.

* module/oop/goops/compile.scm (code-table-lookup): Just return the
  cmethod, not the entry -- since the entry is now just (append types
  cmethod).
  (compile-make-procedure): New procedure, returns a form that, when
  evaluated/compiled, will yield a procedure of one argument, the
  next-method. When called with a next-method, the procedure returns an
  actual method implementation. compile-make-procedure returns #f if the
  body doesn't call next-method.
  (compile-method): Unify to always return procedures. Much cleaner and
  *much* faster in the compiled case. In the interpreted case, there
  might be a slight slowdown, but if there is one it should be slight.

* module/oop/goops/dispatch.scm (method-cache-install!): Adapt to removal
  of compute-entry-with-cmethod.
2009-02-13 23:30:20 +01:00
Andy Wingo
5a0df7be5f flush output when writing .go files
* module/system/base/compile.scm (call-with-output-file/atomic): Close
  the port we are writing to before renaming it, so that we flush output.
  Might fix some 0-length write errors that Jao was seeing.
2009-02-13 21:48:56 +01:00
Andy Wingo
34898db352 inline record predicates into record-case
* module/system/base/syntax.scm (record-case): Inline record predicates
  into the record-case. Shaves off a few more milliseconds from a GOOPS
  load.
2009-02-13 00:16:44 +01:00
Andy Wingo
d9d671f76e no keyword arguments in GHIL / GLIL, just optional args -- faster compiles
* module/system/base/syntax.scm (define-record): So, in the generated
  constructors, allow optional arguments, but not keyword arguments.
  Conses much less in the constructors.
  (define-record/keywords): And the old define-record is here.

* module/language/ghil.scm (parse-ghil):
* module/language/ghil/compile-glil.scm (codegen):
* module/language/scheme/compile-ghil.scm (translate-1, quote)
  (quasiquote): Don't use keywords in this compiler hotpath.

* module/system/base/language.scm (<language>):
* module/system/repl/common.scm (<repl>):
* module/system/vm/debug.scm (<debugger>): Use define-record/keywords.
2009-02-13 00:01:47 +01:00
Andy Wingo
e14679bd52 speed up record-case
* module/language/ghil.scm: Whoops, export some unquote-splicing
  accessors that we didn't have exported before.

* module/system/base/syntax.scm: Speed up record-case, by syntactically
  determining the predicates and accessors. Nasty, in a way; but also
  much faster.
2009-02-11 22:08:04 +01:00
Andy Wingo
8899057d65 match bare literals with eq? in pmatch, not equal?
* module/system/base/pmatch.scm (ppat): Match atoms with eq?, not equal?.
  This speeds up compilation considerably, as we never match against
  numbers or strings or what-have-you. Note, you can match against
  literals with equal? via quoting the literal in the pattern.
2009-02-10 13:18:36 +01:00
Andy Wingo
028e3d0666 propagate much more source info through compilation
* module/language/ghil/compile-glil.scm (codegen): Record source location
  for offset 0 into a lambda, if we can.

* module/language/scheme/compile-ghil.scm (translate-1)
  (define-scheme-translator): In the retrans procedures, propagate the
  location information from the enclosing expression if the subexpression
  has no location information. Gives source information to many more
  expressions.
  (location): Just propagate the source properties as they are, the
  glil->assembly compiler will interpret them.

* module/language/glil.scm (<glil>): Change glil-source to take "props"
  and not "loc", as it's the source properties that we're interested in.

* module/language/glil/compile-assembly.scm (limn-sources): New function,
  takes a list of addr-source property pairs and "compresses" them for
  serialization to disk.
  (glil->assembly): Limn the sources before writing them to disk. Avoid
  non-tail recursion when determining total byte length of code.

* module/system/vm/program.scm (source:file, source:line, source:column):
  Update for new source representation.
  (program-source): Export.
  (write-program): Nicer pretty-printing of anonymous procedures.

* libguile/backtrace.c (display_backtrace_get_file_line): Update for the
  new VM source representation.

* libguile/programs.h:
* libguile/programs.c (scm_program_sources): Update for the new
  serialized source representation, where the filename is not in the
  stream unless it changes.
  (scm_program_source): New exported function, looks up the source for a
  given ip offset.
  (scm_c_program_source): Update to return the last source information
  that was <= the given IP, because we only serialize source info when it
  changes.
2009-02-10 11:53:23 +01:00
Andy Wingo
dae318a631 nicety in the compiler
* module/language/scheme/compile-ghil.scm (lookup-transformer): Use @@.
  Delightfully metacircular.
2009-02-09 12:02:04 +01:00
Andy Wingo
277f728b14 allow defmacros to unquote in macros into expanded expressions
* module/language/scheme/compile-ghil.scm (lookup-transformer): Allow
  macros to be unquoted into the car of any form that results from macro
  expansion. This lets modules export defmacros built on other defmacros
  that are not exported.
2009-02-09 11:50:58 +01:00
Andy Wingo
9892287960 minor cleanups
* libguile/stacks.c (scm_make_stack): Instead of aborting when we misread
  the number of stack frames, just print a warning. I'd like to figure
  out what these cases are, exactly.

* module/language/scheme/compile-ghil.scm (lambda): Reindent the lambda
  transformer.

* module/system/base/compile.scm (call-with-compile-error-catch): Write
  the expression instead of displaying it.
  (call-with-output-file/atomic): Don't actually redirect output to this
  port, as it's not necessary -- the language-printer should respect the
  port that we pass.
2009-02-09 11:42:27 +01:00
Andy Wingo
af35fc20a6 use append-map in goops
* module/oop/goops.scm (ensure-metaclass, make-extended-generic): Some
  minor optimizations to use append-map.
2009-02-05 00:31:38 +01:00
Andy Wingo
ef7e18683c inline dispatch to program cmethods, tick in return, remove old goops methods
* libguile/objects.c (scm_apply_generic): Inline the case when the
  generic is a program.

* libguile/vm-i-system.c (return): Tick when functions return.

* module/oop/goops.scm (object-eqv?, object-equal?): Remove these
  historical methods.
2009-02-03 21:13:01 +01:00