Well, we have a REPL. It blows up horribly, but we have one.

This commit is contained in:
Simon Brooke 2026-04-17 14:20:31 +01:00
parent 4efe9eab87
commit cf05e30540
19 changed files with 422 additions and 144 deletions

View file

@ -19,6 +19,7 @@
#include "ops/stack_ops.h"
#include "payloads/cons.h"
#include "payloads/function.h"
#include "payloads/stack.h"
struct pso_pointer lisp_bind(

View file

@ -3,7 +3,7 @@
*
* Post Scarcity Software Environment: bind.
*
* Test for pointer binduality.
* Bind a name to a value in a store.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.

View file

@ -23,6 +23,7 @@
#include "ops/truth.h"
#include "payloads/cons.h"
#include "payloads/function.h"
#include "payloads/stack.h"
/**

View file

@ -15,6 +15,8 @@
#include "memory/pointer.h"
#include "memory/pso4.h"
#include "payloads/function.h"
struct pso_pointer car(
#ifndef MANAGED_POINTER_ONLY
struct pso4 *frame,

90
src/c/ops/repl.c Normal file
View file

@ -0,0 +1,90 @@
/**
* repl.c
*
* Post Scarcity Soctware Environment
*
* First cut at a top level read-eval-print loop.
*
* Copyright (c): 17 Apr 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#include <signal.h>
#include <stdio.h>
#include <wchar.h>
#include "debug.h"
#include "io/fopen.h"
#include "io/io.h"
#include "io/print.h"
#include "io/read.h"
#include "memory/node.h"
#include "memory/pointer.h"
#include "memory/pso.h"
#include "memory/pso2.h"
#include "memory/pso2.h"
#include "memory/pso2.h"
#include "memory/pso2.h"
#include "memory/pso4.h"
#include "memory/tags.h"
#include "payloads/cons.h"
#include "payloads/function.h"
#include "payloads/stack.h"
#include "ops/assoc.h"
#include "ops/eval_apply.h"
#include "ops/truth.h"
/**
* @brief Handle an interrupt signal.
*
* @param dummy
*/
void int_handler( int dummy ) {
wprintf( L"TODO: handle ctrl-C in a more interesting way\n" );
}
/**
* Very simple read/eval/print loop for bootstrapping.
*/
void c_repl( ) {
signal( SIGINT, int_handler );
debug_print( L"Entered repl\n", DEBUG_REPL, 0 );
struct pso_pointer env = consp( oblist ) ? oblist : c_cons( oblist, nil );
struct pso_pointer input_stream = c_assoc( lisp_io_in, env );
struct pso_pointer output_stream = c_assoc( lisp_io_out, env );
while ( readp( input_stream )
&& !url_feof( stream_get_url_file( input_stream ) ) ) {
/* bottom of stack */
struct pso_pointer frame_pointer = make_frame( 1, nil, input_stream );
if ( nilp( frame_pointer ) )
break;
struct pso_pointer input = read(
#ifndef MANAGED_POINTER_ONLY
pointer_to_pso4( frame_pointer ),
#endif
frame_pointer, env );
frame_pointer = make_frame( 1, frame_pointer, input );
if ( 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 );
}
debug_print( L"Leaving repl\n", DEBUG_REPL, 0 );
}

View file

@ -1,15 +1,20 @@
/**
* ops/repl.h
* repl.h
*
* The read/eval/print loop.
* Post Scarcity Soctware Environment
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
* Read/Eval/Print loop
*
* Copyright (c): 17 Apr 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#ifndef __psse_ops_repl_h
#define __psse_ops_repl_h
#ifndef SRC_C_OPS_REPL_H_
#define SRC_C_OPS_REPL_H_
// struct pso_pointer repl( struct pso_pointer prompt, struct pso_pointer readtable);
#endif
void c_repl( );
#endif /* SRC_C_OPS_REPL_H_ */