Commit Graph

145 Commits

Author SHA1 Message Date
Jesse D. McDonald d79eab3848 For vectors, spaces come before 2nd-Nth values; #(1 2 3) vs. #(12 3 ). 2012-07-14 13:47:44 -05:00
Jesse D. McDonald f3458173c4 Implement simple self-hosting compiler (src/compiler.rls). 2012-07-14 13:47:39 -05:00
Jesse D. McDonald c3a4a0fc57 Remove profiling code, which doesn't appear to work anyway. 2012-07-14 13:47:38 -05:00
Jesse D. McDonald 9fbd3d0212 Use hash table for *symbols* in reader, instead of a list. 2012-07-14 13:47:37 -05:00
Jesse D. McDonald 99da463f84 Add the ability to remove keys from a hash table. 2012-07-14 13:47:36 -05:00
Jesse D. McDonald a2a5532703 Add basic (non-balancing binary tree) hash-table implementation & test. 2012-07-14 13:47:35 -05:00
Jesse D. McDonald da3b000312 Reimplement map-variables to handle captured variables properly. 2012-07-14 13:47:34 -05:00
Jesse D. McDonald ded5b4851d Add support for named (let ...) forms. (Does not yet include let* or letrec.) 2012-07-14 13:47:33 -05:00
Jesse D. McDonald 647fcd59d7 Remove transient/instance-variable?, which is no longer used. 2012-07-14 13:47:32 -05:00
Jesse D. McDonald b14f75d946 Add -E option to dump result of module reader before simplification. 2012-07-14 13:47:30 -05:00
Jesse D. McDonald be48535995 Change bytecode from 'frame' vars to 'transient' values.
Each transient identifies the value of the corresponding previous bytecode.
This change (a) frees up many bytecodes formerly used by the conditional
expression (if c t f); (b) regularizes the bytecode by always placing opcodes
before operands; and (c) causes the bytecode to conform to the Single Static
Assignment (SSA) form preferred by e.g. LLVM.

Includes updates to the hand-assembled files (*.rla) and the bytecode compiler.
2012-07-14 13:47:28 -05:00
Jesse D. McDonald 6da373201c Fix printing of fixnums on 64-bit platforms by using %lld and "long long int". 2012-07-14 13:47:26 -05:00
Jesse D. McDonald 3b56fdb5fc Properly define INTPTR_MIN and INTPTR_MAX on x86_64 platforms. 2012-07-14 13:47:23 -05:00
Jesse D. McDonald b6271bf13e Ensure correct types are passed to printf() when size_t != int. 2012-07-14 13:47:22 -05:00
Jesse D. McDonald cb0d7b62e5 Support writing recursive data structures and quoted symbols.
Eliminate use of #="undefined" as an explicit initializer for boxes.
Do not allow #@ ("freeze") to be applied to references, for sanity's sake.

Inside compiler, builtins are now represented by (#%builtin "name") form.
Plain symbols are promoted to builtins; quoted symbols become structures.
2012-07-14 13:47:19 -05:00
Jesse D. McDonald cc16957256 Add "#@" to lambdas/templates and their string/vector fields.
This makes the values immutable, which is now enforced by the interpreter.
2012-07-14 13:47:17 -05:00
Jesse D. McDonald 03c3dec091 Extend reader with placeholders for immutable values and structures.
This means that such values can once again contain references (#=nnn).
2012-07-14 13:47:15 -05:00
Jesse D. McDonald 42312e394a Add a helper function for creating structure types. 2012-07-14 13:47:13 -05:00
Jesse D. McDonald 892af308ce Add support for immutable vectors, byte-strings, and structures.
The interpreter now requires its input to be immutable.
The reader marks values read after '#@' as immutable, e.g. #@#(...).
2012-07-14 13:47:10 -05:00
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