My monster, it not only compiles, it now runs!

This commit is contained in:
Simon Brooke 2026-03-30 11:52:41 +01:00
parent 60921be3d4
commit a8b4a6e69d
26 changed files with 244 additions and 172 deletions

View file

@ -23,15 +23,15 @@
* @param cdr the pointer which should form the cdr of this cons cell.
* @return struct pso_pointer a pointer to the newly allocated cons cell.
*/
struct pso_pointer cons( struct pso_pointer car, struct pso_pointer cdr) {
struct pso_pointer result = allocate( CONSTAG, 2);
struct pso_pointer cons( struct pso_pointer car, struct pso_pointer cdr ) {
struct pso_pointer result = allocate( CONSTAG, 2 );
struct pso2 *object = pointer_to_object( result );
object->payload.cons.car = car;
object->payload.cons.cdr = cdr;
inc_ref( car);
inc_ref( cdr);
inc_ref( car );
inc_ref( cdr );
return result;
}
@ -43,7 +43,7 @@ struct pso_pointer cons( struct pso_pointer car, struct pso_pointer cdr) {
* @return true if `ptr` indicates a cons cell.
* @return false otherwise
*/
bool consp( struct pso_pointer ptr) {
bool consp( struct pso_pointer ptr ) {
// TODO: make it actually work!
return false;
}
@ -55,11 +55,11 @@ bool consp( struct pso_pointer ptr) {
* @return the car of the indicated cell.
* @exception if the pointer does not indicate a cons cell.
*/
struct pso_pointer car( struct pso_pointer cons) {
struct pso_pointer car( struct pso_pointer cons ) {
struct pso_pointer result = nil;
struct pso2 *object = pointer_to_object( result );
if ( consp( cons)) {
if ( consp( cons ) ) {
result = object->payload.cons.car;
}
// TODO: else throw an exception
@ -74,14 +74,14 @@ struct pso_pointer car( struct pso_pointer cons) {
* @return the cdr of the indicated cell.
* @exception if the pointer does not indicate a cons cell.
*/
struct pso_pointer cdr( struct pso_pointer cons) {
struct pso_pointer cdr( struct pso_pointer cons ) {
struct pso_pointer result = nil;
struct pso2 *object = pointer_to_object( result );
if ( consp( cons)) {
if ( consp( cons ) ) {
result = object->payload.cons.cdr;
}
// TODO: else throw an exception
return result;
}
}

View file

@ -30,12 +30,12 @@ struct cons_payload {
struct pso_pointer cdr;
};
struct pso_pointer car( struct pso_pointer cons);
struct pso_pointer car( struct pso_pointer cons );
struct pso_pointer cdr( struct pso_pointer cons);
struct pso_pointer cdr( struct pso_pointer cons );
struct pso_pointer cons( struct pso_pointer car, struct pso_pointer cdr);
struct pso_pointer cons( struct pso_pointer car, struct pso_pointer cdr );
bool consp( struct pso_pointer ptr);
bool consp( struct pso_pointer ptr );
#endif

View file

@ -1,13 +1,21 @@
/**
* payloads/exception.c
*
* An exception; required three pointers, so use object of size class 3.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#import "memory/pointer.h"
#import "memory/pso.h"
#import "payloads/exception.h"
#include "memory/pointer.h"
#include "memory/pso.h"
#include "payloads/exception.h"
/**
* @param p a pointer to an object.
* @return true if that object is an exception, else false.
*/
bool exceptionp( struct pso_pointer p) {
return (get_tag_value( p) == EXCEPTIONTV);
bool exceptionp( struct pso_pointer p ) {
return ( get_tag_value( p ) == EXCEPTIONTV );
}

View file

@ -28,6 +28,6 @@ struct exception_payload {
struct pso_pointer cause;
};
bool exceptionp( struct pso_pointer p);
bool exceptionp( struct pso_pointer p );
#endif

View file

@ -41,9 +41,9 @@ struct function_payload {
* a cons pointer (representing its result).
* \todo check this documentation is current!
*/
struct pso_pointer ( *executable ) ( struct pso4*,
struct pso_pointer,
struct pso_pointer );
struct pso_pointer ( *executable ) ( struct pso4 *,
struct pso_pointer,
struct pso_pointer );
};
#endif

View file

@ -45,11 +45,11 @@
* i.e. either an assoc list or a further hashtable.
*/
struct hashtable_payload {
struct pso_pointer hash_fn; /* function for hashing values in this hashtable, or `NIL` to use
the default hashing function */
uint32_t n_buckets; /* number of hash buckets */
struct pso_pointer buckets[]; /* actual hash buckets, which should be `NIL`
* or assoc lists or (possibly) further hashtables. */
struct pso_pointer hash_fn; /* function for hashing values in this hashtable, or `NIL` to use
the default hashing function */
uint32_t n_buckets; /* number of hash buckets */
struct pso_pointer buckets[]; /* actual hash buckets, which should be `NIL`
* or assoc lists or (possibly) further hashtables. */
};
#endif

View file

@ -32,7 +32,7 @@ struct mutex_payload {
pthread_mutex_t mutex;
};
struct pso_pointer make_mutex();
struct pso_pointer make_mutex( );
/**
* @brief evaluates these forms within the context of a thread-safe lock.
@ -50,7 +50,8 @@ struct pso_pointer make_mutex();
* @param forms a list of arbitrary Lisp forms.
* @return struct pso_pointer the result.
*/
struct pso_pointer with_lock( struct pso_pointer lock, struct pso_pointer forms);
struct pso_pointer with_lock( struct pso_pointer lock,
struct pso_pointer forms );
/**
* @brief as with_lock, q.v. but attempts to obtain a lock and returns an
@ -64,6 +65,7 @@ struct pso_pointer with_lock( struct pso_pointer lock, struct pso_pointer forms)
* @param forms a list of arbitrary Lisp forms.
* @return struct pso_pointer the result.
*/
struct pso_pointer attempt_with_lock( struct pso_pointer lock, struct pso_pointer forms);
struct pso_pointer attempt_with_lock( struct pso_pointer lock,
struct pso_pointer forms );
#endif

View file

@ -48,17 +48,17 @@
* i.e. either an assoc list or a further namespace.
*/
struct namespace_payload {
struct pso_pointer hash_fn; /* function for hashing values in this namespace, or
* `NIL` to use the default hashing function */
uint32_t n_buckets; /* number of hash buckets */
uint32_t unused; /* for word alignment and possible later expansion */
struct pso_pointer write_acl; /* it seems to me that it is likely that the
* principal difference between a hashtable and a
* namespace is that a hashtable has a write ACL
* of `NIL`, meaning not writeable by anyone */
struct pso_pointer mutex; /* the mutex to lock when modifying this namespace.*/
struct pso_pointer buckets[]; /* actual hash buckets, which should be `NIL`
* or assoc lists or (possibly) further hashtables. */
struct pso_pointer hash_fn; /* function for hashing values in this namespace, or
* `NIL` to use the default hashing function */
uint32_t n_buckets; /* number of hash buckets */
uint32_t unused; /* for word alignment and possible later expansion */
struct pso_pointer write_acl; /* it seems to me that it is likely that the
* principal difference between a hashtable and a
* namespace is that a hashtable has a write ACL
* of `NIL`, meaning not writeable by anyone */
struct pso_pointer mutex; /* the mutex to lock when modifying this namespace. */
struct pso_pointer buckets[]; /* actual hash buckets, which should be `NIL`
* or assoc lists or (possibly) further hashtables. */
};
#endif

View file

@ -1,42 +0,0 @@
/**
* 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/pso2.h"
#include "memory/pso4.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;
}

View file

@ -13,7 +13,7 @@
#define __psse_payloads_stack_h
#include "memory/pointer.h"
#include "memory/pso4.h"
// #include "memory/pso4.h"
#define STACKTAG "STK"
#define STACKTV 4936787
@ -23,13 +23,6 @@
*/
#define args_in_frame 8
/**
* @brief The maximum depth of stack before we throw an exception.
*
* `0` is interpeted as `unlimited`.
*/
extern uint32_t stack_limit;
/**
* A stack frame.
*/
@ -48,6 +41,4 @@ struct stack_frame_payload {
uint32_t depth;
};
struct pso_pointer fetch_arg( struct pso4 *frame, unsigned int index );
#endif

View file

@ -13,6 +13,6 @@
#include "memory/pso.h"
#include "payloads/vector_pointer.h"
bool vectorpointp( struct pso_pointer p) {
return (get_tag_value( p) == VECTORPOINTTV);
bool vectorpointp( struct pso_pointer p ) {
return ( get_tag_value( p ) == VECTORPOINTTV );
}

View file

@ -39,6 +39,6 @@ struct vectorp_payload {
void *address;
};
bool vectorpointp( struct pso_pointer p);
bool vectorpointp( struct pso_pointer p );
#endif