This once again does NOT compile. I've done work on macros; they don't work yet..

This commit is contained in:
Simon Brooke 2026-03-30 21:49:08 +01:00
parent e3f922a8bf
commit 2b22780ccf
86 changed files with 279 additions and 153 deletions

View file

@ -1,5 +1,5 @@
/*
* fopen.h
* io/fopen.h
*
* adapted from https://curl.haxx.se/libcurl/c/fopen.html.
*

122
src/c/io/print.c Normal file
View file

@ -0,0 +1,122 @@
/**
* io/print.c
*
* Post Scarcity Software Environment: print.
*
* Print basic Lisp objects..This is :bootstrap layer print; it needs to be
* able to print characters, symbols, integers, lists and dotted pairs. I
* don't think it needs to be able to print anything else.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* wide characters
*/
#include <wchar.h>
#include <wctype.h>
#include "io/fopen.h"
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/pso2.h"
#include "memory/tags.h"
#include "payloads/character.h"
#include "payloads/cons.h"
#include "payloads/integer.h"
struct pso_pointer in_print( pso_pointer p, URL_FILE * stream);
struct pso_pointer print_list_content( pso_pointer p, URL_FILE * stream) {
struct pso_pointer result = nil;
if (consp(p)) {
for (; consp( p); p = cdr(p)) {
stuct pso2* object = pointer_to_object(cursor);
result = in_print( object->payload.cons.car, stream);
if (exceptionp(result)) break;
switch (get_tag_value(object->payload.cons.cdr)) {
case NILTV :
break;
case CONSTV :
url_fputwc( L'\ ', output );
break;
default :
url_fputws( L" . ", output);
result = in_print( object->payload.cons.cdr, stream);
}
}
struct pso_pointer cdr = object->payload.cons.cdr;
switchb( get)
} else {
// TODO: return exception
}
return result;
}
struct pso_pointer in_print( pso_pointer p, URL_FILE * stream) {
stuct pso2* object = pointer_to_object(p);
struct pso_pointer result = nil;
if )object != NULL) {
switch (get_tag_value( p)) {
case CHARACTERTV :
url_fputwc( object->payload.character.character, output);
break;
case CONSTV :
url_fputwc( L'\(', output );
result = print_list_content( object, stream);
url_fputwc( L'\)', output );
break;
case INTEGERTV :
fwprintf( output, "%d", (int64_t)(object->payload.integer.value));
break;
case TRUETV :
url_fputwc( L'\t', output );
break;
case NILTV :
url_fputws( L"nil", output );
default :
// TODO: return exception
}
} else {
// TODO: return exception
}
return result;
}
/**
* @brief Simple print for bootstrap layer.
*
* @param p pointer to the object to print.
* @param stream if a pointer to an open write stream, print to there.
* @return struct pso_pointer `nil`, or an exception if some erroe occurred.
*/
struct pso_pointer print( pso_pointer p, pso_pointer stream) {
URL_FILE *output = writep( stream) ?
pointer_to_object( stream )->payload.stream.stream:
stdout;
if ( writep( stream)) { inc_ref( stream); }
struct pso_pointer result = in_print(p, output);
if ( writep( stream)) { dec_ref( stream); }
return result;
}

19
src/c/io/print.h Normal file
View file

@ -0,0 +1,19 @@
/**
* io/print.c
*
* Post Scarcity Software Environment: print.
*
* Print basic Lisp objects..This is :bootstrap layer print; it needs to be
* able to print characters, symbols, integers, lists and dotted pairs. I
* don't think it needs to be able to print anything else.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#ifndef __psse_io_print_h
#define __psse_io_print_h
struct pso_pointer print( pso_pointer p, pso_pointer stream);
#endif

0
src/c/io/read.h Normal file
View file

View file

@ -11,7 +11,9 @@
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include "debug.h"
#include "memory/memory.h"
#include "memory/node.h"
#include "memory/page.h"
@ -29,6 +31,8 @@
#include "memory/psod.h"
#include "memory/psoe.h"
#include "memory/psof.h"
#include "memory/tags.h"
#include "payloads/free.h"
/**

View file

@ -24,6 +24,8 @@
#include "memory/page.h"
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/tags.h"
#include "ops/truth.h"
/**
@ -171,20 +173,3 @@ void lock_object( struct pso_pointer pointer ) {
}
/**
* @brief Get the numeric value of the tag bytes of the object indicated
* by this pointer
*
* @param pointer a pointer to an object.
* @return the tag value of the object indicated.
*/
uint32_t get_tag_value( struct pso_pointer pointer ) {
struct pso2 *object = pointer_to_object( pointer );
uint32_t result = ( object->header.tag.value & 0xffffff );
if ( vectorpointp( pointer ) ) {
result = ( object->payload.vectorp.tag.value & 0xffffff );
}
return result;
}

View file

@ -251,6 +251,6 @@ struct pso_pointer inc_ref( struct pso_pointer pointer );
void lock_object( struct pso_pointer pointer);
uint32_t get_tag_value( struct pso_pointer pointer);
// uint32_t get_tag_value( struct pso_pointer pointer);
#endif

View file

@ -13,6 +13,8 @@
#include <stdint.h>
#include "memory/header.h"
#include "memory/tags.h"
#include "payloads/character.h"
#include "payloads/cons.h"
#include "payloads/free.h"

125
src/c/memory/tags.h Normal file
View file

@ -0,0 +1,125 @@
/**
* memory/tags.h
*
* Tags for all page space and vector objects known to the bootstrap layer.
*
* All macros!
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#ifndef __psse_memory_tags_h
#define __psse_memory_tags_h
#define TAGLENGTH 3
#define CONSTAG "CNS"
#define EXCEPTIONTAG "EXP"
#define FREETAG "FRE"
#define FUNCTIONTAG "FUN"
#define HASHTAG "HTB"
#define INTEGERTAG "INT"
#define KEYTAG "KEY"
#define LAMBDATAG "LMD"
#define LOOPTAG "LOP"
#define LAZYCONSTAG "LZY"
#define LAZYSTRTAG "LZS"
#define LAZYWRKRTAG "WRK"
#define MUTEXTAG "MTX"
#define NAMESPACETAG "NSP"
#define NILTAG "NIL"
#define NLAMBDATAG "NLM"
#define RATIOTAG "RAT"
#define READTAG "RED"
#define REALTAG "REA"
#define SPECIALTAG "SFM"
#define STACKTAG "STK"
#define STRINGTAG "STR"
#define SYMBOLTAG "SYM"
#define TIMETAG "TIM"
#define TRUETAG "TRU"
#define VECTORTAG "VEC"
#define VECTORPOINTTAG "VSP"
#define WRITETAG "WRT"
// TODO: all these tag values are WRONG, recalculate!
#define CONSTV 5459523
#define EXCEPTIONTV 5265477
#define FREETV 4543046
#define FUNCTIONTV 5133638
#define HASHTV 4346952
#define INTEGERTV 5525065
#define KEYTV 5850443
#define LAMBDATV 4345164
#define LOOPTV 5263180
#define MUTEXTV 5788749
#define NAMESPACETV 5264206
#define NILTV 4999502
#define NLAMBDATV 5065806
#define RATIOTV 5521746
#define READTV 4474194
#define REALTV 4277586
#define SPECIALTV 5064275
#define STACKTV 4936787
#define STRINGTV 5395539
#define SYMBOLTV 5069139
#define TIMETV 5065044
#define TRUETV 5591636
#define VECTORTV 4408662
#define VECTORPOINTTV 5264214
#define WRITETV 5264214
#define consp(p) (check_tag(p,CONSTV))
#define exceptionp(p) (check_tag(p,EXCEPTIONTV))
#define freep(p) (check_tag(p,FREETV))
#define functionp(p) (check_tag(p,FUNCTIONTV))
#define integerp(p) (check_tag(p,INTEGERTV))
#define keywordp(p) (check_tag(p,KEYTV))
#define lambdap(p) (check_tag(p,LAMBDATV))
#define loopp(p) (check_tag(p,LOOPTV))
#define namespacep(p)(check_tag(p,NAMESPACETV))
// the version of nilp in ops/truth.c is better than this, because it does not
// require a fetch, and will see nils curated by other nodes as nil.
// #define nilp(p) (check_tag(p,NILTV))
#define numberp(p) (check_tag(p,INTEGERTV)||check_tag(p,RATIOTV)||check_tag(p,REALTV))
#define ratiop(p) (check_tag(p,RATIOTV))
#define readp(p) (check_tag(p,READTV))
#define realp(p) (check_tag(p,REALTV))
#define sequencep(p) (check_tag(p,CONSTV)||check_tag(p,STRINGTV)||check_tag(p,SYMBOLTV))
#define specialp(p) (check_tag(p,SPECIALTV))
#define streamp(p) (check_tag(p,READTV)||check_tag(p,WRITETV))
#define stringp(p) (check_tag(p,STRINGTV))
#define symbolp(p) (check_tag(p,SYMBOLTV))
#define timep(p) (check_tag(p,TIMETV))
// the version of truep in ops/truth.c is better than this, because it does not
// require a fetch, and will see ntsils curated by other nodes as t.
// #define tp(p) (check_tag(p,TRUETV))
// #define truep(p) ( !check_tag(p,NILTV))
#define vectorpointp(p) (check_tag(p,VECTORPOINTTV))
#define vectorp(p) (check_tag(p,VECTORTV))
#define writep(p) (check_tag(p,WRITETV))
/**
* @brief return the numerical value of the tag of the object indicated by
* pointer `p`.
*
* @param p must be a struct pso_pointer, indicating the appropriate object.
*
* @return the numerical value of the tag, as a uint32_t.
*/
#define get_tag_value(p)((pointer_to_object(p)->header.tag.value) & 0xffffff)
/**
* @brief check that the tag of the object indicated by this poiner has this
* value.
*
* @param p must be a struct pso_pointer, indicating the appropriate object.
* @param v should be an integer, ideally uint32_t, the expected value of a tag.
*
* @return true if the tag at p matches v, else false.
*/
#define check_tag(p,v) (get_tag_value(p) == v)
#endif

View file

@ -11,6 +11,8 @@
#include "memory/pointer.h"
#include "memory/pso4.h"
#include "memory/tags.h"
#include "payloads/cons.h"
#include "payloads/exception.h"
#include "payloads/function.h"

View file

@ -13,6 +13,7 @@
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/pso2.h"
#include "memory/tags.h"
#include "payloads/cons.h"
/**
@ -36,17 +37,6 @@ struct pso_pointer cons( struct pso_pointer car, struct pso_pointer cdr ) {
return result;
}
/**
* @brief return true if `ptr` indicates a cons cell, else false.
*
* @param ptr a pointer.
* @return true if `ptr` indicates a cons cell.
* @return false otherwise
*/
bool consp( struct pso_pointer ptr ) {
// TODO: make it actually work!
return false;
}
/**
* @brief return the car of this cons cell.

View file

@ -13,11 +13,6 @@
#include "memory/pointer.h"
/**
* An ordinary cons cell:
*/
#define CONSTAG "CNS"
#define CONSTV 5459523
/**
* @brief A cons cell.

View file

@ -12,10 +12,3 @@
#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 );
}

View file

@ -13,9 +13,6 @@
#include "memory/pointer.h"
#define EXCEPTIONTAG "EXP"
#define EXCEPTIONTV 5265477
/**
* @brief An exception; required three pointers, so use object of size class 3.
*/
@ -28,6 +25,4 @@ struct exception_payload {
struct pso_pointer cause;
};
bool exceptionp( struct pso_pointer p );
#endif

View file

@ -12,12 +12,6 @@
#include "memory/pointer.h"
/**
* @brief Tag for an unassigned object; may be of any size class.
*/
#define FREETAG "FRE"
#define FREETV 4543046
/**
* @brief An unassigned object, on a freelist; may be of any size class.
*

View file

@ -13,14 +13,6 @@
#include "memory/pointer.h"
#include "memory/pso4.h"
/**
* @brief Tag for an ordinary Lisp function - one whose arguments are pre-evaluated.
* \see LAMBDATAG for interpretable functions.
* \see SPECIALTAG for functions whose arguments are not pre-evaluated.
*/
#define FUNCTIONTAG "FUN"
#define FUNCTIONTV 5133638
/**
* @brief Payload of a function cell.
* `source` points to the source from which the function was compiled, or NIL

View file

@ -32,13 +32,6 @@
#include "memory/pointer.h"
/**
* @brief Tag for an ordinary Lisp hashtable - one whose contents are immutable.
* \see NAMESPACETAG for mutable hashtables.
*/
#define HASHTABLETAG "HTB"
#define HASHTABLETV 4346952
/**
* The payload of a hashtable. The number of buckets is assigned at run-time,
* and is stored in n_buckets. Each bucket is something ASSOC can consume:

View file

@ -12,9 +12,6 @@
#include <stdint.h>
#define INTEGERTAG "INT"
#define INTEGERTV 5525065
/**
* @brief An integer .
*

View file

@ -12,12 +12,6 @@
#include "memory/pointer.h"
/**
* Tag for a keyword - an interned, self-evaluating string.
*/
#define KEYTAG "KEY"
#define KEYTV 5850443
/* 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. */

View file

@ -14,14 +14,6 @@
#include "memory/pointer.h"
/**
* @brief Tag for mutex cell. mutexes are thread-safe locks, required by
* mutable objects.
* \see FUNCTIONTAG.
*/
#define MUTEXTAG "MTX"
#define MUTEXTV 5788749
/**
* @brief payload for mutex objects.
*

View file

@ -35,13 +35,6 @@
#include "memory/pointer.h"
/**
* @brief Tag for a Lisp namespace - a hashtable whose contents are mutable.
* \see HASHTABLETAG for mutable hashtables.
*/
#define NAMESPACETAG "NSP"
#define NAMESPACETV 5264206
/**
* The payload of a namespace. The number of buckets is assigned at run-time,
* and is stored in n_buckets. Each bucket is something ASSOC can consume:

View file

@ -12,12 +12,6 @@
#include "memory/pointer.h"
/**
* An ordinary nlambda cell:
*/
#define NLAMBDATAG "NLM"
#define NLAMBDATV 5065806
/* nlambda shares a payload with lambda */
#endif

View file

@ -17,13 +17,6 @@
#include "memory/pointer.h"
/**
* @brief Tag for string of characters, organised as a linked list.
*/
#define STRINGTAG "STR"
#define STRINGTV 5395539
/**
* @brief payload of a string cell.
*

View file

@ -17,12 +17,6 @@
#include "io/fopen.h"
#include "memory/pointer.h"
/**
* An open read stream.
*/
#define READTAG "REA"
#define READTV 4277586
/**
* payload of a read or write stream cell.
*/

View file

@ -21,7 +21,5 @@
* provided.
* \see NLAMBDATAG.
*/
#define SPECIALTAG "SFM"
#define SPECIALTV 5064275
#endif

View file

@ -13,10 +13,6 @@
#define __psse_payloads_stack_h
#include "memory/pointer.h"
// #include "memory/pso4.h"
#define STACKTAG "STK"
#define STACKTV 4936787
/*
* number of arguments stored in a stack frame

View file

@ -12,13 +12,6 @@
#include "memory/pointer.h"
/**
* Tag for a symbol: just like a keyword except not self-evaluating.
*/
#define SYMBOLTAG "SYM"
#define SYMBOLTV 5069139
/* 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. */

View file

@ -1,18 +0,0 @@
/**
* payloads/vector_pointer.c
*
* A pointer to an object in vector space.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include <stdbool.h>
#include "memory/pointer.h"
#include "memory/pso.h"
#include "payloads/vector_pointer.h"
bool vectorpointp( struct pso_pointer p ) {
return ( get_tag_value( p ) == VECTORPOINTTV );
}

View file

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

View file

@ -10,14 +10,5 @@
#ifndef __psse_payloads_write_stream_h
#define __psse_payloads_write_stream_h
#include "io/fopen.h"
#include "memory/pointer.h"
/**
* @brief Tag for an open write stream.
*/
#define WRITETAG "WRT"
#define WRITETV 5264214
/* write stream shares a payload with /see read_streem.h */
#endif

View file

Can't render this file because it has a wrong number of fields in line 2.