It compiles. It runs. Nothing works, but it also doesn't crash. Victory!

This commit is contained in:
Simon Brooke 2026-04-23 11:50:30 +01:00
parent 8d2acbeb0f
commit aa0d60bbed
20 changed files with 390 additions and 244 deletions

View file

@ -35,6 +35,26 @@
#include "ops/truth.h"
/**
* @brief a means of creating a cons cell without using a stack frame, to
* prevent runaway recursion.
*
* @param car
* @param cdr
*
* return cons
*/
struct pso_pointer cheaty_make_cons( struct pso_pointer car,
struct pso_pointer cdr ) {
struct pso_pointer result = allocate( nil, CONSTAG, 2 );
struct pso2 *obj = pointer_to_object( result );
obj->payload.cons.car = car;
obj->payload.cons.cdr = cdr;
return result;
}
/**
* @brief Allocate an object of this `size_class` with this `tag`.
*
@ -67,15 +87,18 @@ struct pso_pointer allocate( struct pso_pointer frame_pointer, char *tag,
struct pso4 *frame = pointer_to_pso4( frame_pointer );
if ( !c_nilp( result ) ) {
strncpy( ( char * ) ( pointer_to_object( result )->header.tag.
bytes.mnemonic ), tag, TAGLENGTH );
strncpy( ( char * ) ( pointer_to_object( result )->header.tag.bytes.
mnemonic ), tag, TAGLENGTH );
debug_printf( DEBUG_ALLOC, 0, L"at page %d, offset %d... ",
result.page, result.offset );
if ( stackp( frame_pointer ) ) {
struct pso_pointer locals = make_cons( frame_pointer, result,
frame->payload.
stack_frame.locals );
// You can't make a stack frame in the middle of making a stack
// frame. Infinite recursion. So we have to cheat.
struct pso_pointer locals = cheaty_make_cons( result,
frame->
payload.stack_frame.
locals );
frame->payload.stack_frame.locals = locals;
} else if ( memory_initialised ) {