Commit Graph

112 Commits

Author SHA1 Message Date
Jesse D. McDonald 50d9e0e0fc Commit high-level version of existing primitive functions. 2012-07-14 13:45:35 -05:00
Jesse D. McDonald b1add2caf1 Simplify some compiler functions, while tuning for performance. 2012-07-14 13:45:33 -05:00
Jesse D. McDonald 269a512e20 Commit function wrappers for builtin primitive operations. 2012-07-14 13:45:31 -05:00
Jesse D. McDonald a76e86013a Fix loading from relative paths, and output of empty lists.
Also add some basic command-line processing to the front-end.
2012-07-14 13:45:28 -05:00
Jesse D. McDonald 2f67f502f7 Convert cat.rla to high-level language and rename as cat.rls. 2012-07-14 13:45:26 -05:00
Jesse D. McDonald 387ff63a48 Fix some reader-bugs introduced in the conversion to scheme/match. 2012-07-14 13:45:25 -05:00
Jesse D. McDonald cbcea20701 Lots of misc. cleanup, and a few bug fixes.
* Remap all instance variables in one pass, to avoid an insidious bug [1].
* Fix another bug by merging promote-shared-variables and narrow-binds [2].
* Don't assume different variable means different value in propogate-set!.
* Add support for (apply), (value-list) and (call-with-values) forms.
* Add support for including files (as if directly substituted) in reader.
* Use scheme/match library to simplify form pattern-matching.
* Refactor (map-form) and (search-form) using a more basic (traverse-form),
  which just recurses over the form and returns void by default, and a
  new utility function (curry-keywords) to provide default keyword arguments.

[1] Was renaming e.g. %f0 to %i0, then %i0 to %i1, which eliminates the
distinction between %f0 and %i0. Solution is to construct a map from old
names to new names, then traverse the form and change every old variable
to its new equivalent in the map exactly once.

[2] Some variables were not being promoted to boxes, as promotions only occur
at the top-level, when constructing each lambda, and narrow-binds could push
the unpromoted variables down into a subordinate lambda form first. Solution
was to promote variables immediately after narrowing bindings, including the
recursive calls which exist after pushing variables into nested scopes.
2012-07-14 13:45:22 -05:00
Jesse D. McDonald b3fd7bf6fc Adjust initial allocations to improve memory efficiency.
Also convert existing .rls (Rosella Source) files to module syntax.
2012-07-14 13:45:20 -05:00
Jesse D. McDonald 8318db755f Fix module syntax; should be (define ...), not (declare ...). 2012-07-14 13:45:18 -05:00
Jesse D. McDonald 723f52dc1d Rather than a single form, accept an entire module as input.
Module consists of mixed (declare ...) forms and expressions.
Groups of (declare ...) forms become (letrec ...)s surrounding
later expressions and (declare ...) groups.
The (declare (fn-name . arglist) forms...) syntax is supported.
2012-07-14 13:45:10 -05:00
Jesse D. McDonald 4b96515362 Split compiler into separate modules.
Created one module one per pass, plus utilities functions, primitives, and output.
Changed extension to ".scm" for compatibility with hg syntax highlighting backend.
2012-07-14 13:45:03 -05:00
Jesse D. McDonald 786258f144 Add the rest of the FP math primitives.
Improve detection of unsimplified primitive forms. Also hides %goto-end-*.
Automatically convert fixnum to FP in get_float(). (But not _get_float()!)
2012-07-14 13:45:01 -05:00
Jesse D. McDonald 67ea700ac2 Fix handling of (set! var (let (var) ...)) and similar cases.
Was moving (set!) into the (%bind) form, and thus setting the wrong variable.
Now, if set! var is bound, will create a temporary for result of %bind first,
and set! original variable to temporary in the proper scope.

Also, normalize rules for nested (%bind)s:
* The (%bind) inside a (%lambda) is always flat.
   - This is a responsiblity of simplify-lambda, and any function which
     may change structure after simplification (e.g. promote-to-box).
* Any other (%bind) may be nested, unless otherwise noted.
2012-07-14 13:44:56 -05:00
Jesse D. McDonald 5c8625a1f1 Check in some sample programs demonstrating the compiler. 2012-07-14 13:44:55 -05:00
Jesse D. McDonald cc8dc5d9b6 Add many additional primitives, and centralize definitions.
Also:
- assume top-level free variables are constants, not boxes;
- bind variable 'argv' to top-level argument list, rather than assuming no arguments;
- make %values a first-class form, just like %apply and %call/cc (was: pseudo-primitive);
- fix case where 'rest' argument is sole item in argument list: (lambda argv ...); and
- perform misc. cleanup in output code.
2012-07-14 13:44:52 -05:00
Jesse D. McDonald 03fc616b7a Add basic support for outputting values suitable for the Rosella reader. 2012-07-14 13:44:51 -05:00
Jesse D. McDonald c5cf95b867 Implement basic value-propogation and support for multiple return values.
Also performed misc. cleanup, corrected use of temp variables in (let ...),
changed make-bindings-unique to preserve original names as prefixes, improved
detection of unused %set! forms in reduce-set!, and fixed map-variables to
extract the real value from (quote ...) literal forms.
2012-07-14 13:44:48 -05:00
Jesse D. McDonald 4ab23f6877 Thread context register (%ctx) through %apply and %call/cc forms.
Also remove top-level forms without side-effects during CPS transformation.
2012-07-14 13:44:46 -05:00
Jesse D. McDonald 35059dfebf Implement register allocation.
All that remains is to convert the result to bytecode & format as rosella source code.
2012-07-14 13:44:43 -05:00
Jesse D. McDonald c3e46525db Implement conversion of shared variables to boxes.
Also, narrow bindings to their minimal necessary scope. This reduces
the number of variables which must be considered 'shared'.
2012-07-14 13:44:39 -05:00
Jesse D. McDonald b899f0c3b0 Implement support for (call/cc), and shorthand form (let/cc).
Adds support for non-local returns, among other control-flow structures.
2012-07-14 13:44:35 -05:00
Jesse D. McDonald 14b2a1570a Add support for (quote) literal forms in compiler.ss. 2012-07-14 13:44:33 -05:00
Jesse D. McDonald 0b0b352dd6 Clean up handling of (let) and (%bind), plus misc. cleanup.
With this change, any (%bind) returned from (simplify-let) or (simplify-form)
can be assumed to be flat, with unique bound symbols. Before, this was only
true of (%lambda) forms and the output of (compile).
2012-07-14 13:44:30 -05:00
Jesse D. McDonald 6b51229c48 Raise an error if (set! ...) is applied to a form without a value.
Exception is (%tail-call ...) form, which is permitted simply because
(%tail-call ...) transfers control unidirectionally; the enclosing
(%set! ...) form wouldn't be run anyway.
2012-07-14 13:44:17 -05:00
Jesse D. McDonald 8e147f7989 Don't create extra lambdas when both results of (if ...) are trivial.
Also map () directly to %nil, and allow (%if ...) to provide a value to a set! form.
2012-07-14 13:44:05 -05:00
Jesse D. McDonald 46b18c07d6 Implement conversion to tail-call form (CPS).
Also add some basic optimizations concerning binding and setting
variables which will never be used.
2012-07-14 13:43:58 -05:00
Jesse D. McDonald a98ecda079 Commit other half of doc/compiler.txt -> compiler.ss move. 2012-07-14 13:43:50 -05:00
Jesse D. McDonald 988d4264b2 Improve representation of tail-calls, and normalize primitive operations. 2012-07-14 13:43:45 -05:00
Jesse D. McDonald fd17fcd99c Update compiler description (now a working Scheme program).
Maps lexical variables, decodes argument lists, and flattens procedures
to simple lists of primitive operations, but does not yet convert to
CPS or perform register (gN, iN, fN) allocation, much less optimization.
2012-07-14 13:43:40 -05:00
Jesse D. McDonald 885a1ebdbb Fix a missing-root error in interp.c:perform_tail_call(). 2012-07-14 13:43:39 -05:00
Jesse D. McDonald 9f351abd86 Commit simple script to run regression tests: src/examples/test-*.rla. 2012-07-14 13:43:38 -05:00
Jesse D. McDonald 314e167e6e Commit initial notes on compilation from Scheme-like source code. 2012-07-14 13:43:37 -05:00
Jesse D. McDonald f542fa2bd5 Add bytecodes to skip the rest of a block based on a condition.
Should simplify error-handling and sequences of primitive tests.
Also, automatically instantiate templates used in the tail-call lambda & cont'n fields.
2012-07-14 13:43:33 -05:00
Jesse D. McDonald 6dd02a5d6e Stop reading at EOF, and signal an error when EOF occurs inside a string. 2012-07-14 13:43:32 -05:00
Jesse D. McDonald 7e5014ab07 Correct oversight - 0xfe was not changed to 0xff in lambda args. 2012-07-14 13:43:30 -05:00
Jesse D. McDonald bc3df6dd17 Swap continuation & context in the lambda and template structures.
This is to separate the three 'call' parameters (target, argv, ctx) from
the 'return to' parameter (k). The old order made it look as if the dynamic
context was in some way related to the continuation, which is not the case.
2012-07-14 13:43:26 -05:00
Jesse D. McDonald 9af29f28da Commit basic (and ...) & (or ...) *functions*, with lambda args. 2012-07-14 13:43:25 -05:00
Jesse D. McDonald 893b7e122e Commit (append ...) function, implemented as nested (foldr ...) calls. 2012-07-14 13:43:24 -05:00
Jesse D. McDonald a6715b0922 More primitive functions: map, reverse, acons. 2012-07-14 13:43:23 -05:00
Jesse D. McDonald 2d7b079dd8 Make (foldl ...) state the second argument, as with (foldr ...). 2012-07-14 13:43:22 -05:00
Jesse D. McDonald c6500a53b3 Commit implementation of (foldl ...) function. 2012-07-14 13:43:21 -05:00
Jesse D. McDonald 3a418484c8 Commit (foldr ...) function, and refactor (list ...) to use it. 2012-07-14 13:43:20 -05:00
Jesse D. McDonald a1db12d1e2 Commit implementation of (list ...) primitive function. 2012-07-14 13:43:18 -05:00
Jesse D. McDonald ffb8e8f86d Separate statistics for Gen-0 vs. Gen-1 garbage collection. 2012-07-14 13:43:17 -05:00
Jesse D. McDonald 0a6d2f3f73 Control printing of GC stats with GC_STATS env. var rather than #if 0/1. 2012-07-14 13:43:16 -05:00
Jesse D. McDonald 7a651dc9d1 Update main app to use new gc_init() prototype w/ separate Gen-0 size. 2012-07-14 13:43:15 -05:00
Jesse D. McDonald 632ac19adf Make Gen-0 size semi-independent of Gen-1 minimum size. 2012-07-14 13:43:14 -05:00
Jesse D. McDonald 7f55142d72 Fix several significant bugs in the generational collector.
No known issues remaining at this time.
2012-07-14 13:43:10 -05:00
Jesse D. McDonald 311a4c2d55 Don't include gc_poison_region in non-debug builds. 2012-07-14 13:43:09 -05:00
Jesse D. McDonald 12b5976b66 Fix a bug which was cryptically preventing Gen-1 size from increasing. 2012-07-14 13:43:07 -05:00