Commit Graph

161 Commits

Author SHA1 Message Date
Jesse D. McDonald fde689fb50 (add-top-level-variable) should return accessors as list, not values. 2012-07-14 14:57:06 -05:00
Jesse D. McDonald 66d3ff9d38 Fix a reader issue which prevented reading numbers.
Previous change to (fail) by default assumed (return) was called
on success, which wasn't the case. This rectifies that omission.
2012-07-14 14:55:17 -05:00
Jesse D. McDonald 3bd580d398 Increase memory limit before GC kicks in (2x last active and >= 16MB). 2012-07-14 14:53:08 -05:00
Jesse D. McDonald 8c683a2451 Fix up remaining references to boolean_value, fixnum_value, and cons. 2012-07-14 13:52:25 -05:00
Jesse D. McDonald 3d478c85ee Replace .hgignore with .gitignore. 2012-07-14 13:48:01 -05:00
Jesse D. McDonald 9e789dce14 First version of simplified garbage collector.
For now, this GC is non-generational, and much slower than the old
version. It tracks objects by a fixed object ID rather than changeable
memory address. Small object (eight bytes or less) are stored directly
in the array, indexed by object ID, while larger object are allocated
with malloc() (for now) and stored in the array as a pointer. Object
IDs are stored as 32-bit integers, even on 64-bit platforms.

Advantages:
- Simpler design
- Requires less memory on 64-bit platforms
- Object IDs don't change when running the GC
- No need to store a random "hash" value in vectors/strings/structs
- Can hash pairs by identity, not just value
- Can move objects individually, without fixing up all references
- Can determine object type from value, without another memory access

Disadvantages:
- Lower initial performance (non-generational, relies on malloc())
- 32-bit values place a (high) limit on total number of objects
- Must explicitly free unreachable object IDs after GC
2012-07-14 13:47:58 -05:00
Jesse D. McDonald 8f9ce6122e Read numbers as a subset of symbol syntax. 2012-07-14 13:47:57 -05:00
Jesse D. McDonald b923693c61 Update test code for various library routine API changes. 2012-07-14 13:47:56 -05:00
Jesse D. McDonald b4be240d6f Miscellaneous improvements to the self-hosting compiler. 2012-07-14 13:47:55 -05:00
Jesse D. McDonald 4a98f4eb21 Use builtin exit function as initial continuation and add some debug info. 2012-07-14 13:47:53 -05:00
Jesse D. McDonald 8ba3fa0860 Add built-in functions to exit the program and format floats as strings. 2012-07-14 13:47:52 -05:00
Jesse D. McDonald dcacdecfff Initial commit of RLA-style output library, src/lib/writer.rls. 2012-07-14 13:47:51 -05:00
Jesse D. McDonald 33ef2ce582 Add the ability to print the empty list to src/lib/display.rls. 2012-07-14 13:47:50 -05:00
Jesse D. McDonald 704c473015 Add a new syntax macro, compose-if.
The macro resembles (or x (fn x)) except:
1) The value is only evaluated once, and
2) Multiple (single-argument) functions can be chained.

If the original value or the result of any function is #f, the
final value is #f. Otherwise the result is ((compose ,@fns) x).
Short-circuit evaluation is employed.
2012-07-14 13:47:49 -05:00
Jesse D. McDonald 173c117d86 Improve calculation of hash values. 2012-07-14 13:47:48 -05:00
Jesse D. McDonald d473552806 byte-string-ref should return unsigned fixnums (0 <= x <= 255). 2012-07-14 13:47:46 -05:00
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