read isn't written yet, but I think all the building blocks I need for it are.
Compiles and runs; does nothing yet.
This commit is contained in:
parent
364d7d2c7b
commit
1196b3eb1d
21 changed files with 84 additions and 3347 deletions
|
|
@ -152,3 +152,11 @@ struct pso_pointer allocate_page( uint8_t size_class ) {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief allow other files to see the current value of npages_allocated, but not
|
||||
* change it.
|
||||
*/
|
||||
uint32_t get_pages_allocated() {
|
||||
return npages_allocated;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,6 @@ union page {
|
|||
|
||||
struct pso_pointer allocate_page( uint8_t size_class );
|
||||
|
||||
uint32_t get_pages_allocated();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -41,8 +41,13 @@ struct pso2 *pointer_to_object( struct pso_pointer pointer ) {
|
|||
struct pso2 *result = NULL;
|
||||
|
||||
if ( pointer.node == node_index ) {
|
||||
union page *pg = pages[pointer.page];
|
||||
result = ( struct pso2 * ) &pg->words[pointer.offset];
|
||||
if (pointer.page < get_pages_allocated() && pointer.offset < (PAGE_BYTES / 8)) {
|
||||
// TODO: that's not really a safe test of whether this is a valid pointer.
|
||||
union page *pg = pages[pointer.page];
|
||||
result = ( struct pso2 * ) &pg->words[pointer.offset];
|
||||
} else {
|
||||
// TODO: throw bad pointer exception.
|
||||
}
|
||||
}
|
||||
// TODO: else if we have a copy of the object in cache, return that;
|
||||
// else request a copy of the object from the node which curates it.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../payloads/psse_string.h"
|
||||
#include "memory/header.h"
|
||||
#include "payloads/character.h"
|
||||
#include "payloads/cons.h"
|
||||
|
|
@ -22,7 +23,6 @@
|
|||
#include "payloads/lambda.h"
|
||||
#include "payloads/nlambda.h"
|
||||
#include "payloads/read_stream.h"
|
||||
#include "payloads/psse-string.h"
|
||||
#include "payloads/symbol.h"
|
||||
#include "payloads/time.h"
|
||||
#include "payloads/vector_pointer.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Post Scarcity Software Environment: eq.
|
||||
*
|
||||
* Test for pointer equality.
|
||||
* Test for pointer equality; bootstrap level tests for object equality.
|
||||
*
|
||||
* (c) 2026 Simon Brooke <simon@journeyman.cc>
|
||||
* Licensed under GPL version 2.0, or, at your option, any later version.
|
||||
|
|
@ -12,6 +12,11 @@
|
|||
#include "memory/memory.h"
|
||||
#include "memory/node.h"
|
||||
#include "memory/pointer.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "memory/tags.h"
|
||||
|
||||
#include "payloads/cons.h"
|
||||
#include "payloads/integer.h"
|
||||
#include "payloads/stack.h"
|
||||
#include "ops/stack_ops.h"
|
||||
#include "ops/truth.h"
|
||||
|
|
@ -32,6 +37,39 @@ bool eq( struct pso_pointer a, struct pso_pointer b ) {
|
|||
return ( a.node == b.node && a.page == b.page && a.offset == b.offset );
|
||||
}
|
||||
|
||||
bool equal( struct pso_pointer a, struct pso_pointer b) {
|
||||
bool result = false;
|
||||
|
||||
if ( eq( a, b)) {
|
||||
result = true;
|
||||
} else if ( get_tag_value(a) == get_tag_value(b)) {
|
||||
switch ( get_tag_value(a)) {
|
||||
case CONSTV :
|
||||
result = (equal( car(a), car(b)) && equal( cdr(a), cdr(b)));
|
||||
break;
|
||||
case INTEGERTV :
|
||||
result = (pointer_to_object(a)->payload.integer.value ==
|
||||
pointer_to_object(b)->payload.integer.value);
|
||||
break;
|
||||
case KEYTV:
|
||||
case STRINGTV :
|
||||
case SYMBOLTV :
|
||||
while (result == false && !nilp(a) && !nilp(b)) {
|
||||
if (pointer_to_object(a)->payload.string.character ==
|
||||
pointer_to_object(b)->payload.string.character) {
|
||||
a = cdr(a);
|
||||
b = cdr(b);
|
||||
}
|
||||
}
|
||||
result = nilp(a) && nilp(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function; do all arguments to this finction point to the same object?
|
||||
*
|
||||
|
|
@ -60,3 +98,5 @@ struct pso_pointer lisp_eq( struct pso4 *frame,
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,4 +22,5 @@ struct pso_pointer lisp_eq( struct pso4 *frame,
|
|||
struct pso_pointer frame_pointer,
|
||||
struct pso_pointer env );
|
||||
|
||||
bool equal( struct pso_pointer a, struct pso_pointer b);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,7 +14,11 @@
|
|||
#include "memory/pso.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "memory/tags.h"
|
||||
|
||||
#include "payloads/cons.h"
|
||||
#include "payloads/exception.h"
|
||||
|
||||
#include "ops/string_ops.h"
|
||||
|
||||
/**
|
||||
* @brief allocate a cons cell with this car and this cdr, and return a pointer
|
||||
|
|
@ -58,19 +62,29 @@ struct pso_pointer car( struct pso_pointer cons ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief return the cdr of this cons cell.
|
||||
* @brief return the cdr of this cons (or other sequence) cell.
|
||||
*
|
||||
* @param cons a pointer to the cell.
|
||||
* @return the cdr of the indicated cell.
|
||||
* @exception if the pointer does not indicate a cons cell.
|
||||
*/
|
||||
struct pso_pointer cdr( struct pso_pointer cons ) {
|
||||
struct pso_pointer cdr( struct pso_pointer p ) {
|
||||
struct pso_pointer result = nil;
|
||||
struct pso2 *object = pointer_to_object( result );
|
||||
|
||||
if ( consp( cons ) ) {
|
||||
result = object->payload.cons.cdr;
|
||||
switch (get_tag_value( p)) {
|
||||
case CONSTV : result = object->payload.cons.cdr; break;
|
||||
case KEYTV :
|
||||
case STRINGTV :
|
||||
case SYMBOLTV :
|
||||
result = object->payload.string.cdr; break;
|
||||
default :
|
||||
result = make_exception(
|
||||
cons(c_string_to_lisp_string(L"Invalid type for cdr"), p),
|
||||
nil, nil);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: else throw an exception
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ struct exception_payload {
|
|||
struct pso_pointer cause;
|
||||
};
|
||||
|
||||
struct pso_pointer make_exception( struct pso_pointer message, struct pso_pointer frame_pointer, struct pso_pointer cause);
|
||||
struct pso_pointer make_exception( struct pso_pointer message,
|
||||
struct pso_pointer frame_pointer, struct pso_pointer cause);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -37,4 +37,6 @@ struct stack_frame_payload {
|
|||
uint32_t depth;
|
||||
};
|
||||
|
||||
struct pso_pointer make_frame( struct pso_pointer previous, ...);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue