Well, I really made a mess with the last commit; this one sorts it out.

This commit is contained in:
Simon Brooke 2026-03-31 20:09:37 +01:00
parent 1196b3eb1d
commit a302663b32
16 changed files with 3671 additions and 0 deletions

55
src/c/ops/reverse.c Normal file
View file

@ -0,0 +1,55 @@
/**
* ops/reverse.c
*
* Post Scarcity Software Environment: reverse.
*
* Reverse a sequence. Didn'e want to do this in the substrate, but I need
* if for reading atoms!.
*
* (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/node.h"
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/pso2.h"
#include "memory/tags.h"
#include "payloads/cons.h"
#include "payloads/exception.h"
#include "payloads/psse_string.h"
#include "ops/string_ops.h"
#include "ops/truth.h"
struct pso_pointer reverse( struct pso_pointer sequence) {
struct pso_pointer result = nil;
for (struct pso_pointer cursor = sequence; !nilp( sequence); cursor = cdr(cursor)) {
struct pso2* object = pointer_to_object( cursor);
switch (get_tag_value(cursor)) {
case CONSTV :
result = cons( car(cursor), result);
break;
case KEYTV :
result = make_string_like_thing( object->payload.string.character, result, KEYTAG);
break;
case STRINGTV :
result = make_string_like_thing( object->payload.string.character, result, STRINGTAG);
break;
case SYMBOLTV :
result = make_string_like_thing( object->payload.string.character, result, SYMBOLTAG);
break;
default :
result = make_exception( c_string_to_lisp_string(L"Invalid object in sequence"), nil, nil);
goto exit;
break;
}
}
exit:
return result;
}