summaryrefslogtreecommitdiff
path: root/src/lisp
Commit message (Collapse)AuthorAge
* altos: Escape lisp REP loop with () inputKeith Packard2017-04-09
| | | | | | | Provide a way to get out of a lisp read-eval-print loop that can be easily input from the keyboard. Signed-off-by: Keith Packard <keithp@keithp.com>
* lisp: Fix up lisp build so projects can get ao_lisp_const.h built as neededKeith Packard2017-04-02
| | | | Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Not quite ready to start making it look like scheme yetKeith Packard2017-02-20
| | | | | | Lots more code to write before these symbols can be exposed. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Start adding scheme symbolsKeith Packard2017-02-20
| | | | | | Migrating to something more like scheme Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Add casts to keep the latest GCC from whingingKeith Packard2017-02-20
| | | | | | Something about alignment issues. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Tell compiler that the two lisp memory pools are alignedKeith Packard2017-02-20
| | | | | | | Otherwise, it will generate unaligned accesses to things fetched from them. Sigh. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Move stack recursion check after null checkKeith Packard2017-02-20
| | | | | | Don't crash when printing null stack this way. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Cleanup some DBG definesKeith Packard2017-02-20
| | | | | | Get rid of the remaining duplicate defines. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Share binary search for memory chunk between mark and moveKeith Packard2017-02-20
| | | | | | Save some text space. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Add builtin 'collect'Keith Packard2017-02-20
| | | | | | Collect memory, return amount free. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Sort frames by atomKeith Packard2017-02-20
| | | | | | | | | Fortunately, the collector always retains the relative order between addresses, so we can sort based on the atom address itself. This reduces the time spent looking for names in larger (e.g. global) frames. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: bounds check in move_map plus binary searchKeith Packard2017-02-20
| | | | | | | | | | This makes move_map faster by skipping all addresses which aren't changing. Also changed the interface from address to offset to avoid computing the offset multiple times. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Empty lambda body is not an errorKeith Packard2017-02-20
| | | | | | It's not very exciting, but it's still legal Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Use poly stashes for stacksKeith Packard2017-02-20
| | | | | | Saves some memory. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Make DBG settings globalKeith Packard2017-02-20
| | | | | | This avoids having different values in different files, which wasn't useful. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Add continuationsKeith Packard2017-02-20
| | | | | | This provides call/cc and makes 'stacks' visible to the application. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: have 'while' return the last body valueKeith Packard2017-02-20
| | | | | | | Instead of always returning 'nil', let while return the last body value. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Take advantage of implicit progn in ROM codeKeith Packard2017-02-20
| | | | Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Make lambda, cond and while all have implicit prognsKeith Packard2017-02-20
| | | | | | | This lets all of these execute more than one sexpr, returning the value of the last. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Compile ao_lisp_make_const -no-pieKeith Packard2017-02-20
| | | | | | Makes debugging easier Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Fix uninitialized values in ao_lisp_make_constKeith Packard2017-02-20
| | | | Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Dump globals on errorKeith Packard2017-02-20
| | | | | | Useful for debugging Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Fix error atom name in ao_lisp_lengthKeith Packard2017-02-20
| | | | | | Cut&paste error. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Remove some stale frame debugging checksKeith Packard2017-02-20
| | | | | | No-one sets frame->_num to 0xff to hit these Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Eliminate compiler warning about array bounds at -O3Keith Packard2017-02-20
| | | | | | | | | Using ao_lisp_pool - 4 caused the compiler to whinge about computing an address outside the bounds of the array. Sigh. Restructure the code to do the adjustment-by-4 in the integer computations instead of the pointer ones. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: binary search for chunk in collectKeith Packard2017-02-20
| | | | | | Speeds up collect a bit Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Allow empty defun bodiesKeith Packard2017-02-20
| | | | | | This allows for (defun foo()) Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Optimize chunk searching in collectKeith Packard2017-02-20
| | | | | | | Note range of existing chunks to exclude objects outside. Only look at chunks which have been set to reduce loop cost. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Add incremental collectionKeith Packard2017-02-20
| | | | | | | | | | | | Realizing that long-lived objects will eventually float to the bottom of the heap, I added a simple hack to the collector that 'remembers' the top of the heap the last time a full collect was run and then runs incremental collects looking to shift only objects above that boundary. That doesn't perfectly capture the bounds of transient objects, but does manage to reduce the amount of time spent not moving persistent objects each time through the collector. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Take advantage of multi-arg macros. Add more ROM funcsKeith Packard2017-02-20
| | | | | | Added nth, or and and. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Allow macro/nlambda/lexpr to have multiple argsKeith Packard2017-02-20
| | | | | | | | Entries from the params are bound to the formals with whatever remaining formals there are bound to the last argument as a list. This makes writing functions a bit easier. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Do better checking for un-evaluated macros in ROMKeith Packard2017-02-20
| | | | | | | | Need to look at immediate lambdas as well, and also deal with recursive functions by checking for recursion at each atom dereference. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: re-use small framesKeith Packard2017-02-20
| | | | | | | | | This saves a pile more use of the allocator by noting when frames have not been referenced from another frame and freeing them when they go out of scope. Frames with references are left to the allocator to deal with. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Get lambdakey and nucleo-32 building againKeith Packard2017-02-20
| | | | | | Remove exti from the build list to make things fit. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Evaluate macros once, then smash them into placeKeith Packard2017-02-20
| | | | | | | This assumes that macros are all pure functions, which should be true for syntactic macros. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Cache freed cons and stack itemsKeith Packard2017-02-20
| | | | | | | | | Track freed cons cells and stack items from the eval process where possible so that they can be re-used without needing to collect. This dramatically reduces the number of collect calls. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Simplify GC a bit by only marking the head of each objectKeith Packard2017-02-20
| | | | | | | | | We don't need to mark the whole object now as we're getting information about where objects are by walking the tree each time around the loop; ao_lisp_busy is only useful for terminating the walk now. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Change GC to do moves in batches of 32Keith Packard2017-02-20
| | | | | | This should make it quite a bit faster than doing one at a time. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Append a CRC to the saved image to validate on restoreKeith Packard2017-02-20
| | | | | | | The CRC is actually of the ROM bits, so we can tell if the restored image relates to the currently running code. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Add save/restore infrastructure. Needs OS support to work.Keith Packard2017-02-20
| | | | | | | | This sticks a few globals past the end of the heap and then asks the OS to save the heap. On restore, the heap is re-populated by the OS and then various global variables reset. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Make sure memmove only happens once per object. Other GC fixesKeith Packard2017-02-20
| | | | | | | | | | | | The memmove may be overlapping, so make sure it happens only once by just checking whether move_size has been set, rather than looking at ao_lisp_moving; that doesn't get set when moving a noted cons as that still needs to be walked at a later time. Fix up the various looping move functions to all use the same pattern. Atom was busted. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Make ao_lisp_ref and ao_lisp_poly non-inlineKeith Packard2017-02-20
| | | | | | | These functions are pretty large and end up consuming quite a bit of space if inlined everywhere they are used. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Share mark function for mark and moveKeith Packard2017-02-20
| | | | | | | These two operations both wanted to walk the referenced objects; sharing is caring. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: add length, pack, unpack and flushKeith Packard2017-02-20
| | | | | | lots more builtins Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Deal with memory compation in the middle of operationsKeith Packard2017-02-20
| | | | | | | | Handle memory compaction in places where we've got pointers into the heap across an allocation operation. Either re-compute the values from managed global references or add new roots across the allocation. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Make read() return eof atom on end of fileKeith Packard2017-02-20
| | | | | | Also make it an exception to hit eof in the middle of an sexpr. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: use regular read-eval-print loop for make constKeith Packard2017-02-20
| | | | | | No need to open code this sequence of operations. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: add progn, while, read and evalKeith Packard2017-02-20
| | | | | | | | Progn as a builtin will help with tail-recursion. while provides for loops until tail-recursion works :-) read and eval are kinda useful. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: Clean up OS integration bits, add defunKeith Packard2017-02-20
| | | | | | | Provide an abstraction for the OS interface so that it can build more cleanly on Linux and AltOS. Add defun macro. Signed-off-by: Keith Packard <keithp@keithp.com>
* altos/lisp: macros appear to work nowKeith Packard2017-02-20
| | | | | | | | Needed an extra stack frame to stash the pre-macro state. This simplified macro processing quite a bit; a macro now just evaluates the function and then sends that result to be evaluated again. Signed-off-by: Keith Packard <keithp@keithp.com>