Commit Graph

126 Commits

Author SHA1 Message Date
Jesse D. McDonald 00718b410b Split 'unbox' and 'weak-unbox' operations (different optimizations).
Normal boxes change only by set-box!; weak boxes can change to #f at any time.
2012-07-14 13:47:07 -05:00
Jesse D. McDonald 960d7917c9 Enforce that all structures have types derived from 'structure'.
Take advantage of this invariant to simplify struct type checks elsewhere.
Group (meta)structure definition with basic types.
2012-07-14 13:47:03 -05:00
Jesse D. McDonald b993d6617f Add support for reading symbols.
Also remove | and \ from the list of valid symbol characters.
2012-07-14 13:46:54 -05:00
Jesse D. McDonald 1cd72fc8e0 Add support for reading vectors and strings.
Fix choice of continuation when function ends in (call/cc).
Change empty kw-args from '() to #%nil in (simplify-apply).
Improve error message when no match is found for a primitive form.
2012-07-14 13:46:49 -05:00
Jesse D. McDonald 61b6a76205 Fix a bug in (read-string) which affects non-special characters. 2012-07-14 13:46:47 -05:00
Jesse D. McDonald e1662ca4b8 Convert tail-call parameters to a byte-string.
Add special variables for keyword arguments & values.
Add support for keyword arguments to (simplify-apply).
Implement full string parsing in src/reader.rls.
TODO: Support keywords in (simplify-lambda) and writer.
2012-07-14 13:46:42 -05:00
Jesse D. McDonald a9427d2ec5 In-VM reader for high-level Scheme syntax, initial revision.
Currently supports booleans, lists/pairs, fixnums (incl. 0x, 0b,
0, #x, #d, #o, and #b radix prefixes), basic byte strings, boxes,
weak boxes, script headers (#!), and end-of-line comments.
TODO: Floating-point, vectors, structs, symbols, cyclic references.
2012-07-14 13:46:00 -05:00
Jesse D. McDonald fd62415dee Fix pattern-matching for (value-list (#%apply ...)), etc.
Fix assertion in gc_object_left_behind() to work in Gen-0 collection.
Add (weak-box?) and (make-weak-box) primitives. (unbox) now works for both.
Add option to just simplify the input (stops before reduce-function).
Default to writing .rla without indentation, comments, or newlines.
2012-07-14 13:45:58 -05:00
Jesse D. McDonald 9e4286b49e Refactor (define) parser to work in (let), (lambda), (begin), etc.
Add support for (fix=), (list), (and), (or), (cond), (when), and (unless).
Fix a mapper bug which could assign the same frame var to separate variables.
Update make-struct primitive for new structure type layout.
Change primitives to use #% as prefix instead of just %.
Add primitive operations for comparing byte-strings.
2012-07-14 13:45:54 -05:00
Jesse D. McDonald 061364c75c Remove structure/field names from builtin structure type.
Moves naming policy (strings/symbols) from the VM to the input image.
To restore introspection, derive annotated base types from anonymous builtins.
2012-07-14 13:45:49 -05:00
Jesse D. McDonald 85eed3da7a Fix mismatched parentheses. 2012-07-14 13:45:48 -05:00
Jesse D. McDonald 96b3bded17 Add a primitive operation to calculate a 30-bit hash from any value.
Pairs, boxes, and strings are hashed by values; vectors and structures
are "hashed" by reference. Takes into account the possibility of cycles.
This is a prelude to implementing hash-tables.
2012-07-14 13:45:40 -05:00
Jesse D. McDonald 5d8a302225 More compiler performance tweaks. 2012-07-14 13:45:39 -05:00
Jesse D. McDonald e375edfc83 Improve on struct_is_a() and expose it as a VM primitive operation. 2012-07-14 13:45:36 -05:00
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