Still making progress. Dropped the archive because it was causing problems.

This commit is contained in:
Simon Brooke 2026-04-22 21:09:15 +01:00
parent eed4711fee
commit 8d2acbeb0f
97 changed files with 490 additions and 13322 deletions

View file

@ -33,6 +33,7 @@
#include "ops/assoc.h"
#include "ops/eval_apply.h"
#include "ops/stack_ops.h"
#include "ops/truth.h"
/**
@ -47,14 +48,14 @@ void int_handler( int dummy ) {
/**
* Very simple read/eval/print loop for bootstrapping.
*/
void c_repl( bool show_prompt ) {
void repl( struct pso_pointer frame_pointer ) {
struct pso4 *frame = pointer_to_pso4( frame_pointer );
bool show_prompt = c_truep( fetch_arg( frame, 0 ) );
// todo: issue #21: must have stack frame passed in.
signal( SIGINT, int_handler );
debug_print( L"Entered repl\n", DEBUG_REPL, 0 );
// TODO: NULL is not OK here, but will do until we have a REPL in Lisp.
struct pso_pointer env =
consp( oblist ) ? oblist : make_cons( nil, oblist, nil );
struct pso_pointer env = fetch_env( frame_pointer );
struct pso_pointer input_stream = c_assoc( lisp_io_in, env );
struct pso_pointer output_stream = c_assoc( lisp_io_out, env );
@ -72,32 +73,28 @@ void c_repl( bool show_prompt ) {
while ( readp( input_stream ) &&
!url_feof( stream_get_url_file( input_stream ) ) ) {
if ( show_prompt )
c_princ( c_assoc( lisp_io_prompt, env ), output_stream );
princ( make_frame( 2, frame_pointer,
c_assoc( lisp_io_prompt, env ),
output_stream ) );
/* bottom of stack */
struct pso_pointer frame_pointer = make_frame( 1, nil, input_stream );
/* the reason for initialising a new stack for each REPL input is to
* be sure the old stack is fully torn down and reclaimed. Once I'm
* confident of that, TODO: do not start a new stack base each time!
*/
struct pso_pointer base_of_stack =
inc_ref( make_frame_with_env( 0, nil,
consp( oblist ) ? oblist :
make_cons( nil, oblist, nil ) ) );
if ( c_nilp( frame_pointer ) )
break;
struct pso_pointer input = read(
#ifndef MANAGED_POINTER_ONLY
pointer_to_pso4( frame_pointer ),
#endif
frame_pointer, env );
print( make_frame
( 2, base_of_stack,
eval( make_frame
( 1, base_of_stack,
read( make_frame
( 1, base_of_stack, input_stream ) ) ) ),
output_stream ) );
frame_pointer = make_frame( 1, frame_pointer, input );
if ( c_nilp( frame_pointer ) )
break;
struct pso_pointer result = eval(
#ifndef MANAGED_POINTER_ONLY
pointer_to_pso4( frame_pointer ),
#endif
frame_pointer, oblist );
c_print( result, output_stream );
dec_ref( frame_pointer );
dec_ref( base_of_stack );
}
debug_print( L"Leaving repl\n", DEBUG_REPL, 0 );