Right, I'm committing this session because I'm too cold and tired to go on.

It does not at present build (and it's going to take a good bit more work
before it does).
This commit is contained in:
Simon Brooke 2026-04-20 18:29:28 +01:00
parent f05d1af9d6
commit 6148d3699f
32 changed files with 364 additions and 309 deletions

View file

@ -35,16 +35,20 @@
#include "ops/truth.h"
/**
* @brief Allocate an object of this size_class with this tag.
* @brief Allocate an object of this `size_class` with this `tag`.
*
* All objects that are allocated (after completion of init)) should be linked
* onto the `locals` slot on a stack frame. This guarantees
* 1. that they get `inc_ref`ed; and that,
* onto the `locals` slot of a stack frame. This guarantees
* 1. that they do get `inc_ref`ed; and that,
* 2. if nothing else hangs onto them they will be reclaimed when that stack
* frame is reclaimed.
* for some objects (e.g. those cons cells on the locals list) this isn't
* possible due to infinite recursion, but those special cases need to be
* audited carefully
* audited carefully.
*
* The stack frame pointer is DELIBERATELY a C pointer, not a Lisp pointer,
* because you are definitely not supposed to be calling this function from
* Lisp. Please do not!
*
* @param stack_pointer C (NOT Lisp!) pointer to an active stack frame (or
* NULL, but only during initialisation).
@ -52,8 +56,9 @@
* @param size_class The size class for the object to be allocated;
* @return struct pso_pointer a pointer to the newly allocated object
*/
struct pso_pointer allocate( /* struct pso4 * stack_pointer,*/ char *tag, uint8_t size_class ) {
// todo: issue #21: must have stack frame passed in.
struct pso_pointer allocate( struct pso4 *stack_pointer, char *tag,
uint8_t size_class ) {
// todo: issue #21: must have stack frame passed in.
#ifdef DEBUG
debug_printf( DEBUG_ALLOC, 0,
@ -61,26 +66,29 @@ struct pso_pointer allocate( /* struct pso4 * stack_pointer,*/ char *tag, uint8_
size_class, tag );
#endif
struct pso_pointer result = pop_freelist(size_class);
struct pso_pointer result = pop_freelist( size_class );
if (!nilp( result)) {
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 ( stack_pointer != NULL &&
// (stack_pointer->header.tag.value & 0xffffff) == STACKTV) {
// struct pso_pointer locals = make_cons(result,
// stack_pointer->payload.stack_frame.locals);
// stack_pointer->payload.stack_frame.locals = locals;
//
// } else {
// fputws( L"WARNING: No stack frame passed to `allocate`.\n", stderr);
// }
} else {
// TODO: throw exception
}
if ( !nilp( result ) ) {
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 ( stack_pointer != NULL &&
( stack_pointer->header.tag.value & 0xffffff ) == STACKTV ) {
struct pso_pointer locals = make_cons( result,
stack_pointer->
payload.stack_frame.
locals );
stack_pointer->payload.stack_frame.locals = locals;
} else if ( memory_initialised ) {
fputws( L"WARNING: No stack frame passed to `allocate`.\n",
stderr );
}
} else {
// TODO: throw exception
}
#ifdef DEBUG
debug_print( exceptionp( result ) ? L"fail\n" : L"success\n", DEBUG_ALLOC,
@ -203,7 +211,7 @@ struct pso_pointer free_object( struct pso_pointer p ) {
obj->payload.words[i] = 0;
}
push_freelist(p);
push_freelist( p );
return result;
}