154 lines
6 KiB
C
154 lines
6 KiB
C
/*
|
|
* dump.c
|
|
*
|
|
* Dump representations of both cons space and vector space objects.
|
|
*
|
|
* TODO: This is going to be entirely rewritten and merged with `inspect.c`,
|
|
* q.v., which will be the main entrypoint to this code. What exists is
|
|
* technical debt but will work for now.
|
|
*
|
|
* (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/pointer.h"
|
|
#include "memory/pso2.h"
|
|
#include "memory/pso4.h"
|
|
#include "memory/tags.h"
|
|
#include "io/print.h"
|
|
|
|
#include "payloads/stack.h"
|
|
#include "payloads/lambda.h"
|
|
|
|
|
|
void dump_string_cell( struct pso_pointer frame_pointer, struct pso_pointer output, wchar_t *prefix,
|
|
struct pso_pointer pointer ) {
|
|
URL_FILE* os = pointer_to_object(output)->payload.stream.stream;
|
|
struct pso2 *cell = pointer_to_object( pointer );
|
|
|
|
if ( cell->payload.string.character == 0 ) {
|
|
url_fwprintf( os,
|
|
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( os,
|
|
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( os, L"\t\t value: " );
|
|
c_print( frame_pointer, pointer, output );
|
|
url_fwprintf( os, L"\n" );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* dump the object at this pso_pointer to this output stream.
|
|
*/
|
|
void dump_object( struct pso_pointer frame_pointer, struct pso_pointer output, struct pso_pointer pointer ) {
|
|
URL_FILE* os = pointer_to_object(output)->payload.stream.stream;
|
|
|
|
struct pso2 *cell = pointer_to_object( pointer );
|
|
url_fwprintf( os, 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( os,
|
|
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 );
|
|
c_print( frame_pointer, pointer, output );
|
|
url_fputws( L"\n", os );
|
|
break;
|
|
// case EXCEPTIONTV:
|
|
// url_fwprintf( os, L"\t\tException cell: " );
|
|
// dump_stack_trace( output, pointer );
|
|
// break;
|
|
case FREETV:
|
|
url_fwprintf( os,
|
|
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( os, L"\t\tInteger cell: value %ld, count %u\n",
|
|
cell->payload.integer.value, cell->header.count );
|
|
break;
|
|
case KEYTV:
|
|
dump_string_cell( frame_pointer, output, L"Keyword", pointer );
|
|
break;
|
|
case LAMBDATV:
|
|
url_fwprintf( os, L"\t\t\u03bb cell;\n\t\t args: " );
|
|
c_print( frame_pointer, cell->payload.lambda.args, output );
|
|
url_fwprintf( os, L";\n\t\t\tbody: " );
|
|
c_print( frame_pointer, cell->payload.lambda.body, output );
|
|
url_fputws( L"\n", os );
|
|
break;
|
|
case NILTV:
|
|
break;
|
|
case NLAMBDATV:
|
|
url_fwprintf( os, L"\t\tn\u03bb cell; \n\t\targs: " );
|
|
c_print( frame_pointer, cell->payload.lambda.args, output );
|
|
url_fwprintf( os, L";\n\t\t\tbody: " );
|
|
c_print( frame_pointer, cell->payload.lambda.body, output );
|
|
url_fputws( L"\n", os );
|
|
break;
|
|
// case RATIOTV:
|
|
// url_fwprintf( os,
|
|
// 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: ", os );
|
|
c_print( frame_pointer, cell->payload.stream.meta, output );
|
|
url_fputws( L"\n", os );
|
|
break;
|
|
case REALTV:
|
|
url_fwprintf( os, L"\t\tReal cell: value %Lf, count %u\n",
|
|
cell->payload.real.value, cell->header.count );
|
|
break;
|
|
// case STACKTV:
|
|
// dump_frame( frame_pointer, output, pointer );
|
|
// break;
|
|
case STRINGTV:
|
|
dump_string_cell( frame_pointer, output, L"String", pointer );
|
|
break;
|
|
case SYMBOLTV:
|
|
dump_string_cell( frame_pointer, output, L"Symbol", pointer );
|
|
break;
|
|
case TRUETV:
|
|
break;
|
|
case WRITETV:
|
|
url_fputws( L"\t\tOutput stream; metadata: ", os );
|
|
c_print( frame_pointer, cell->payload.stream.meta, output );
|
|
url_fputws( L"\n", os );
|
|
break;
|
|
default:
|
|
url_fwprintf(os, L"TODO: Cannot yet dump object of type %3.3s\n",
|
|
cell->header.tag.bytes.mnemonic[0]);
|
|
break;
|
|
}
|
|
}
|