diff --git a/docs/Home.md b/docs/Home.md index 8937653..b4dfc0e 100644 --- a/docs/Home.md +++ b/docs/Home.md @@ -1,6 +1,6 @@ # Post Scarcity Software Environment: general documentation -Work towards the implementation of a software system for the hardware of the deep future. +Work towards the implementation of a software system like that described in [Post Scarcity Software](https://www.journeyman.cc/blog/posts-output/2006-02-20-postscarcity-software/). ## Note on canonicity @@ -12,7 +12,7 @@ You can read about the current [state of play](State-of-play.md). ## Roadmap -There is now a [roadmap](https://www.journeyman.cc/post-scarcity/html/md_workspace_2post-scarcity_2docs_2_roadmap.html) for the project. +There is now a [roadmap](Roadmap.md) for the project. ## AWFUL WARNING 1 diff --git a/docs/State-of-play.md b/docs/State-of-play.md index 393f1aa..ffa4e79 100644 --- a/docs/State-of-play.md +++ b/docs/State-of-play.md @@ -1,12 +1,5 @@ # State of Play -## 20260326 - -Most of the memory architecture of the new prototype is now roughed out, but -in C, not in a more modern language. It doesn't compile yet. - -My C is getting better... but it needed to! - ## 20260323 I started an investigastion of the [Zig language](https://ziglang.org/) and diff --git a/src/c/arith/READMDE.md b/src/c/arith/READMDE.md deleted file mode 100644 index f59b772..0000000 --- a/src/c/arith/READMDE.md +++ /dev/null @@ -1,24 +0,0 @@ -# README: PSSE substrate arithmetic - -This folder/pseudo package is to implement enough of arithmetic for bootstrap: -that is, enough that all more sophisticated arithmetic can be built on top of -it. - -Ratio arithmetic will not be implemented in the substrate, but `make-ratio` -will. The signature for `make-ratio` will be: - -`(make-ratio dividend divisor) => ratio` - -Both divisor and dividend should be integers. If the divisor is `1` it will -return the dividend (as an integer). If the divisor is 0 it will return ∞. - -This implies we need a privileged data item representing infinity... - -Bignum arithmetic will not be implemented in the substrate, but `make-bignum` -will be. The signature for `make-bignum` will be - -`(make-bignum integer) => bignum` - -If the integer argument is less than 64 bits, the argument will be returned -unmodified. If it is more than 64 bits, a bignum of the same value will be -returned. \ No newline at end of file diff --git a/src/c/debug.c b/src/c/debug.c deleted file mode 100644 index 2bd417d..0000000 --- a/src/c/debug.c +++ /dev/null @@ -1,16 +0,0 @@ -/** - * debug.h - * - * Post Scarcity Software Environment: entry point. - * - * Print debugging output. - * - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - - #include "debug.h" - - int verbosity = 0; - \ No newline at end of file diff --git a/src/c/debug.h b/src/c/debug.h deleted file mode 100644 index deb4487..0000000 --- a/src/c/debug.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * debug.h - * - * Post Scarcity Software Environment: entry point. - * - * Print debugging output. - * - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#ifndef __psse_debug_h -#define __psse_debug_h -#include -#include -#include - -/** - * @brief Print messages debugging memory allocation. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_ALLOC 1 - -/** - * @brief Print messages debugging arithmetic operations. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_ARITH 2 - -/** - * @brief Print messages debugging symbol binding. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_BIND 4 - -/** - * @brief Print messages debugging bootstrapping and teardown. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_BOOTSTRAP 8 - -/** - * @brief Print messages debugging evaluation. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_EVAL 16 - -/** - * @brief Print messages debugging input/output operations. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_IO 32 - -/** - * @brief Print messages debugging lambda functions (interpretation). - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_LAMBDA 64 - -/** - * @brief Print messages debugging the read eval print loop. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_REPL 128 - -/** - * @brief Print messages debugging stack operations. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_STACK 256 - -/** - * @brief Print messages about equality tests. - * - * Flag interpretation for the value of `verbosity`, defined in `debug.c`, q.v. - */ -#define DEBUG_EQUAL 512 - -/** - * @brief Verbosity (and content) of debugging output - * - * Interpreted as a sequence of topic-specific flags, see above. - */ -extern int verbosity; - -#endif \ No newline at end of file diff --git a/src/c/memory/memory.c b/src/c/memory/memory.c deleted file mode 100644 index 4a365e3..0000000 --- a/src/c/memory/memory.c +++ /dev/null @@ -1,19 +0,0 @@ -/** - * memory/memory.c - * - * The memory management subsystem. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include - -#include "memory/pointer.h" - - - -int initialise_memory( int node) { - fprintf( stderr, "TODO: Implement initialise_memory()"); - - } \ No newline at end of file diff --git a/src/c/memory/memory.h b/src/c/memory/memory.h deleted file mode 100644 index 37bd39c..0000000 --- a/src/c/memory/memory.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * memory/memory.h - * - * The memory management subsystem. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#ifndef __psse_memory_memory_h -#define __psse_memory_memory_h - -#include "memory/pointer.h" - -int initialise_memory(); - -extern struct pso_pointer out_of_memory_exception; - -#endif diff --git a/src/c/memory/node.c b/src/c/memory/node.c deleted file mode 100644 index efbb9d4..0000000 --- a/src/c/memory/node.c +++ /dev/null @@ -1,55 +0,0 @@ -/** - * memory/node.c - * - * Top level data about the actual node on which this memory system sits. - * May not belong in `memory`. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include "memory/memory.h" -#include "memory/pointer.h" - -/** - * @brief Flag to prevent the node being initialised more than once. - * - */ -bool node_initialised = false; - -/** - * @brief The index of this node in the hypercube. - * - */ -uint32_t node_index = 0; - -/** - * @brief The canonical `nil` pointer - * - */ -struct pso_pointer nil = struct pso_pointer{ 0, 0, 0}; - -/** - * @brief the canonical `t` (true) pointer. - * - */ -struct pso_pointer t = struct pso_pointer{ 0, 0, 1}; - -/** - * @brief Set up the basic informetion about this node - * - * @param index - * @return struct pso_pointer - */ -struct pso_pointer initialise_node( uint32_t index) { - node_index = index; - nil = pso_pointer{ index, 0, 0}; - t = pso_pointer( index, 0, 1); - pso_pointer result = initialise_memory(index); - - if ( eq( result, t)) { - result = initialise_environment(); - } - - return result; -} diff --git a/src/c/memory/node.h b/src/c/memory/node.h deleted file mode 100644 index cae61e6..0000000 --- a/src/c/memory/node.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * memory/node.h - * - * Top level data about the actual node on which this memory system sits. - * May not belong in `memory`. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#ifndef __psse_memory_node_h -#define __psse_memory_node_h - - -/** - * @brief The index of this node in the hypercube. - * - */ -extern int node_index; - -/** - * @brief The canonical `nil` pointer - * - */ -extern struct pso_pointer nil; - -/** - * @brief the canonical `t` (true) pointer. - * - */ -extern struct pso_pointer t; - -#endif diff --git a/src/c/memory/page.c b/src/c/memory/page.c deleted file mode 100644 index 4b9fe0f..0000000 --- a/src/c/memory/page.c +++ /dev/null @@ -1,36 +0,0 @@ -/** - * memory/page.c - * - * Page for paged space psoects. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include - -#include "memory/page.h" -#include "memory/pso2.h" -#include "memory/pso3.h" -#include "memory/pso4.h" -#include "memory/pso5.h" -#include "memory/pso6.h" -#include "memory/pso7.h" -#include "memory/pso8.h" -#include "memory/pso9.h" -#include "memory/psoa.h" -#include "memory/psob.h" -#include "memory/psoc.h" -#include "memory/psod.h" -#include "memory/psoe.h" -#include "memory/psof.h" - -void * malloc_page( uint8_t size_class) { - void * result = malloc( sizeof( page)); - - if (result != NULL) { - - } - - return result; -} \ No newline at end of file diff --git a/src/c/memory/pointer.h b/src/c/memory/pointer.h index 18c3aa9..8b3b3bf 100644 --- a/src/c/memory/pointer.h +++ b/src/c/memory/pointer.h @@ -37,5 +37,3 @@ struct pso_pointer { */ uint16_t offset; }; - -#endif diff --git a/src/c/memory/pso4.h b/src/c/memory/pso4.h index 1384d12..68a351d 100644 --- a/src/c/memory/pso4.h +++ b/src/c/memory/pso4.h @@ -13,7 +13,7 @@ #include #include "memory/header.h" -#include "memory/stack.h" +#include "payloads/stack_frame.h" /** * @brief A paged space object of size class 4, 16 words total, 14 words diff --git a/src/c/memory/stack.c b/src/c/memory/stack.c deleted file mode 100644 index ab98c93..0000000 --- a/src/c/memory/stack.c +++ /dev/null @@ -1,38 +0,0 @@ -/** - * memory/stack.c - * - * The execution stack. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include "memory/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 cons_pointer fetch_arg( struct stack_frame *frame, unsigned int index ) { - struct cons_pointer result = NIL; - - if ( index < args_in_frame ) { - result = frame->arg[index]; - } else { - struct cons_pointer p = frame->more; - - for ( int i = args_in_frame; i < index; i++ ) { - p = pointer2cell( p ).payload.cons.cdr; - } - - result = pointer2cell( p ).payload.cons.car; - } - - return result; -} diff --git a/src/c/ops/README.md b/src/c/ops/README.md deleted file mode 100644 index 80f3ccd..0000000 --- a/src/c/ops/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# README: PSSE substrate operations - -This folder/pseudo-package is for things which implement basic Lisp functions. -These will be the functions which make up the `:bootstrap` and `:substrate` -packages in Lisp. - -For each basic function the intention is that there should be one `.c` file -(and normally one `.h` file as well). This file will provide one version of the -function with Lisp calling conventions, called `lisp_xxxx`, and one with C -calling conventions, called `xxxx`. It does not matter whether the lisp version -calls the C version or vice versa, but one should call the other so there are -not two different versions of the logic. - -Substrate I/O functions will not be provided in this pseudo-package but in `io`. -Substrate arithmetic functions will not be provided in this pseudo-package but -in `arith`. \ No newline at end of file diff --git a/src/c/ops/eq.c b/src/c/ops/eq.c deleted file mode 100644 index 0c2e192..0000000 --- a/src/c/ops/eq.c +++ /dev/null @@ -1,56 +0,0 @@ -/** - * ops/eq.c - * - * Post Scarcity Software Environment: eq. - * - * Test for pointer equality. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include "memory/memory.h" -#include "memory/pointer.h" -#include "memory/stack.h" - -/** - * @brief Function; do these two pointers point to the same object? - * - * Shallow, cheap equality. - * - * TODO: if either of these pointers points to a cache cell, then what - * we need to check is the cached value, which is not so cheap. Ouch! - * - * @param a a pointer; - * @param b another pointer; - * @return `true` if they are the same, else `false` - */ -bool eq( struct pso_pointer a, struct pso_pointer b) { - return ( a.node == b.node && a.page == b.page && a.offset == b.offset); -} - -/** - * Function; do all arguments to this finction point to the same object? - * - * Shallow, cheap equality. - * - * * (eq? args...) - * - * @param frame my stack_frame. - * @param frame_pointer a pointer to my stack_frame. - * @param env my environment (ignored). - * @return `t` if all args are pointers to the same object, else `nil`; - */ -struct pso_pointer lisp_eq( struct stack_frame *frame, - struct pso_pointer frame_pointer, - struct pso_pointer env ) { - struct pso_pointer result = t; - - if ( frame->args > 1 ) { - for ( int b = 1; ( truep( result ) ) && ( b < frame->args ); b++ ) { - result = eq( frame->arg[0], fetch_arg( frame, b ) ) ? t : nil; - } - } - - return result; -} diff --git a/src/c/ops/eq.h b/src/c/ops/eq.h deleted file mode 100644 index febb5af..0000000 --- a/src/c/ops/eq.h +++ /dev/null @@ -1,21 +0,0 @@ -/** - * ops/eq.h - * - * Post Scarcity Software Environment: eq. - * - * Test for pointer equality. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#ifndef __psse_ops_eq_h -#define __psse_ops_eq_h - -bool eq( struct pso_pointer a, struct pso_pointer b); - -struct pso_pointer lisp_eq( struct stack_frame *frame, - struct pso_pointer frame_pointer, - struct pso_pointer env ); - -#endif \ No newline at end of file diff --git a/src/c/ops/eval.c b/src/c/ops/eval.c deleted file mode 100644 index d76da2b..0000000 --- a/src/c/ops/eval.c +++ /dev/null @@ -1,65 +0,0 @@ -/** - * ops/eval.c - * - * Post Scarcity Software Environment: eval. - * - * Evaluate an arbitrary Lisp expression. - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include "memory/pointer" -#include "memory/stack.h" -#include "payloads/cons.h" -#include "payloads/function.h" -#include "payloads/keyword.h" -#include "payloads/lambda.h" -#include "payloads/nlambda.h" -#include "payloads/special.h" - -/** - * @brief Despatch eval based on tag of the form in the first position. - * - * @param frame The current stack frame; - * @param frame_pointer A pointer to the current stack frame; - * @param env the evaluation environment. - * @return struct pso_pointer - */ -struct pso_pointer eval_despatch( struct stack_frame *frame, struct pso_pointer frame_pointer, - struct pso_pointer env ) { - struct pso_pointer result = frame->arg[0]; - - // switch ( get_tag_value( result)) { - // case CONSTV: - // result = eval_cons( frame, frame_pointer, env); - // break; - // case KEYTV: - // case SYMBOLTV: - // result = eval_symbol( frame, frame_pointer, env); - // break; - // case LAMBDATV: - // result = eval_lambda( frame, frame_pointer, env); - // break; - // case NLAMBDATV: - // result = eval_nlambda( frame, frame_pointer, env); - // break; - // case SPECIALTV: - // result = eval_special( frame, frame_pointer, env); - // break; - // } - - return result; -} - -struct pso_pointer lisp_eval( struct stack_frame *frame, struct pso_pointer frame_pointer, - struct pso_pointer env ) { - struct pso_pointer result = eval_despatch( frame, frame_pointer, env); - - if (exceptionp( result)) { - // todo: if result doesn't have a stack frame, create a new exception wrapping - // result with this stack frame. - } - - return result; -} \ No newline at end of file diff --git a/src/c/ops/repl.h b/src/c/ops/repl.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/c/memory/stack.h b/src/c/payloads/stack_frame.h similarity index 67% rename from src/c/memory/stack.h rename to src/c/payloads/stack_frame.h index 7e0b2b0..2aefcfc 100644 --- a/src/c/memory/stack.h +++ b/src/c/payloads/stack_frame.h @@ -1,7 +1,7 @@ /** - * memory/stack.h + * payloads/stack_frame.h * - * The execution stack. + * A stack frame. * * (c) 2026 Simon Brooke * Licensed under GPL version 2.0, or, at your option, any later version. @@ -17,25 +17,18 @@ */ #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. */ struct stack_frame_payload { /** the previous frame. */ - struct pso_pointer previous; + struct cons_pointer previous; /** first 8 arument bindings. */ - struct pso_pointer arg[args_in_frame]; + struct cons_pointer arg[args_in_frame]; /** list of any further argument bindings. */ - struct pso_pointer more; + struct cons_pointer more; /** the function to be called. */ - struct pso_pointer function; + struct cons_pointer function; /** the number of arguments provided. */ int args; /** the depth of the stack below this frame */ diff --git a/src/c/psse.c b/src/c/psse.c deleted file mode 100644 index 636cde5..0000000 --- a/src/c/psse.c +++ /dev/null @@ -1,105 +0,0 @@ - -/** - * psse.c - * - * Post Scarcity Software Environment: entry point. - * - * Start up and initialise the environement - just enough to get working - * and (ultimately) hand off to the executive. - * - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#include "psse.h" -#include "memory/node.h" - -void print_banner( ) { - fwprintf( stdout, L"Post-Scarcity Software Environment version %s\n\n", - VERSION ); -} - -/** - * Print command line options to this `stream`. - * - * @stream the stream to print to. - */ -void print_options( FILE *stream ) { - fwprintf( stream, L"Expected options are:\n" ); - fwprintf( stream, - L"\t-d\tDump memory to standard out at end of run (copious!);\n" ); - fwprintf( stream, L"\t-h\tPrint this message and exit;\n" ); - fwprintf( stream, L"\t-p\tShow a prompt (default is no prompt);\n" ); - fwprintf( stream, - L"\t-s LIMIT\n\t\tSet the maximum stack depth to this LIMIT (int)\n" ); -#ifdef DEBUG - fwprintf( stream, - L"\t-v LEVEL\n\t\tSet verbosity to the specified level (0...512)\n" ); - fwprintf( stream, L"\t\tWhere bits are interpreted as follows:\n" ); - fwprintf( stream, L"\t\t1\tALLOC;\n" ); - fwprintf( stream, L"\t\t2\tARITH;\n" ); - fwprintf( stream, L"\t\t4\tBIND;\n" ); - fwprintf( stream, L"\t\t8\tBOOTSTRAP;\n" ); - fwprintf( stream, L"\t\t16\tEVAL;\n" ); - fwprintf( stream, L"\t\t32\tINPUT/OUTPUT;\n" ); - fwprintf( stream, L"\t\t64\tLAMBDA;\n" ); - fwprintf( stream, L"\t\t128\tREPL;\n" ); - fwprintf( stream, L"\t\t256\tSTACK;\n" ); - fwprintf( stream, L"\t\t512\tEQUAL.\n" ); -#endif -} - - - /** - * main entry point; parse command line arguments, initialise the environment, - * and enter the read-eval-print loop. - */ -int main( int argc, char *argv[] ) { - int option; - bool dump_at_end = false; - bool show_prompt = false; - char *infilename = NULL; - - setlocale( LC_ALL, "" ); - // if ( io_init( ) != 0 ) { - // fputs( "Failed to initialise I/O subsystem\n", stderr ); - // exit( 1 ); - // } - - while ( ( option = getopt( argc, argv, "dhi:ps:v:" ) ) != -1 ) { - switch ( option ) { - case 'd': - dump_at_end = true; - break; - case 'h': - print_banner( ); - print_options( stdout ); - exit( 0 ); - break; - case 'i': - infilename = optarg; - break; - case 'p': - show_prompt = true; - break; - case 's': - stack_limit = atoi( optarg ); - break; - case 'v': - verbosity = atoi( optarg ); - break; - default: - fwprintf( stderr, L"Unexpected option %c\n", option ); - print_options( stderr ); - exit( 1 ); - break; - } - } - - initialise_node( 0); - - repl(); - - exit( 0); -} \ No newline at end of file diff --git a/src/c/psse.h b/src/c/psse.h deleted file mode 100644 index 759c33c..0000000 --- a/src/c/psse.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * psse.h - * - * Post Scarcity Software Environment: entry point. - * - * Start up and initialise the environement - just enough to get working - * and (ultimately) hand off to the executive. - * - * - * (c) 2026 Simon Brooke - * Licensed under GPL version 2.0, or, at your option, any later version. - */ - -#ifndef __psse_psse_h -#define __psse_psse_h - -#include -#include -#include -#include -#include -#include -#include - -#include "debug.h" -#include "memory/memory.h" -#include "memory/stack.h" -#include "version.h" - -#endif \ No newline at end of file