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

237 commits

Author SHA1 Message Date
Andy Wingo
8a73a6d294 rename sc-expand to macroexpand
* module/ice-9/boot-9.scm (macroexpand): Rename from sc-expand.
  (%pre-modules-transformer): Adapt to name change.
* module/ice-9/compile-psyntax.scm: Adapt to name change.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/psyntax.scm: Rename sc-expand to macroexpand.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Adapt to
  name change.
2010-03-19 15:22:27 +01:00
Andy Wingo
54096be752 psyntax expander tracks changes to current module in top-level begin
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/ice-9/psyntax.scm (chi-top-sequence): Track changes to the
  current module. Allows e.g. top-level `define-module' within a begin
  to work.

* test-suite/tests/syncase.test ("changes to expansion environment"):
  Enable test.
2010-03-03 23:09:08 +01:00
Andy Wingo
bcbbba866b re-expand psyntax-pp
* module/ice-9/psyntax-pp.scm: Expand again so we actually use
  with-fluids.
2010-02-19 12:10:11 +01:00
Andy Wingo
6360c1d4c1 psyntax support for with-fluids
* module/ice-9/psyntax.scm (build-dynlet, with-fluids): Use psyntax to
  recognize `with-fluids' as a core form, producing <dynlet> if we are
  compiling.
  (sc-expand): To spice up the mix, use with-fluids here in the
  implementation.

* module/ice-9/psyntax-pp.scm: Bootstrapped twice (!).

* module/ice-9/boot-9.scm: Remove with-fluids definition, it's in the
  core now.
2010-02-18 22:46:31 +01:00
Andy Wingo
64fa96ef28 allow (define* SYM VAL)
* module/ice-9/psyntax.scm (define*): Allow (define* SYM VAL), as 1.8
  did. Thanks to Patrick McCarty for the report.
2010-01-11 22:08:07 +01:00
Andy Wingo
e809758a7e clean up macros.[ch]
There are some incompatible changes here, but only to interfaces that
were introduced earlier in 1.9, or interfaces which have been broken
since early in 1.9.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump, as the macro
  changes affect the interface that is called by psyntax-generated macro
  definitions.

* libguile/inline.h (scm_words): New function, allocates a variable
  number of contiguous scm_t_bits locations, with a given value in the
  0th word, and 0 in the rest of the words.

* libguile/macros.h: Rework interface to correspond more closely, and
  minimally, to the needs of memoize.c and psyntax.
  (SCM_ASSYNT, SCM_MACRO_TYPE_BITS, SCM_MACRO_TYPE_MASK)
  (SCM_F_MACRO_EXTENDED, SCM_MACROP, SCM_MACRO_TYPE)
  (SCM_MACRO_IS_EXTENDED, SCM_BUILTIN_MACRO_P, SCM_SYNCASE_MACRO_P)
  (SCM_MACRO_CODE, scm_tc16_macro): Remove CPP macros related to the
  representation of Scheme macros.
  (scm_i_make_primitive_macro): Renamed from scm_i_makbimacro.
  (scm_i_macro_primitive): New accessor so that memoize.c can get to the
  primitive syntax transformer.
  (scm_make_syncase_macro, scm_make_extended_syncase_macro)
  (scm_syncase_macro_type, scm_syncase_macro_binding): Removed these
  functions, replaced by make-syntax-transformer and its accessors.
  (scm_macro_binding): New accessor, the same as what
  scm_syncase_macro_binding was.

* libguile/macros.c: All representation details of syntax transformers
  are private to this file now.
  (macro_print): Print macros as #<syntax-transformer ...>, or
  #<primitive-syntax-transformer ...> if psyntax has not attached a
  transformer of its own.
  (scm_i_make_primitive_macro): Represent macros as 5-word smobs.
  (scm_make_syntax_transformer): New constructor for syntax transformers
  (macros), exported to scheme. Takes a name, and looks it up in the
  current module to determine the previous primitive transformer, if
  any.
  (scm_macro_type): Instead of returning 'builtin-macro!, etc, return
  the type as set by psyntax, or #f if it's a primitive.
  (scm_macro_name): Return the stored macro name.
  (scm_macro_transformer): Return the psyntax-set syntax transformer.
  Hacky, but should help introspection somewhat.

* libguile/memoize.c (memoize_env_ref_transformer): Use the new
  scm_i_macro_primitive, and adapt to other macro API changes.

* module/ice-9/psyntax.scm (put-global-definition-hook)
  (get-global-definition-hook, chi-install-global): Call (and generate
  calls to) the new macro constructors and accessors.

* module/ice-9/psyntax-pp.scm: Doubly regenerated.

* module/ice-9/debugging/traps.scm (trap-here): Comment out this
  definition and export, while it's not working.
2010-01-05 15:33:46 +01:00
Andy Wingo
f6a8e79197 keyword arg errors throw to 'keyword-argument-error
* libguile/vm-engine.c (VM_NAME): Keyword arg errors are now thrown to
  'keyword-argument-error.

* libguile/vm.c: Define sym_keyword_argument_error, and statically
  allocate some other symbols.

* module/ice-9/optargs.scm (parse-lambda-case): Throw to
  'keyword-argument-error in kwarg error cases.

* module/ice-9/psyntax.scm (build-lambda-case): Remove a couple
  workarounds for the old memoizer. Throw to 'wrong-number-of-args if
  the lambda-case fails to parse.

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

* test-suite/tests/optargs.test: Update expected exceptions.
2009-12-23 22:59:12 +01:00
Andy Wingo
fd5985271f psyntax's labels and marks now unique over a read/write boundary
* module/ice-9/psyntax.scm (gen-label, new-mark): Labels and marks need
  to be unique across read/write boundaries -- it's not sufficient for
  them to simply be unique within a process by virtue of (string #\i)
  constructing a new object. This used to mostly work before, because
  the collapsing of duplicate constants didn't catch many syntax-object
  cases -- but for some reason the attached test case brings out the
  problem. So switch to use gensyms. Potentially more costly, but it's
  what upstream psyntax does now.

  This bug took me fully two days to figure out.

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

* test-suite/tests/syncase.test ("serializable labels and marks"): Add
  test case.
2009-12-20 15:30:32 +01:00
Andreas Rottmann
aa3819aa34 add partial support for tail patterns in syntax-rules/syntax-case
I've prepared a patch that adds partial support for tail patterns.
Things like the the SRFI-34 `guard' macro from [0] are supported, but
you still can't combine dotted patterns with tail patterns, e.g.

(syntax-rules (else)
  ((foo bar ... (else something) . rest)
   <TEMPLATE-HERE>))

will *not* work; there's the issue that one can't just transcribe
the implementation of this feature from the latest version of psyntax,
as I've done for non-dotted tail patterns, as it's implemented using a
dotted pattern like the above. Alas!

[0] <http://article.gmane.org/gmane.lisp.guile.devel/9442>

* module/ice-9/psyntax.scm (syntax-case, $sc-dispatch): Add support for
  tail patterns, transcribed from the latest psyntax.

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

* test-suite/tests/syncase.test: Add tests for tail patterns.
2009-12-11 10:57:29 +01:00
Andy Wingo
5f1611640a really boot primitive-eval from scheme.
* libguile/eval.c (scm_primitive_eval, scm_c_primitive_eval):
  (scm_init_eval): Rework so that scm_primitive_eval always calls out to
  the primitive-eval variable. The previous definition is the default
  value, which is probably overridden by scm_init_eval_in_scheme.

* libguile/init.c (scm_i_init_guile): Move ports and load-path up, so we
  can debug when initing eval. Call scm_init_eval_in_scheme. Awesome.

* libguile/load.h:
* libguile/load.c (scm_init_eval_in_scheme): New procedure, loads up
  ice-9/eval.scm to replace the primitive-eval definition, if everything
  is there and up-to-date.

* libguile/modules.c (scm_module_transformer): Export to Scheme, so it's
  there for eval.go.

* module/ice-9/boot-9.scm: No need to define module-transformer.

* module/ice-9/eval.scm (capture-env): Only reference the-root-module if
  modules are booted.
  (primitive-eval): Inline a definition for identity. Throw a more
  standard error for "wrong number of arguments".

* module/ice-9/psyntax.scm (chi-install-global): The macro binding for a
  syncase macro is now a pair: the transformer, and the module that was
  current when the transformer was installed. The latter is used for
  hygiene purposes, replacing the use of procedure-module, which didn't
  work with the interpreter's shared-code closures.
  (chi-macro): Adapt for the binding being a pair, and get the hygiene
  from the cdr.
  (eval-local-transformer): Adapt to new form of macro bindings.

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

* .gitignore: Ignore eval.go.stamp.

* module/Makefile.am: Reorder for fastest serial compilation, now that
  there are no ordering constraints. I did a number of experiments here
  and this seems to be the best; but the bulk of the time is compiling
  psyntax-pp.scm with eval.scm. Not so great.

* libguile/vm-engine.c (vm-engine): Throw a more standard error for
  "wrong type to apply".

* test-suite/tests/gc.test ("gc"): Remove a hack that shouldn't affect
  the new evaluator, and throw in another (gc) for good measure.

* test-suite/tests/goops.test ("defining classes"):
* test-suite/tests/hooks.test (proc1): We can't currently check what the
  arity is of a closure made by eval.scm -- or more accurately all
  closures have 0 required args and no rest args. So punt for now.

* test-suite/tests/syntax.test ("letrec"): The scheme evaluator can't
  check that a variable is unbound, currently; perhaps the full "fixing
  letrec" expansion could fix this. But barring that, punt.
2009-12-03 00:00:38 +01:00
Andy Wingo
b7742c6b71 new evaluator, y'all
* libguile/eval.c: So, ladies & gents, a new evaluator. It's similar to
  the old one, in that we memoize and then evaluate, but in this
  incarnation, memoization of an expression happens before evaluation,
  not lazily as the expression is evaluated. This makes the evaluation
  itself much cleaner, in addition to being threadsafe. In addition,
  since this C evaluator will in the future just serve to bootstrap the
  Scheme evaluator, we don't have to pay much concern for debugging
  conveniences. So the environment is just a list of values, and the
  memoizer pre-computes where it's going to find each individual value
  in the environment.

  Interface changes are commented below, with eval.h.

  (scm_evaluator_traps): No need to reset the debug mode after rnning te
  traps thing. But really, the whole traps system needs some love.

* libguile/memoize.h:
* libguile/memoize.c: New memoizer, which runs before evaluation,
  checking all syntax before evaluation begins. Significantly, no
  debugging information is left for lexical variables, which is not so
  great for interactive debugging; perhaps we should change this to have
  a var list in the future as per the classic interpreters. But it's
  quite fast, and the resulting code is quite good. Also note that it
  doesn't produce ilocs, memoized code is a smob whose type is in the
  first word of the smob itself.

* libguile/eval.h (scm_sym_and, scm_sym_begin, scm_sym_case)
  (scm_sym_cond, scm_sym_define, scm_sym_do, scm_sym_if, scm_sym_lambda)
  (scm_sym_let, scm_sym_letstar, scm_sym_letrec, scm_sym_quote)
  (scm_sym_quasiquote, scm_sym_unquote, scm_sym_uq_splicing, scm_sym_at)
  (scm_sym_atat, scm_sym_atapply, scm_sym_atcall_cc)
  (scm_sym_at_call_with_values, scm_sym_delay, scm_sym_eval_when)
  (scm_sym_arrow, scm_sym_else, scm_sym_apply, scm_sym_set_x)
  (scm_sym_args): Remove public declaration of these symbols.
  (scm_ilookup, scm_lookupcar, scm_eval_car, scm_eval_body)
  (scm_eval_args, scm_i_eval_x, scm_i_eval): Remove public declaration
  of these functions.
  (scm_ceval, scm_deval, scm_ceval_ptr): Remove declarations of these
  deprecated functions.
  (scm_i_print_iloc, scm_i_print_isym, scm_i_unmemocopy_expr)
  (scm_i_unmemocopy_body): Remove declarations of these internal
  functions.
  (scm_primitive_eval_x, scm_eval_x): Redefine as macros for their less
  destructive siblings.

* libguile/Makefile.am: Add memoize.[ch] to the build.

* libguile/debug.h (scm_debug_mode_p, scm_check_entry_p)
  (scm_check_apply_p, scm_check_exit_p, scm_check_memoize_p)
  (scm_debug_eframe_size): Remove these vars that were tied to the old
  evaluator's execution model.
  (SCM_RESET_DEBUG_MODE): Remove, no more need for this.
  (SCM_MEMOIZEDP, SCM_MEMOIZED_EXP, SCM_MEMOIZED_ENV): Remove macros
  referring to old memoized code representation.
  (scm_local_eval, scm_procedure_environment, scm_memoized_environment)
  (scm_make_memoized, scm_memoized_p): Remove functions operating on old
  memoized code representation.
  (scm_memcons, scm_mem_to_proc, scm_proc_to_mem): Remove debug-only
  code for old evaluator.

* libguile/debug.c: Remove code to correspond with debug.h removals.
  (scm_debug_options): No need to set the debug mode or frame limit
  here, as we don't have C stack limits any more. Perhaps this is a bug,
  but as long as we can compile eval.scm, we should be fine.

* libguile/init.c (scm_i_init_guile): Init memoize.c.

* libguile/modules.c (scm_top_level_env, scm_env_top_level)
  (scm_env_module, scm_system_module_env_p): Remove these functions.

* libguile/print.c (iprin1): No more need to handle isyms. Adapt to new
  form of interpreted procedures.

* libguile/procprop.c (scm_i_procedure_arity): Adapt to new form of
  interpreted procedures.

* libguile/procs.c (scm_thunk_p): Adapt to new form of interpreted
  procedures.
* libguile/procs.h (SCM_CLOSURE_FORMALS): Removed, this exists no more.
  (SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS): New
  accessors.

* libguile/srcprop.c (scm_source_properties, scm_source_property)
  (scm_set_source_property_x): Remove special cases for memoized code.

* libguile/stacks.c (read_frame): Remove a source-property case for
  interpreted code.
  (NEXT_FRAME): Remove a case that I don't fully understand, that seems
  to be designed to skip over apply frames. Will be obsolete in the
  futures.
  (read_frames): Default source value for interpreted frames to #f.
  (narrow_stack): Don't pay attention to the system_module thing.

* libguile/tags.h: Remove isyms and ilocs. Whee!

* libguile/validate.h (SCM_VALIDATE_MEMOIZED): Fix to use the new
  MEMOIZED_P formulation.

* module/ice-9/psyntax-pp.scm (do, quasiquote, case): Adapt for these no
  longer being primitive macros.
* module/ice-9/boot-9.scm: Whitespace change, but just a poke to force a
  rebuild due to and/or/cond/... not being primitives any more.

* module/ice-9/deprecated.scm (unmemoize-expr): Deprecate, it's
  unmemoize-expression now.

* test-suite/tests/eval.test ("define set procedure-name"): XFAIL a
  couple of tests here; I don't know what to do about them. I reckon the
  expander should ensure that defined values are named.

* test-suite/tests/chars.test ("basic char handling"): Fix expected
  exception when trying to apply a char.
2009-12-01 21:00:26 +01:00
Andy Wingo
81b30a35f7 expand out named let to letrec in the eval case
* module/ice-9/psyntax.scm: In the eval case, expand out named let to
  letrec.
* module/ice-9/psyntax-pp.scm: Regenerated.
2009-12-01 21:00:23 +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
Andy Wingo
d89fae24f5 add include-from-path
* module/ice-9/psyntax.scm (include-from-path): New syntax. Searches the
  load path for a file, and includes it.
2009-11-14 17:06:40 +01:00
Ludovic Courtès
cdd73a8d69 Fix typos in `psyntax'.
* module/ice-9/psyntax.scm (lambda*-formals): Fix argument count in
  `rest' invocations.
  [pred]: Fix argument count in `syntax->datum' invocation.
2009-11-07 19:19:16 +01:00
Andy Wingo
24bf130fd1 implement #:predicate
will be useful for making e.g. typecase-lambda. Tough to tell though.

* module/ice-9/psyntax.scm (lambda-formals, lambda*-formals): Parse out
  a #:predicate, which goes right before the rest args. The vanilla
  lambda doesn't parse it out of course, but it does return another
  value.
  (chi-lambda-case, lambda*, lambda): Expand and pass the predicate on
  to build-lambda-case.

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

* module/language/tree-il/compile-glil.scm (flatten): Compile a failing
  predicate without an else clause into a call to `error'. Also, fix
  something the compile warnings caught.
2009-10-26 21:20:35 +01:00
Andy Wingo
647117cd35 case-lambda, case-lambda* in psyntax
* module/ice-9/psyntax.scm (case-lambda, case-lambda*): Add
  implementations of these, present in the base environment.

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

* module/srfi/srfi-16.scm (case-lambda): Replace the core's case-lambda
  definition with our own. We're not quite ready to switch yet.
2009-10-25 13:12:27 +01:00
Andy Wingo
c89222f8ce refactor psyntax.scm's treatment of lambda and lambda*
* module/ice-9/psyntax.scm (lambda-formals, chi-simple-lambda)
  (lambda*-formals, chi-lambda-case): Refactor the lambda
  transformations with an eye to being able to do case-lambda.

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

* test-suite/tests/syntax.test: Adapted tests so that the errors we
  expect match what is given by psyntax.
2009-10-25 12:36:44 +01:00
Andy Wingo
97bc28b60a define* in psyntax
* module/ice-9/optargs.scm:
* module/ice-9/psyntax-pp.scm:
* module/ice-9/psyntax.scm: Make define* available in the default
  environment, as lambda* is available there.
2009-10-24 16:32:27 +02:00
Andy Wingo
df1cd5e59b lambda* in psyntax
* module/ice-9/psyntax.scm (build-lambda-case): Take an "inits" arg.
  Also work around a nasty memoizer bug: see
  http://article.gmane.org/gmane.lisp.guile.devel/9561.
  (lambda*): Implement in psyntax, in the default environment. Exciting
  stuff!

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

* module/ice-9/optargs.scm (parse-lambda-case): Helper for lambda* when
  we're running under the interpreter.
2009-10-23 16:51:43 +02: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
Julian Graham
416c9fb363 Fix typo in psyntax.scm related to syntax-violation reporting.
* module/ice-9/psyntax.scm (chi-macro): Replace `s' with `(wrap-subst w)'.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2009-10-19 22:44:52 +02:00
Ludovic Courtès
b9434165b6 Allow redefinitions in compiled code as in `(define round round)'.
* module/ice-9/psyntax-pp.scm: Regenerate.

* module/ice-9/psyntax.scm (chi-top)[define-form]: If a same-named
  imported variable exists, take its value instead of `#f'.

* test-suite/tests/compiler.test ("psyntax")["redefinition"]: New tests.
2009-08-13 15:50:37 +02:00
Andy Wingo
d95eb7f49f fix gensym creation in psyntax
* module/ice-9/psyntax.scm (build-lexical-var): Make our gensyms really
  unique. Before, there was a chance that different lexicals could
  result in the same gensym.
* module/ice-9/psyntax-pp.scm: Regenerate.
2009-07-24 12:06:19 +02:00
Andy Wingo
89cb70a0d5 fix source information lossage for (define (foo) ...) lambda sugar
* module/ice-9/psyntax.scm (source-wrap): Use decorate-source, for
  clarity.
  (syntax-type): When turning the RHS of (define (foo) ...) into a
  lambda, decorate the resulting lambda expression with source
  information, as the RHS later goes to chi-expr, which receives no
  source information. Perhaps that is a bug. In any case, fixes some
  source location lossage, reported by Jao.

* module/ice-9/psyntax-pp.scm: Regenerated.
2009-06-20 12:41:11 +02:00
Andy Wingo
fc5b616b58 source information for the interpreter
* module/ice-9/psyntax.scm: Try to propagate source information when
  generating output for the interpreter.

* module/ice-9/psyntax-pp.scm: Regenerate.
2009-06-20 10:47:37 +02:00
Andy Wingo
65dd9e3846 pretty-print psyntax-pp.scm
* module/ice-9/compile-psyntax.scm: Pretty-print psyntax-pp.scm, given
  that we are going to compile it anyway.

* module/ice-9/psyntax-pp.scm: Regenerated.
2009-06-08 22:44:01 +02:00
Andy Wingo
55dce020bd fix bootstrapping after last night's psyntax patch
* module/Makefile.am (ice-9/psyntax-pp.scm): Don't try autocompiling when
  making psyntax-pp.scm.

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

* module/ice-9/psyntax.scm (chi-top): Only affect the compile-time
  environment if modules have booted.
2009-06-08 01:04:16 +02:00
Andy Wingo
c0ee32452f fix incorrect inlining of + when + is locally redefined
* libguile/vm-i-scheme.c (FUNC2): Use a signed value for the intermediate
  result here. Not sure what the effect is, though.

* module/ice-9/psyntax.scm (chi-top): Toplevel definitions ensure that
  variables are defined in the current module. Fixes the specific case of
  guile-lib's md5.scm, which redefines + -- this code is needed so that
  we don't incorrectly open-code +.

* module/language/tree-il/primitives.scm (resolve-primitives!): I think
  there were some cases in which vars and names would not resolve
  properly here. Fix those.
2009-06-07 00:53:48 +02:00
Andy Wingo
a23c940b71 support ((@ ...) ...) where the car is a macro
* module/ice-9/psyntax.scm (syntax-type): Remove `external-macro', not
  used any more. Take an extra arg, `for-car?', indicating that we're
  checking on the type of a form in the car position. In the case that
  the expression is a pair, do a full recursion on the car, which allows
  us to catch the fact that the car of the following form is a macro:
     ((@ (ice-9 optargs) let-optional) ...)
  and thus the form itself should be macroexpanded.

  But, since we want to distingush `lambda' from `(lambda ...)', just as
  we have global and global-call, we have core to the new `core-form'.

  (chi-top, chi, chi-expr, chi-body, set!): Adapt to changes to
  syntax-type.
2009-06-06 00:30:05 +02:00
Andy Wingo
0e7b72a8fe source location tracking in psyntax, booya!
* module/ice-9/psyntax.scm (source-annotation): Return #f if
  source-properties returns null.
  (source-wrap): Rework a bit.
  (syntax-type): Don't throw away source info for wrapped expressions.
  Can has source location info, fools!
  (chi-body): Correctly propagate source info for body subforms.
  (syntax): Remove special case for map, it doesn't apply (ahem) for
  Guile.

* module/ice-9/psyntax-pp.scm: Regenerate.
2009-05-22 21:12:42 +02:00
Andy Wingo
b40d023067 remove annotations in psyntax in favor of guile's source properties
* module/ice-9/psyntax.scm: Remove references to annotation objects,
  we're just going to try and use Guile's source properties now. It works
  until `syntax' reconstructs output, at which point it seems we lose it.

* module/ice-9/psyntax-pp.scm: Regenerated.
2009-05-22 19:48:14 +02:00
Andy Wingo
39a2eca2ce fix problem naming internal definitions
* module/ice-9/psyntax.scm (chi-body): Fix a problem introduced in
  dc1eed52f7, that internal syntax definitions were included in the id
  lis along with value definitions. Only showed up on a second bootstrap.
  Psyntax, how I love thee.

* module/ice-9/psyntax-pp.scm
2009-05-22 19:26:58 +02:00
Andy Wingo
dc1eed52f7 residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
  from the SRFI itself. Yuk.
  (%print-module, make-modules-in, %app, (%app modules))
  (module-name): Syncase needs to get at the names of modules, even at
  anonymous modules. So lazily assign gensyms as module names. Name %app
  as (%app), but since (%app modules) is at the top of the module
  hierarchy, name it ().

* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
  definitions and in lets.
  (let, letrec): Give more specific errors in a couple of cases.

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

* test-suite/tests/syntax.test: More work. Many exceptions have different
  messages than they used to, many more generic; we can roll this back to
  be faithful to the original strings, but it doesn't seem necessary to
  me.
2009-05-22 12:08:50 +02:00
Andy Wingo
0260421208 some work on syntax.test
* module/language/tree-il.scm (tree-il->scheme):
* module/ice-9/psyntax.scm (build-conditional): Attempt to not generate
  (if #f #f) as the second arm of an if, but it doesn't seem to be
  successful.

* module/ice-9/psyntax-pp.scm (syntax-rules): Regenerate.

* test-suite/tests/syntax.test (exception:unexpected-syntax): Change
  capitalization.
  ("unquote-splicing"): Update test.
  ("begin"): Add in second arms on these ifs, to avoid the strange though
  harmless expansion of `if'.
  (matches?): New helper macro.
  ("lambda"): Match on lexically bound symbols, as they will be
  alpha-renamed.
2009-05-21 22:43:07 +02:00
Andy Wingo
40b36cfbbe catch syntax errors in unquote and unquote-splicing
* module/ice-9/psyntax.scm (quasiquote): Catch syntax errors in unquote
  and unquote-splicing.

* module/ice-9/psytax-pp.scm: Regenerated.
2009-05-21 22:11:48 +02:00
Andy Wingo
8bb0b3cc9d fix failing macro-as-parameter tests in eval.test
* module/ice-9/psyntax.scm (chi-lambda-clause): Strip the docstring
  before passing it on to the continuation.

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

* test-suite/tests/eval.test (exception:failed-match): New exception, for
  syntax-case failed matches.
  ("evaluator"): Fix macro-as-parameter tests. They pass now :)
2009-05-20 18:11:23 +02:00
Andy Wingo
e32a1792de a few fixups
* module/ice-9/psyntax.scm (chi-install-global, syntax-case): Fix a
  couple of cases in which bare datums were passed to output
  constructors.

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

* module/language/scheme/spec.scm (scheme): Clean up the #:compilers
  list.

* module/language/tree-il/compile-glil.scm (flatten): Fix call to
  `length' in call/cc compiler.
2009-05-20 11:59:41 +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
1eec95f8de define `delay' in terms of make-promise
* module/ice-9/boot-9.scm (delay): Define `delay' in terms of
  make-promise.

* module/ice-9/psyntax-pp.scm (compile): Regenerated with a fully
  compiled Guile, so that the gensym numbers are the same.

* module/language/tree-il/compile-glil.scm: Add some notes about what
  needs doing to catch up to the old compiler.
2009-05-17 18:04:36 +02:00
Andy Wingo
696495f4d2 actually pass original ids on to tree-il data types
* module/ice-9/psyntax.scm (build-lambda, build-let, build-named-let)
  (build-letrec): Actually pass along the original ids to tree-il
  constructors.

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

* module/language/tree-il.scm: Add fields in <lambda>, <let>, and
  <letrec> for the original variable names.

* module/language/tree-il/compile-glil.scm (compile-glil): Adapt for new
  make-lambda arg.
2009-05-17 16:39:55 +02:00
Andy Wingo
547a602d1e preserve original var names in lets and lambdas
* module/ice-9/psyntax.scm (build-letrec, build-let, build-lambda)
  (build-named-let): Take extra args for the original names of the
  gensyms. Not used yet. Callers adapted.

* module/ice-9/psyntax-pp.scm: Regenerated.
2009-05-17 16:27:18 +02:00
Andy Wingo
06656e06d4 go ahead and regenerate psyntax-pp.scm 2009-05-07 17:44:51 +02:00
Andy Wingo
811d10f5a2 new language: tree-il. psyntax generates it when run in compile mode.
* module/Makefile.am: Add tree-il sources.

* module/ice-9/compile-psyntax.scm: Adjust for sc-expand producing
  tree-il in compile mode.

* module/ice-9/psyntax.scm: Switch from expand-support to tree-il for
  generating output in compile mode. Completely generate tree-il -- the
  output wasn't Scheme before, but now it's completely not Scheme.

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

* module/language/scheme/compile-ghil.scm: Strip structures using
  tree-il, not expand-support.

* module/language/tree-il.scm:
* module/language/tree-il/spec.scm
* module/language/tree-il/compile-glil.scm: New language. It will compile
  to GLIL, though it doesn't yet.
2009-05-07 17:32:01 +02:00
Andy Wingo
1aeb082b82 make expand-support structure constructors take a source argument
* module/ice-9/expand-support.scm (make-module-ref, make-lexical): Add
  source arguments to these constructors.

* module/ice-9/psyntax.scm:
* module/ice-9/psyntax-pp.scm: Adapt to match, though we don't wire
  everything up yet.
2009-05-07 11:02:10 +02:00
Andy Wingo
f27e9e11cd fix install-global construction of `define' forms
* module/ice-9/psyntax.scm (build-global-definition): Remove mod
  argument, as it does not seem we could ever define something in another
  module.
  (chi-install-global): Build the define as a definition, not an
  application. Doesn't matter now, but it will later.
  (chi-top): Fix build-global-definition call.

* module/ice-9/psyntax.scm: Regenerated.
2009-05-07 10:27:53 +02:00
Andy Wingo
f4a644ee88 when compiling, use make-lexical to residualize original var names
* module/ice-9/psyntax.scm (build-lexical-reference): Change to be a
  function. Take an extra arg, the original name of the variable. If we
  are compiling, make a #<lexical>, annotated with the original var name.
  All callers changed.
  (build-lexical-assignment): Also a function, taking also the original
  var name, using build-lexical-reference to build its output.

* module/ice-9/psyntax-pp.scm: Regenerated.
2009-05-04 12:18:14 +02:00
Andy Wingo
71f46dbd5e sc-expand in compile mode produces (ice-9 expand-support) structures
* module/ice-9/psyntax.scm (*mode*): New moving part, a fluid.
  (sc-expand): Dynamically bind *mode* to the expansion mode.
  (build-global-reference): Change to be a procedure instead of local
  syntax. Import the logic about when to make a @ or @@ form to here,
  from boot-9.scm. If we are compiling, build output using (ice-9
  expand-support)'s make-module-ref, otherwise just making the familiar
  s-expressions. (This will allow us to correctly expand in modules in
  which @ or @@ are not bound, at least when we are compiling.)
  (build-global-assignment): Use the result of build-global-reference. A
  bit hacky, but hey.
  (top-level-eval-hook, local-eval-hook): Strip expansion structures
  before evalling.

* module/ice-9/boot-9.scm (make-module-ref): Remove, this logic is now
  back in psyntax.scm.

* module/ice-9/compile-psyntax.scm (source): Since we expand in compile
  mode, we need to strip expansion structures.

* module/ice-9/expand-support.scm (strip-expansion-structures): Remove
  the logic about whether and how to strip @/@@ from here, as it's part
  of psyntax now.

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

* module/language/scheme/compile-ghil.scm (compile-ghil): Strip expansion
  structures -- for now. In the future, we might translate directly from
  these structures into GHIL.
2009-05-04 11:57:36 +02:00