Initialisation almost succeeds. nil and t are successfully instantiated.

We then go into a mess of exceptions which trigger exceptions until we run out
of allocatable memory, but all those exceptions and stack frames are correctly
allocated and torn down again afterwards, so.... sort of good?
This commit is contained in:
Simon Brooke 2026-04-16 11:39:01 +01:00
commit ba985474f6
31 changed files with 869 additions and 199 deletions

View file

@ -9,8 +9,23 @@
#include <stdbool.h>
#include "debug.h"
#include "memory/memory.h"
#include "memory/node.h"
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/pso2.h"
#include "memory/tags.h"
#include "ops/bind.h"
#include "ops/string_ops.h"
#include "payloads/cons.h"
#include "payloads/exception.h"
#include "payloads/psse_string.h"
#include "ops/truth.h"
/**
* @brief Flag to prevent re-initialisation.
@ -20,16 +35,57 @@ bool environment_initialised = false;
/**
* @brief Initialise a minimal environment, so that Lisp can be bootstrapped.
*
* @param node theindex of the node we are initialising.
* @param node the index of the node we are initialising.
* @return struct pso_pointer t on success, else an exception.
*/
struct pso_pointer initialise_environment( uint32_t node ) {
struct pso_pointer result = t;
if ( environment_initialised ) {
// TODO: throw an exception "Attempt to reinitialise environment"
} else {
// TODO: actually initialise it.
struct pso_pointer result = initialise_memory( node );
if ( truep( result ) ) {
debug_print( L"Initialising `nil`... ", DEBUG_BOOTSTRAP, 0);
struct pso_pointer n = allocate( NILTAG, 2 );
if ( ( n.page == 0 ) && ( n.offset == 0 ) ) {
struct pso2 *object = pointer_to_object( n );
object->payload.cons.car = nil;
object->payload.cons.cdr = nil;
nil = n;
debug_print( L"success\n", DEBUG_BOOTSTRAP, 0);
} else {
result =
make_exception( c_string_to_lisp_string
( L"Unexpected cell while allocating `nil`." ),
nil, n );
debug_print( L"fail\n", DEBUG_BOOTSTRAP, 0);
}
}
if ( !exceptionp( result ) ) {
debug_print( L"Initialising `t`... ", DEBUG_BOOTSTRAP, 0);
struct pso_pointer n = allocate( TRUETAG, 2 );
// offset is in words, and size of a pso2 is four words
if ( ( n.page == 0 ) && ( n.offset == 4 ) ) {
struct pso2 *object = pointer_to_object( n );
object->payload.string.character = L't';
object->payload.cons.cdr = t;
t = n;
debug_print( L"success\n", DEBUG_BOOTSTRAP, 0);
} else {
result =
make_exception( c_string_to_lisp_string
( L"Unexpected cell while allocating `t`." ),
nil, n );
debug_print( L"fail\n", DEBUG_BOOTSTRAP, 0);
}
}
if ( !exceptionp( result ) ) {
result = c_bind( c_string_to_lisp_symbol( L"nil" ), nil, nil );
result = c_bind( c_string_to_lisp_symbol( L"t" ), t, result );
environment_initialised = true;
}
return result;