Lots more code written, and I think most of it's OK; but it doesn't compile yet.

This commit is contained in:
Simon Brooke 2026-03-26 09:01:46 +00:00
parent 604fca3c24
commit 6c4be8f283
19 changed files with 634 additions and 7 deletions

16
src/c/ops/README.md Normal file
View file

@ -0,0 +1,16 @@
# 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`.

56
src/c/ops/eq.c Normal file
View file

@ -0,0 +1,56 @@
/**
* ops/eq.c
*
* Post Scarcity Software Environment: eq.
*
* Test for pointer equality.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* 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;
}

21
src/c/ops/eq.h Normal file
View file

@ -0,0 +1,21 @@
/**
* ops/eq.h
*
* Post Scarcity Software Environment: eq.
*
* Test for pointer equality.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* 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

65
src/c/ops/eval.c Normal file
View file

@ -0,0 +1,65 @@
/**
* ops/eval.c
*
* Post Scarcity Software Environment: eval.
*
* Evaluate an arbitrary Lisp expression.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* 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;
}

0
src/c/ops/repl.h Normal file
View file