Skip to content

flisp repl implemented completely in Lisp itself#62

Open
jorge-leon wants to merge 93 commits into
hughbarney:masterfrom
jorge-leon:lisp-repl
Open

flisp repl implemented completely in Lisp itself#62
jorge-leon wants to merge 93 commits into
hughbarney:masterfrom
jorge-leon:lisp-repl

Conversation

@jorge-leon

Copy link
Copy Markdown
Contributor

This PR simplifies the flisp command substantially, by implementing the complete Read Eval Print Loop (repl) in Lisp itself.
Previous PR's have added some required features, this PR adds a new function interp for introspection and configuration of the Lisp interpreter. Currently it only supports reading the version string and setting the input stream of the interpreter.

Several other pending simplification have been included: The stdlib.lsp was integrated into flisp.lsp, thus the number of Lisp files (test suites and documentation chapters) is reduced. Several useful functions have been moved into the core.lsp library
and thus are loaded on startup.

The fLisp core has been reduced further, by replacing some fprintf's with fputs and introducing the bind function. setq is implemented as a macro in terms of bind . All I/O functions not related to fLisp startup itself are move to the file extension.

Documentation and test suites have been expanded.

Change List:

  • Implemented interp introspection and configuration command with version and
    input subcommands.
  • Implemented simple repl in Lisp and minimized flisp.c
  • Replace setq and define with bind in the core. setq is defined in core.lsp
  • Moved append, fold-left, flip, reverse, apply, print, princ to core.lsp
  • Renamed os.env to getenv and move to file extension.
  • Unified stdlib into flisp.lsp (again).
  • Moved (system) to file extension.

Georg Lehner and others added 30 commits August 25, 2025 22:07
See test/1_dired.lsp for a demo test suite

Run `make ltest`  to execute it.
tap code is simplified: instead of appending a test to the test list it is
prepended and the list of tests is reversed before iterating over it.

This adds `reverse` and `flip` to the flisp library.
The `run` test suite runner is renamed to `test` and it got proper command
line parsing.

All test suites must be named *.test.  The first line determines if it is
to be tested by poor mans shell test runner within flips or by the Lisp implementation
tap.lsp within femto.

The first line must contain the Emacs mode string: -*- mode: _type_ -*-
where type is `sh` for flisp and `lisp` for femto.

`tap.lsp` has a simple command line parser to specifiy the test(s) to run.

For writing test scripts:

Write a function which returns a true value if the test passes.

Register the function and a test comment with tap.lsp:

`(tap-register comment function)`
Will need this for file mode operations.
Added file.h, flisp_file_primitives struct in file.c and load it in
initRootEnv() in lisp.c
Parametrized readNumberOrSymbol to compile for integer only if double
extension is not required.
Since the double extension is practically required, it must be declared
in the build of all extension files to not get the type enums wrongly
ordered.
fstat returns a property list with size, mode uid, gid and type, type as string.

It throws one of the following exceptions:
- permission-denied
- not-found
- io-error

(catch (fstat path)) can therefore be used to test for existence of files.
Duplicate "catch" code in lisp-eval() is replaced by using evalCatch.

The only interface with the interpreter is now interp->object, which
receives a catch object (error_type message object).

If error_type == nil, object is the result, otherwise object is the err'ed
object (or nil) and message a string object, message->string the error
message.
to- and fromSpace are allocated individually and resized on demand.

FLISP_MEMORY_INC_SIZE determines the size of allocation junks.

Note: While all tests pass when sufficient initial memory is given,
  gc_always still segfaults.
Must be rewritten in Lisp
…ory size

The interpreter allocates a minimal chunk of memory to boot itself on
start. After that, every time the Lisp object memory is to small, it is
increased by a specific chunk size.

Both parameters: FLISP_MIN_MEMORY and FLISP_MEMORY_INC_SIZE are defined
lisp.h.

While the approach is working well, there are problems with segfaults, when
using gc_always.  These seem to be related to wrong GC_TRACE'ing

Note: on startup the interpreter prints out, how much memory is used for
the initial startup. We round it up manually to the chunk size.
Georg Lehner and others added 29 commits September 10, 2025 09:02
All done items sorted into their version section.
- Fix: Femto did not include the file extension.
- Implement a log facility in startup.lsp.
- Use (catch (fstat ..)) instead of (sytem ("test .." ..)) to test for
  existance of user rc file.
- Improve (getopts) - currently to not allow any command line option.
- Autoload oxo to reduce startup load.
- Set up sensible logging for rc file loading and command line parsing.
femto.rc includes a repl which only prints out something when stdin is
a tty.

No additional library is loaded on startup.

Moved append, fold-left, flip, reverse, apply, print, princ to core.lsp to
be able to use apply, princ and print.

Pending:
- (flisp input)
- (flisp version)
- If stdin is not a tty just set interp input to it.
fprintf of fixed strings are waste of computing power.

The %p format differs in output for different platforms. For printing
the stream serialization we use now the uintptr_t to print the file
descriptor.
The (flisp) command will provide introspection and configuration of the
current interpreter. The 'version sub command returns the full version
string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant