Builds and runs, but print is badly broken. Need some rethink.
This commit is contained in:
parent
9425506e2a
commit
22b0160a26
7 changed files with 118 additions and 91 deletions
|
|
@ -34,6 +34,8 @@
|
|||
#include "memory/pointer.h"
|
||||
#include "memory/pso.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "memory/pso3.h"
|
||||
#include "memory/pso4.h"
|
||||
#include "memory/tags.h"
|
||||
|
||||
#include "ops/string_ops.h"
|
||||
|
|
@ -46,7 +48,7 @@
|
|||
#include "ops/truth.h"
|
||||
|
||||
struct pso_pointer in_write( struct pso_pointer p, URL_FILE * output,
|
||||
bool escape );
|
||||
bool escape, int indent );
|
||||
|
||||
/**
|
||||
* @brief write this character `wc` to this `output` stream, escaping it if
|
||||
|
|
@ -70,11 +72,11 @@ struct pso_pointer print_string_like_thing( struct pso_pointer p,
|
|||
URL_FILE *output, bool escape ) {
|
||||
switch ( get_tag_value( p ) ) {
|
||||
case KEYTV:
|
||||
url_fputwc( L':', output );
|
||||
write_char( L':', output, escape );
|
||||
break;
|
||||
case STRINGTV:
|
||||
if ( escape )
|
||||
url_fputwc( L'"', output );
|
||||
write_char( L'"', output, escape );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +92,7 @@ struct pso_pointer print_string_like_thing( struct pso_pointer p,
|
|||
|
||||
if ( stringp( p ) ) {
|
||||
if ( escape )
|
||||
url_fputwc( L'"', output );
|
||||
write_char( L'"', output, escape );
|
||||
}
|
||||
|
||||
return p;
|
||||
|
|
@ -104,7 +106,7 @@ struct pso_pointer write_list_content( struct pso_pointer p, URL_FILE *output,
|
|||
for ( ; consp( p ); p = c_cdr( p ) ) {
|
||||
struct pso2 *object = pointer_to_object( p );
|
||||
|
||||
result = in_write( object->payload.cons.car, output, escape );
|
||||
result = in_write( object->payload.cons.car, output, escape, 0 );
|
||||
|
||||
if ( exceptionp( result ) )
|
||||
break;
|
||||
|
|
@ -113,12 +115,12 @@ struct pso_pointer write_list_content( struct pso_pointer p, URL_FILE *output,
|
|||
case NILTV:
|
||||
break;
|
||||
case CONSTV:
|
||||
url_fputwc( L' ', output );
|
||||
write_char( L' ', output, escape );
|
||||
break;
|
||||
default:
|
||||
url_fputws( L" . ", output );
|
||||
result =
|
||||
in_write( object->payload.cons.cdr, output, escape );
|
||||
in_write( object->payload.cons.cdr, output, escape, 0 );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -128,6 +130,13 @@ struct pso_pointer write_list_content( struct pso_pointer p, URL_FILE *output,
|
|||
return result;
|
||||
}
|
||||
|
||||
void in_write_nl (URL_FILE *output, int indent) {
|
||||
write_char( L'\n', output, false);
|
||||
for (int i = 0; i < indent; i++) {
|
||||
write_char( L'\t', output, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is kind of modelled after the implementation of PRIN* variants on page
|
||||
* 383 of the aluminium book. It is the inner workings of all PRIN* functions.
|
||||
|
|
@ -139,7 +148,7 @@ struct pso_pointer write_list_content( struct pso_pointer p, URL_FILE *output,
|
|||
* @return p on success, exception on failure.
|
||||
*/
|
||||
struct pso_pointer in_write( struct pso_pointer p, URL_FILE *output,
|
||||
bool escape ) {
|
||||
bool escape, int indent ) {
|
||||
struct pso2 *object = pointer_to_object( p );
|
||||
struct pso_pointer result = nil;
|
||||
|
||||
|
|
@ -151,10 +160,26 @@ struct pso_pointer in_write( struct pso_pointer p, URL_FILE *output,
|
|||
escape );
|
||||
break;
|
||||
case CONSTV:
|
||||
url_fputwc( L'(', output );
|
||||
write_char( L'(', output, escape);
|
||||
result = write_list_content( p, output, escape );
|
||||
url_fputwc( L')', output );
|
||||
write_char( L')', output, escape);
|
||||
break;
|
||||
case EXCEPTIONTV :
|
||||
struct pso3* exception = pointer_to_pso3(p);
|
||||
url_fputws( L"<exception: ", output);
|
||||
in_write( exception->payload.exception.message, output, escape, indent);
|
||||
if (!c_nilp( exception->payload.exception.meta)) {
|
||||
in_write_nl( output, indent+1);
|
||||
url_fputws( L"metadata: ", output);
|
||||
in_write( exception->payload.exception.meta, output, escape, indent);
|
||||
}
|
||||
if (!c_nilp( exception->payload.exception.cause)) {
|
||||
in_write_nl( output, indent+1);
|
||||
url_fputws( L"cause: ", output);
|
||||
in_write( exception->payload.exception.cause, output, escape, indent);
|
||||
}
|
||||
write_char( L'>', output, escape);
|
||||
break;
|
||||
case INTEGERTV:
|
||||
url_fwprintf( output, L"%d",
|
||||
( int64_t ) ( object->payload.integer.value ) );
|
||||
|
|
@ -171,11 +196,11 @@ struct pso_pointer in_write( struct pso_pointer p, URL_FILE *output,
|
|||
case WRITETV:
|
||||
url_fwprintf( output, L"<%s stream: ",
|
||||
v == READTV ? "read" : "write" );
|
||||
in_write( object->payload.stream.meta, output, escape );
|
||||
url_fputwc( L'>', output );
|
||||
in_write( object->payload.stream.meta, output, escape, indent );
|
||||
write_char( L'>', output, escape );
|
||||
break;
|
||||
case TRUETV:
|
||||
url_fputwc( L't', output );
|
||||
write_char( L't', output, escape );
|
||||
break;
|
||||
default:
|
||||
// TODO: return exception
|
||||
|
|
@ -212,18 +237,14 @@ struct pso_pointer write( struct pso_pointer frame_pointer ) {
|
|||
struct pso2* stream_obj = pointer_to_object( stream );
|
||||
|
||||
if ( writep( stream ) ) {
|
||||
inc_ref( stream );
|
||||
|
||||
URL_FILE *output = stream_obj->payload.stream.stream;
|
||||
|
||||
if ( nl_before )
|
||||
url_fputwc( L'\n', output );
|
||||
|
||||
result = in_write( object, output, true );
|
||||
result = in_write( object, output, true, 0);
|
||||
|
||||
url_fputwc( nl_after ? L'\n' : L' ', output );
|
||||
|
||||
dec_ref( stream );
|
||||
} else {
|
||||
result =
|
||||
make_exception( make_frame( 1, frame_pointer,
|
||||
|
|
@ -245,9 +266,15 @@ struct pso_pointer write( struct pso_pointer frame_pointer ) {
|
|||
struct pso_pointer print( struct pso_pointer frame_pointer ) {
|
||||
struct pso4 *frame = pointer_to_pso4( frame_pointer );
|
||||
|
||||
return write( make_frame( 5, frame_pointer,
|
||||
struct pso_pointer next = inc_ref( make_frame( 5, frame_pointer,
|
||||
fetch_arg( frame, 0 ), fetch_arg( frame, 1 ), t,
|
||||
t, nil ) );
|
||||
t, nil ));
|
||||
|
||||
struct pso_pointer result = write( next );
|
||||
|
||||
dec_ref( next);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -256,7 +283,13 @@ struct pso_pointer print( struct pso_pointer frame_pointer ) {
|
|||
struct pso_pointer princ( struct pso_pointer frame_pointer ) {
|
||||
struct pso4 *frame = pointer_to_pso4( frame_pointer );
|
||||
|
||||
return write( make_frame( 5, frame_pointer,
|
||||
fetch_arg( frame, 0 ), fetch_arg( frame, 1 ),
|
||||
nil, t, nil ) );
|
||||
struct pso_pointer next = inc_ref( make_frame( 5, frame_pointer,
|
||||
fetch_arg( frame, 0 ), fetch_arg( frame, 1 ),
|
||||
nil, t, nil ));
|
||||
|
||||
struct pso_pointer result = write( next );
|
||||
|
||||
dec_ref( next);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue