There's an enormous lot of good stuff in this, but I've messed up print
almost certainly by writing a non-wide character to a wide stream.
This commit is contained in:
parent
7e40d65df0
commit
93b84087ce
13 changed files with 379 additions and 131 deletions
80
src/repl.c
80
src/repl.c
|
|
@ -19,6 +19,54 @@
|
|||
#include "print.h"
|
||||
#include "stack.h"
|
||||
|
||||
|
||||
/* TODO: this is subtly wrong. If we were evaluating
|
||||
* (print (eval (read)))
|
||||
* then the stack frame for read would have the stack frame for
|
||||
* eval as parent, and it in turn would have the stack frame for
|
||||
* print as parent.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dummy up a Lisp read call with its own stack frame.
|
||||
*/
|
||||
struct cons_pointer repl_read( struct cons_pointer stream_pointer) {
|
||||
struct stack_frame *frame = make_empty_frame( NULL, oblist );
|
||||
|
||||
frame->arg[0] = stream_pointer;
|
||||
struct cons_pointer result = lisp_read( frame, oblist);
|
||||
free_stack_frame( frame );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy up a Lisp eval call with its own stack frame.
|
||||
*/
|
||||
struct cons_pointer repl_eval( struct cons_pointer input) {
|
||||
struct stack_frame *frame = make_empty_frame( NULL, oblist );
|
||||
|
||||
frame->arg[0] = NIL /* input */;
|
||||
struct cons_pointer result = lisp_eval( frame, oblist);
|
||||
free_stack_frame( frame );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy up a Lisp print call with its own stack frame.
|
||||
*/
|
||||
struct cons_pointer repl_print( struct cons_pointer stream_pointer, struct cons_pointer value) {
|
||||
struct stack_frame *frame = make_empty_frame( NULL, oblist );
|
||||
|
||||
frame->arg[0] = value;
|
||||
frame->arg[1] = NIL /* stream_pointer */;
|
||||
struct cons_pointer result = lisp_print( frame, oblist);
|
||||
free_stack_frame( frame );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The read/eval/print loop
|
||||
* @param in_stream the stream to read from;
|
||||
|
|
@ -29,23 +77,21 @@
|
|||
void
|
||||
repl( FILE * in_stream, FILE * out_stream, FILE * error_stream,
|
||||
bool show_prompt ) {
|
||||
while ( !feof( in_stream ) ) {
|
||||
if ( show_prompt ) {
|
||||
fwprintf( out_stream, L"\n:: " );
|
||||
}
|
||||
struct cons_pointer input = read( in_stream );
|
||||
fwprintf( error_stream, L"\nread {%d,%d}=> ", input.page,
|
||||
input.offset );
|
||||
print( error_stream, input );
|
||||
struct cons_pointer input_stream = make_read_stream(in_stream);
|
||||
struct cons_pointer output_stream = make_write_stream(out_stream);
|
||||
|
||||
struct stack_frame *frame = make_empty_frame( NULL, oblist );
|
||||
frame->arg[0] = input;
|
||||
struct cons_pointer value = lisp_eval( frame, oblist );
|
||||
free_stack_frame( frame );
|
||||
// print( out_stream, input );
|
||||
fwprintf( out_stream, L"\n" );
|
||||
fwprintf( error_stream, L"\neval {%d,%d}=> ", input.page,
|
||||
input.offset );
|
||||
print( out_stream, value );
|
||||
while ( !feof( pointer2cell(input_stream).payload.stream.stream ) ) {
|
||||
if ( show_prompt ) {
|
||||
fwprintf( out_stream, L"\n:: " );
|
||||
}
|
||||
|
||||
struct cons_pointer val = repl_eval( repl_read( input_stream));
|
||||
|
||||
/* suppress the 'end of stream' exception */
|
||||
if ( exceptionp(val) &&
|
||||
!feof( pointer2cell( input_stream).payload.stream.stream ) )
|
||||
{
|
||||
repl_print( output_stream, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue