Still doesn't compile, but I think excellent progress.

This commit is contained in:
Simon Brooke 2026-04-28 11:54:15 +01:00
parent dbeb99759a
commit aac4669a3d
34 changed files with 1128 additions and 673 deletions

140
src/c/ops/dump.c Normal file
View file

@ -0,0 +1,140 @@
/*
* dump.c
*
* Dump representations of both cons space and vector space objects.
*
*
* (c) 2018 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
/*
* wide characters
*/
#include <wchar.h>
#include <wctype.h>
#include "memory/pso2.h"
#include "memory/tags.h"
#include "io/print.h"
#include "payloads/lambda.h"
void dump_string_cell( URL_FILE *output, wchar_t *prefix,
struct pso_pointer pointer ) {
struct pso2 *cell = pointer_to_object( pointer );
if ( cell->payload.string.character == 0 ) {
url_fwprintf( output,
L"\t\t%ls cell: termination; next at page %d offset %d, count %u\n",
prefix,
cell->payload.string.cdr.page,
cell->payload.string.cdr.offset, cell->header.count );
} else {
url_fwprintf( output,
L"\t\t%ls cell: character '%lc' (%d) with hash %d; next at page %d offset %d, count %u\n",
prefix,
( wint_t ) cell->payload.string.character,
cell->payload.string.character,
cell->payload.string.hash,
cell->payload.string.cdr.page,
cell->payload.string.cdr.offset, cell->header.count );
url_fwprintf( output, L"\t\t value: " );
print( output, pointer );
url_fwprintf( output, L"\n" );
}
}
/**
* dump the object at this pso_pointer to this output stream.
*/
void dump_object( URL_FILE *output, struct pso_pointer pointer ) {
struct pso2 *cell = pointer_to_object( pointer );
url_fwprintf( output, L"\t%3.3s (%d) at page %d, offset %d count %u\n",
cell->header.tag.bytes.mnemonic[0], get_tag_value( pointer ),
pointer.page, pointer.offset, cell->header.count );
switch ( get_tag_value( pointer ) ) {
case CONSTV:
url_fwprintf( output,
L"\t\tCons cell: car at page %d offset %d, cdr at page %d "
L"offset %d, count %u :",
cell->payload.cons.car.page,
cell->payload.cons.car.offset,
cell->payload.cons.cdr.page,
cell->payload.cons.cdr.offset );
print( output, pointer );
url_fputws( L"\n", output );
break;
case EXCEPTIONTV:
url_fwprintf( output, L"\t\tException cell: " );
dump_stack_trace( output, pointer );
break;
case FREETV:
url_fwprintf( output,
L"\t\tFree cell: next at page %d offset %d\n",
cell->payload.cons.cdr.page,
cell->payload.cons.cdr.offset );
break;
case HASHTV:
dump_map( output, pointer );
break;
case INTEGERTV:
url_fwprintf( output, L"\t\tInteger cell: value %ld, count %u\n",
cell->payload.integer.value, cell->header.count );
break;
case KEYTV:
dump_string_cell( output, L"Keyword", pointer );
break;
case LAMBDATV:
url_fwprintf( output, L"\t\t\u03bb cell;\n\t\t args: " );
print( output, cell->payload.lambda.args );
url_fwprintf( output, L";\n\t\t\tbody: " );
print( output, cell->payload.lambda.body );
url_fputws( L"\n", output );
break;
case NILTV:
break;
case NLAMBDATV:
url_fwprintf( output, L"\t\tn\u03bb cell; \n\t\targs: " );
print( output, cell->payload.lambda.args );
url_fwprintf( output, L";\n\t\t\tbody: " );
print( output, cell->payload.lambda.body );
url_fputws( L"\n", output );
break;
case RATIOTV:
url_fwprintf( output,
L"\t\tRational cell: value %ld/%ld, count %u\n",
pointer_to_object( cell->payload.ratio.
dividend ).payload.integer.value,
pointer_to_object( cell->payload.ratio.
divisor ).payload.integer.value,
cell->header.count );
break;
case READTV:
url_fputws( L"\t\tInput stream; metadata: ", output );
print( output, cell->payload.stream.meta );
url_fputws( L"\n", output );
break;
case REALTV:
url_fwprintf( output, L"\t\tReal cell: value %Lf, count %u\n",
cell->payload.real.value, cell->header.count );
break;
case STACKTV:
dump_frame( output, pointer );
break;
case STRINGTV:
dump_string_cell( output, L"String", pointer );
break;
case SYMBOLTV:
dump_string_cell( output, L"Symbol", pointer );
break;
case TRUETV:
break;
case WRITETV:
url_fputws( L"\t\tOutput stream; metadata: ", output );
print( output, cell->payload.stream.meta );
url_fputws( L"\n", output );
break;
}
}