Huge amount of work. Does not even nearly compile, but it's nearer.

This commit is contained in:
Simon Brooke 2026-03-28 23:46:14 +00:00
parent 1afb1b9fad
commit cae27731b7
31 changed files with 407 additions and 96 deletions

41
src/c/payloads/stack.c Normal file
View file

@ -0,0 +1,41 @@
/**
* payloads/stack.c
*
* The execution stack.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include "memory/node.h"
#include "memory/pso.h"
#include "payloads/stack.h"
/**
* @brief The maximum depth of stack before we throw an exception.
*
* `0` is interpeted as `unlimited`.
*/
uint32_t stack_limit = 0;
/**
* Fetch a pointer to the value of the local variable at this index.
*/
struct pso_pointer fetch_arg( struct pso4 *frame, unsigned int index ) {
struct pso_pointer result = nil;
// TODO check that the frame is indeed a frame!
if ( index < args_in_frame ) {
result = frame->payload.stack_frame.arg[index];
} else {
struct pso_pointer p = frame->payload.stack_frame.more;
for ( int i = args_in_frame; i < index; i++ ) {
p = pointer_to_object( p)->payload.cons.cdr;
}
result = pointer_to_object( p)->payload.cons.car;
}
return result;
}