Added character as a first class object. Stepped through a run; it all works.

This commit is contained in:
Simon Brooke 2026-03-30 13:29:26 +01:00
parent a8b4a6e69d
commit e3f922a8bf
5 changed files with 52 additions and 26 deletions

View file

@ -12,8 +12,8 @@
#include <stdint.h>
#include "../payloads/psse-string.h"
#include "memory/header.h"
#include "payloads/character.h"
#include "payloads/cons.h"
#include "payloads/free.h"
#include "payloads/function.h"
@ -22,9 +22,9 @@
#include "payloads/lambda.h"
#include "payloads/nlambda.h"
#include "payloads/read_stream.h"
#include "payloads/special.h"
#include "payloads/psse-string.h"
#include "payloads/symbol.h"
// #include "payloads/time.h"
#include "payloads/time.h"
#include "payloads/vector_pointer.h"
#include "payloads/write_stream.h"
@ -38,13 +38,16 @@ struct pso2 {
union {
char bytes[16];
uint64_t words[2];
struct character_payload character;
struct cons_payload cons;
struct free_payload free;
struct function_payload function;
struct integer_payload integer;
struct lambda_payload lambda;
// struct special_payload special;
struct function_payload special;
struct stream_payload stream;
struct string_payload string;
// TODO: this isn't working and I don't know why (error: field time has incomplete type)
// struct time_payload time;
struct vectorp_payload vectorp;
} payload;

View file

@ -0,0 +1,39 @@
/**
* payloads/character.h
*
* A character object.
*
* Note that, instead of instantiating actual character objects, it would be
* possible to reserve one special page index, outside the normal page range,
* possibly even page 0, such that a character would be represented by a
* pso_pointer {node, special_page, character_code}. The special page wouldn't
* actually have to exist. This wouldn't prevent `nil` being 'the object at
* {n, 0, 0}, since the UTF character with the index 0 is NULL, which feels
* entirely compatible. UTF 1 is 'Start of heading', which is not used by
* anything I'm aware of these days, and is canonically not NULL, so I don't
* see why we should not continue to treat {n, 0, 1} as `t`.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#ifndef __psse_payloads_character_h
#define __psse_payloads_character_h
/*
* wide characters
*/
#include <wchar.h>
#include <wctype.h>
#define CHARTAG "CHR"
#define CHARTV 5392451
/**
* @brief a single character, as returned by the reader.
*/
struct character_payload {
wchar_t character;
};
#endif

View file

@ -3,6 +3,9 @@
*
* A special form.
*
* No payload here; it would be identical to function_payload, q.v., so
* use that instead.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
@ -21,25 +24,4 @@
#define SPECIALTAG "SFM"
#define SPECIALTV 5064275
// /**
// * @brief Payload of a special form cell.
// *
// * Currently identical to the payload of a function cell.
// * \see function_payload
// */
// struct special_payload {
// /**
// * pointer to the source from which the special form was compiled, or NIL
// * if it is a primitive.
// */
// struct pso_pointer meta;
// /** pointer to a function which takes a cons pointer (representing
// * its argument list) and a cons pointer (representing its environment) and a
// * stack frame (representing the previous stack frame) as arguments and returns
// * a cons pointer (representing its result). */
// struct pso_pointer ( *executable ) ( struct pso4*,
// struct pso_pointer,
// struct pso_pointer );
// };
#endif

View file

@ -10,7 +10,9 @@
#ifndef __psse_payloads_cons_h
#define __psse_payloads_cons_h
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include "memory/pointer.h"
@ -26,7 +28,7 @@
* convenience, 14Bn years before 1st Jan 1970 (the UNIX epoch))
*/
struct time_payload {
unsigned __int128_t value;
unsigned __int128 value;
};
#endif

Binary file not shown.