Still doesn't compile, but I think excellent progress.

This commit is contained in:
Simon Brooke 2026-04-28 11:54:15 +01:00
parent dbeb99759a
commit aac4669a3d
34 changed files with 1128 additions and 673 deletions

View file

@ -49,7 +49,7 @@ struct pso_pointer make_cons( struct pso_pointer frame_pointer,
*/
#define make_cons2(car,cdr) (cons(make_frame(2, frame_pointer, car, cdr)))
#define c_car(p)(consp(p) ? pointer_to_object(p)->payload.cons.car : nil)
#define c_cdr(p)(consp(p) ? pointer_to_object(p)->payload.cons.cdr : nil)
#define c_car(p)(sequencep(p) ? pointer_to_object(p)->payload.cons.car : nil)
#define c_cdr(p)(sequencep(p) ? pointer_to_object(p)->payload.cons.cdr : nil)
#endif

View file

@ -15,6 +15,8 @@
#include <wctype.h>
#include "debug.h"
#include "environment/privileged_keywords.h"
#include "memory/node.h"
#include "memory/pointer.h"
#include "memory/pso.h"
@ -26,6 +28,7 @@
#include "ops/stack_ops.h"
#include "ops/truth.h"
#include "payloads/cons.h"
#include <stdlib.h>
#include <stdlib.h>
#include <stdlib.h>
@ -92,3 +95,71 @@ struct pso_pointer destroy_exception( struct pso_pointer fp ) {
return nil;
}
/**
* Throw an exception with a cause.
* `throw_exception` is a misnomer, because it doesn't obey the calling signature of a
* lisp function; but it is nevertheless to be preferred to make_exception. A
* real `throw_exception`, which does, will be needed.
* object pointing to it. Then this should become a normal lisp function
* which expects a normally bound frame and environment, such that
* frame->payload.stack_frame.arg[0] is the payload, frame->payload.stack_frame.arg[1] is the cause, and frame->payload.stack_frame.arg[2] is the cons-space
* pointer to the frame in which the exception occurred.
*/
struct pso_pointer throw_exception_with_cause( struct pso_pointer location,
struct pso_pointer message,
struct pso_pointer cause,
struct pso_pointer
frame_pointer ) {
struct pso_pointer result = nil;
#ifdef DEBUG
debug_print( U"\nERROR: `", DEBUG_ANY, 0 );
debug_print_object( message, DEBUG_ANY, 0 );
debug_print( U"` at `", DEBUG_ANY, 0 );
debug_print_object( location, DEBUG_ANY, 0 );
debug_print( U"`\n", DEBUG_ANY, 0 );
if ( !c_nilp( cause ) ) {
debug_print( U"\tCaused by: ", DEBUG_ANY, 0 );
debug_print_object( cause, DEBUG_ANY, 0);
debug_print( U"`\n", DEBUG_ANY, 0 );
}
#endif
struct pso2 *cell = pointer_to_object( message );
if (get_tag_value( message)) {
result = message;
} else {
struct pso_pointer x_frame = inc_ref(make_frame(
2, frame_pointer, message,
(nilp(location)
? nil
: make_cons(frame_pointer,
make_cons(frame_pointer,
privileged_keyword_location, location),
nil)),
cause));
result = push_local(frame_pointer, make_exception(x_frame));
}
return result;
}
/**
* Throw an exception.
* `throw_exception` is a misnomer, because it doesn't obey the calling signature of a
* lisp function; but it is nevertheless to be preferred to make_exception. A
* real `throw_exception`, which does, will be needed.
* object pointing to it. Then this should become a normal lisp function
* which expects a normally bound frame and environment, such that
* frame->payload.stack_frame.arg[0] is the payload, frame->payload.stack_frame.arg[1] is the cause, and frame->payload.stack_frame.arg[2] is the cons-space
* pointer to the frame in which the exception occurred.
*/
struct pso_pointer
throw_exception( struct pso_pointer location,
struct pso_pointer payload,
struct pso_pointer frame_pointer ) {
return throw_exception_with_cause( location, payload, nil, frame_pointer );
}

View file

@ -30,7 +30,6 @@ struct function_payload {
*/
struct pso_pointer meta;
#ifdef MANAGED_POINTER_ONLY
/**
* pointer to a C function which takes a managed pointer to the same stack
* frame and a managed pointer to the environment as arguments. Arguments
@ -38,16 +37,6 @@ struct function_payload {
* invocation.
*/
struct pso_pointer ( *executable ) ( struct pso_pointer frame_pointer );
#else
/**
* pointer to a C function which takes an unmanaged pointer to a stack frame,
* a managed pointer to the same stack frame, and a managed pointer to the
* environment as arguments. Arguments to the Lisp function are assumed to be
* loaded into the frame before invocation.
*/
struct pso_pointer ( *executable ) ( struct pso4 * frame,
struct pso_pointer frame_pointer );
#endif
};
#endif

27
src/c/payloads/keyword.c Normal file
View file

@ -0,0 +1,27 @@
/**
* keyword.c
*
* Post Scarcity Soctware Environment
*
* TODO: Edit purpose.
*
* Copyright (c): 27 Apr 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include "memory/pointer.h"
#include "memory/tags.h"
#include "ops/string_ops.h"
/**
* Construct a keyword from the character `c` and this `tail`. A string is
* implemented as a flat list of cells each of which has one character and a
* pointer to the next; in the last cell the pointer to next is NIL.
*
* @param c the character to add (prepend);
* @param tail the keyword which is being built.
*/
struct pso_pointer make_keyword( struct pso_pointer frame_pointer, wint_t c,
struct pso_pointer tail ) {
return make_string_like_thing( frame_pointer, c, tail, KEYTAG );
}

View file

@ -11,9 +11,13 @@
#define __psse_payloads_keyword_h
#include "memory/pointer.h"
#include <wctype.h>
/* TODO: for now, Keyword shares a payload with String, but this may change.
* Strings are of indefinite length, but keywords are really not, and might
* fit into any size class. */
struct pso_pointer make_keyword( struct pso_pointer frame_pointer, wint_t c,
struct pso_pointer tail );
#endif

24
src/c/payloads/lambda.c Normal file
View file

@ -0,0 +1,24 @@
/**
* lambda.c
*
* Post Scarcity Soctware Environment
*
* TODO: Edit purpose.
*
* Copyright (c): 27 Apr 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/pso2.h"
struct pso_pointer make_lambda_like_thing(struct pso_pointer frame_pointer,
struct pso_pointer args,
struct pso_pointer body, char *tag) {
struct pso_pointer result = allocate(frame_pointer, tag, 2);
struct pso2 *object = pointer_to_object(result);
object->payload.lambda.args = args;
object->payload.lambda.body = body;
}

View file

@ -11,6 +11,7 @@
#define __psse_payloads_lambda_h
#include "memory/pointer.h"
#include "memory/tags.h"
/**
* @brief Tag for lambda cell. Lambdas are the interpretable (source) versions of functions.
@ -29,5 +30,9 @@ struct lambda_payload {
struct pso_pointer body;
};
struct pso_pointer make_lambda_like_thing(struct pso_pointer frame_pointer,
struct pso_pointer args,
struct pso_pointer body, char *tag);
#define make_lambda(f,a,b) (make_lambda_like_thing( f, a, b, LAMBDATAG))
#endif

View file

@ -11,7 +11,11 @@
#define __psse_payloads_nlambda_h
#include "memory/pointer.h"
#include "memory/tags.h"
#include "payloads/lambda.h"
/* nlambda shares a payload with lambda */
#define make_nlambda(f,a,b)(make_lambda_like_thing(f, a, b, NLAMBDATAG))
#endif

View file

@ -0,0 +1,33 @@
/**
* packed_string.h
*
* Post Scarcity Soctware Environment
*
* The idea of a packed string is that it is an array of wide characters,
* packed into a paged space object. Any size of paged space object may be
* used.
*
* The initial inspiration is I wanted to use swprintf to produce formatted
* strings. Eventually, we will have a `format` function in Lisp similar to
* Common Lisp's or Clojure's, so this issue will go away. But it may still
* be useful to have an array of character as an explicit type.
*
* Copyright (c): 22 Apr 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#ifndef SRC_C_PAYLOADS_PACKED_STRING_H_
#define SRC_C_PAYLOADS_PACKED_STRING_H_
#include <stdint.h>
/*
* wide characters
*/
#include <wchar.h>
struct packed_string_payload {
uint32_t length; /* number of characters */
wchar_t chars[]; /* actual characters. */
};
#endif /* SRC_C_PAYLOADS_PACKED_STRING_H_ */

View file

@ -20,11 +20,25 @@
#include "memory/pso4.h"
#include "memory/tags.h"
#include "ops/string_ops.h"
#include "payloads/cons.h"
#include "ops/stack_ops.h"
/**
* Construct a string from the character `c` and this `tail`. A string is
* implemented as a flat list of cells each of which has one character and a
* pointer to the next; in the last cell the pointer to next is NIL.
*
* @param c the character to add (prepend);
* @param tail the string which is being built.
*/
struct pso_pointer make_string( struct pso_pointer frame_pointer, wint_t c,
struct pso_pointer tail ) {
return make_string_like_thing( frame_pointer, c, tail, STRINGTAG );
}
/**
* @brief When an string is freed, its cdr pointer must be decremented.
*

View file

@ -33,6 +33,9 @@ struct string_payload {
struct pso_pointer cdr;
};
struct pso_pointer make_string( struct pso_pointer frame_pointer, wint_t c,
struct pso_pointer tail );
struct pso_pointer destroy_string( struct pso_pointer fp );
#endif

29
src/c/payloads/symbol.c Normal file
View file

@ -0,0 +1,29 @@
/**
* symbol.c
*
* Post Scarcity Soctware Environment
*
* TODO: Edit purpose.
*
* Copyright (c): 27 Apr 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include <wctype.h>
#include "memory/pointer.h"
#include "memory/tags.h"
#include "ops/string_ops.h"
/**
* Construct a symbol from the character `c` and this `tail`. A string is
* implemented as a flat list of cells each of which has one character and a
* pointer to the next; in the last cell the pointer to next is NIL.
*
* @param c the character to add (prepend);
* @param tail the symbol which is being built.
*/
struct pso_pointer make_symbol( struct pso_pointer frame_pointer, wint_t c,
struct pso_pointer tail ) {
return make_string_like_thing( frame_pointer, c, tail, SYMBOLTAG );
}

View file

@ -10,10 +10,15 @@
#ifndef __psse_payloads_symbol_h
#define __psse_payloads_symbol_h
#include <wctype.h>
#include "memory/pointer.h"
/* TODO: for now, Symbol shares a payload with String, but this may change.
* Strings are of indefinite length, but symbols are really not, and might
* fit into any size class. */
struct pso_pointer make_symbol( struct pso_pointer frame_pointer, wint_t c,
struct pso_pointer tail );
#endif