Commit graph

9200 commits

Author SHA1 Message Date
Daniel Kochmański
6a37c7839a [wip] reader: add a new helper function ecl_parse_fixnum
This funciton parses an integer and returns OBJNULL when it exceeds the size of
a fixnum.

It is used in format.d - a file that is not compiled currently. It should be
also used in cl_name_char.

[wip] because:
- is it really needed?
- I've commented unicode access for digitp
2026-03-08 21:56:21 +01:00
Daniel Kochmański
ff944563de [r2rs] add read-print-loop 2026-03-08 21:56:07 +01:00
Daniel Kochmański
e696eb0d91 [r2rs] add a stub for r2rs implementation 2026-03-08 20:03:25 +01:00
Daniel Kochmański
758de4e73f [nucl] adjust to the new reader implementation 2026-03-08 20:03:25 +01:00
Daniel Kochmański
c4bbfad258 [nucl] smaller stacks 2026-03-08 20:03:25 +01:00
Daniel Kochmański
829bd4173c [nucl] fix the compiled code size and cleanup the dictionary
Previously we've wrongly estimated that the vector with opcodes has the same
length as the number of words, but:

CALLW takes an argument denoting the index of the function on data stack
PUSHQ takes an argument denoting the index of the literal on data stack

Moreover rename some dictionary entries for more descriptive names and add a new
word .V that prints values stored in the environment.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
a3facd8530 [nucl] _nucl_word_dispatch use a stack-allocated frame
nucl_stack_frame is not always defined when we call to this function.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
5736cc88c2 [nucl] add all opcodes to the dictionary 2026-03-08 20:03:25 +01:00
Daniel Kochmański
2e6d259ea9 [nucl] words operate directly on the stack
In the first sketch they operated on stack frames, but this approach was flawed
because a) leaving things on the stack above frame prevented it from growing
leading to an internal error, b) closing the frame wiped all values deposited on
the stack that were above the frame base.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
0184f70354 [nucl] write a forth compiler 2026-03-08 20:03:25 +01:00
Daniel Kochmański
214a2cead5 [nucl] add a (mock for now) function nucl_compile_definition 2026-03-08 20:03:25 +01:00
Daniel Kochmański
b5fdebc811 [nucl] don't modify VALUES vector and use dynamic STDIN/STDOUT vals 2026-03-08 20:03:25 +01:00
Daniel Kochmański
422dfbcc2e [nucl] liberate stack frames from stack allocation terror 2026-03-08 20:03:25 +01:00
Daniel Kochmański
5191798704 [nucl] don't pop if the item was not added 2026-03-08 20:03:25 +01:00
Daniel Kochmański
ac33b8698e [nucl] clean up the file (move things around) 2026-03-08 20:03:25 +01:00
Daniel Kochmański
d038931e1b [nucl] implement word definition 2026-03-08 20:03:25 +01:00
Daniel Kochmański
d83fcdf836 [nucl] add a compilation mode (doesn't actually compile yet) 2026-03-08 20:03:25 +01:00
Daniel Kochmański
a317f03c01 [nucl] resolve words only when called, otherwise return symbols
This is necessary for defining new words and allows us to move the dictionary
implementation after the reader.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
6e8fb94e6c [nucl] add to the dictionary word pop 2026-03-08 20:03:25 +01:00
Daniel Kochmański
809c8f3b48 [nucl] reorganize file and add "print stack" word 2026-03-08 20:03:25 +01:00
Daniel Kochmański
d766f74ab0 [nucl] allow calling into words and properly maintain the stack
This commit takes a correction over things corrected (and rebased) in
refactor-stacks branch.

consturctors nucl_stack_to_foo remove elements from the stack and leave the
parsed element on the stack.

Move specials at the beginning.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
f993eda32f [nucl] fix eof issues and add reading the line of objects 2026-03-08 20:03:25 +01:00
Daniel Kochmański
816e741e00 [nucl] allow extending the dictionary and make it a special variable 2026-03-08 20:03:25 +01:00
Daniel Kochmański
e7989cc8f9 [nucl] add a provisionary symbol dictionary 2026-03-08 20:03:25 +01:00
Daniel Kochmański
7426a3cfed [nucl] add a proto-repl without eval step 2026-03-08 20:03:25 +01:00
Daniel Kochmański
3db21bec37 [nucl] use the data stack 2026-03-08 20:03:25 +01:00
Daniel Kochmański
5eec810592 [nucl] skip whitespace in the reader 2026-03-08 20:03:25 +01:00
Daniel Kochmański
ab45a0256b [nucl] parse fixnums and hexnums 2026-03-08 20:03:25 +01:00
Daniel Kochmański
aa7109495c [nucl] implement basic reader and writer 2026-03-08 20:03:25 +01:00
Daniel Kochmański
9da5576fc1 [nucl] stacks: add a few unsafe operations 2026-03-08 20:03:25 +01:00
Daniel Kochmański
1f07d7530e [nucl] add barebones reader 2026-03-08 20:03:25 +01:00
Daniel Kochmański
4ec019ba90 [nucl] add Lali-ho I/O 2026-03-08 20:03:25 +01:00
Daniel Kochmański
902c27306d [nucl] implement a barebones stream 2026-03-08 20:03:25 +01:00
Daniel Kochmański
36dcd4675e [nucl] add a mock stream 2026-03-08 20:03:25 +01:00
Daniel Kochmański
778bcd4e9a [nucl] showcase calling into ecl_interpret 2026-03-08 20:03:25 +01:00
Daniel Kochmański
40c1571257 [wip] nucl: binary and preliminary notes
nucl: build nucleus directly from .c files (not .o)
2026-03-08 20:03:25 +01:00
Daniel Kochmański
fd0f5db4d5 [wip] msvc: update a makefile and specify /std:c11 minimal standard
MSVC does not allow for specifying /std:c99 so we need c11. We don't rely on the
default standard because it does not allow for static struct initializers.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
2e1d336581 [bytevm][wip] new opcode CALLW, don't use lcl frame when no locals
CALLW calls a word from the data stack. The word differs from normal functions
in that it takes no arguments (so the call does not modify the data stack).

To allow words using the stack across calls (like in "real" forth) don't unwind
the stack on exit if there are no locals.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
aa6600cea3 [bytevm][wip] bytevm: allocate stack manually
wip tag because:

- we don't free tha stack (we use alloc_memory)
2026-03-08 20:03:25 +01:00
Daniel Kochmański
9411f7a1ae [wip] memory: ensure disabled interrupts in top-level operators
ecl_alloc_object, ecl_free_object
ecl_alloc, ecl_alloc_manual, ecl_alloc_atomic, ecl_dealloc

Moreover move all top-level ops to memory.d so they are not reliant on mem_gc.
The stubbed allocator uses manual memory managament for all ops.

[wip] because we should adjust ecl_make_stack too
2026-03-08 20:03:25 +01:00
Daniel Kochmański
30e57a8eab memory: reify the type_info database
We store information about the object size, its pointers and name. This
information is later reused by the garbage collector.
2026-03-08 20:03:25 +01:00
Daniel Kochmański
bb278092e0 memory: move ecl_alloc_adjustable_*_string to memory.d
These constructors are used to provide buffers that may be returned to cl_core.
2026-03-08 20:02:27 +01:00
Daniel Kochmański
2bcb475df4 memory: move ecl_cons to memory.d
ecl_cons requires a separate allocator because it may be a small cons.
2026-03-08 20:01:34 +01:00
Daniel Kochmański
a435f69b1f memory: make it possible to configure the allocator 2026-03-08 20:01:34 +01:00
Daniel Kochmański
ac423108d7 nucleus: introduce a table with early symbols ecl_symbols
This table contains symbols that are essential to the core runtime: ECL_T,
ECL_UNBOUND, ECL_SIGNAL_HANDLERS, ECL_RESTART_CLUSTERs, ECL_INTERRUPTS_ENABLED,
ECL_ALLOW_OTHER_KEYS and ECL_UNBOUND.

The table is initialized with constexpr, so it is possible to use its elements
in static elements. We also add ecl_def_function to ecl-inl to allow
appropriating C functions into Lisp world at top level.
2026-03-08 20:01:34 +01:00
Daniel Kochmański
f203d2db64 nucleus: move early stacks to a separate file
This is necessary if we want to link them into nucleus without CL env baggage.
2026-03-08 20:01:34 +01:00
Daniel Kochmański
21fb42edd9 nucleus: move aux throw/go/tagbody implementations to jump.d 2026-03-08 20:01:34 +01:00
Daniel Kochmański
6be00c50c5 garbage: allow for building ecl without bdwgc and with nogc
In that case we use a dummy object nogc.o that contains stubs for GC-related
functions. It also defines a substitute module.
2026-03-08 20:01:34 +01:00
Daniel Kochmański
0c8e6b38b9 modules: uninstall signal handlers when unixint is destroyed 2026-03-08 20:01:34 +01:00
Daniel Kochmański
7894622840 modules: deallocate stacks when modules are destroyed 2026-03-08 20:01:34 +01:00