Right, I'm committing this session because I'm too cold and tired to go on.
It does not at present build (and it's going to take a good bit more work before it does).
This commit is contained in:
parent
f05d1af9d6
commit
6148d3699f
32 changed files with 364 additions and 309 deletions
|
|
@ -41,6 +41,6 @@ struct pso_pointer lisp_bind(
|
|||
struct pso_pointer c_bind( struct pso_pointer key,
|
||||
struct pso_pointer value,
|
||||
struct pso_pointer store ) {
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
return make_cons( make_cons( key, value ), store );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,12 +85,18 @@ struct pso_pointer eval(
|
|||
default:
|
||||
result =
|
||||
make_exception( make_cons
|
||||
( c_string_to_lisp_string
|
||||
( L"Can't yet evaluate things of this type: " ),
|
||||
result ), frame_pointer,
|
||||
make_cons( make_cons
|
||||
( c_string_to_lisp_keyword( L"tag" ),
|
||||
get_tag_string( result ) ), nil ),
|
||||
( frame, c_string_to_lisp_string
|
||||
( frame,
|
||||
L"Can't yet evaluate things of this type: " ),
|
||||
result ), frame_pointer, make_cons( frame,
|
||||
make_cons
|
||||
( frame,
|
||||
c_string_to_lisp_keyword
|
||||
( frame,
|
||||
L"tag" ),
|
||||
get_tag_string
|
||||
( result ) ),
|
||||
nil ),
|
||||
nil );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ struct pso_pointer cdr(
|
|||
#ifdef MANAGED_POINTER_ONLY
|
||||
struct pso4 *frame = pointer_to_pso4( frame_pointer );
|
||||
#endif
|
||||
return c_cdr( fetch_arg( frame, 0 ) );
|
||||
return c_cdr( frame, fetch_arg( frame, 0 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,7 +66,7 @@ struct pso_pointer cons(
|
|||
struct pso4 *frame = pointer_to_pso4( frame_pointer );
|
||||
|
||||
#endif
|
||||
return make_cons( fetch_arg( frame, 0 ), fetch_arg( frame, 1 ) );
|
||||
return make_cons( frame, fetch_arg( frame, 0 ), fetch_arg( frame, 1 ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -48,11 +48,13 @@ void int_handler( int dummy ) {
|
|||
* Very simple read/eval/print loop for bootstrapping.
|
||||
*/
|
||||
void c_repl( bool show_prompt ) {
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
signal( SIGINT, int_handler );
|
||||
debug_print( L"Entered repl\n", DEBUG_REPL, 0 );
|
||||
|
||||
struct pso_pointer env = consp( oblist ) ? oblist : make_cons( oblist, nil );
|
||||
// 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( NULL, oblist, nil );
|
||||
struct pso_pointer input_stream = c_assoc( lisp_io_in, env );
|
||||
struct pso_pointer output_stream = c_assoc( lisp_io_out, env );
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#define SRC_C_OPS_REPL_H_
|
||||
|
||||
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
void c_repl( );
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
* the argument was not a sequence.
|
||||
*/
|
||||
struct pso_pointer c_reverse( struct pso_pointer sequence ) {
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
// todo: issue #21: must have stack frame passed in.
|
||||
struct pso_pointer result = nil;
|
||||
|
||||
for ( struct pso_pointer cursor = sequence; !nilp( sequence );
|
||||
|
|
@ -66,8 +66,8 @@ struct pso_pointer c_reverse( struct pso_pointer sequence ) {
|
|||
default:
|
||||
result =
|
||||
make_exception( make_cons( c_string_to_lisp_string
|
||||
( L"Invalid object in sequence" ),
|
||||
cursor ), nil, nil, nil );
|
||||
( L"Invalid object in sequence" ),
|
||||
cursor ), nil, nil, nil );
|
||||
goto exit;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,12 +69,13 @@ uint32_t calculate_hash( wint_t c, struct pso_pointer ptr ) {
|
|||
* char32_t in larger pso classes, so this function may be only for strings
|
||||
* (and thus simpler).
|
||||
*/
|
||||
struct pso_pointer make_string_like_thing( wint_t c, struct pso_pointer tail,
|
||||
struct pso_pointer make_string_like_thing( struct pso4 *frame_pointer,
|
||||
wint_t c, struct pso_pointer tail,
|
||||
char *tag ) {
|
||||
struct pso_pointer pointer = tail;
|
||||
|
||||
if ( check_type( tail, tag ) || nilp( tail ) ) {
|
||||
pointer = allocate( tag, CONS_SIZE_CLASS );
|
||||
pointer = allocate( frame_pointer, tag, CONS_SIZE_CLASS );
|
||||
struct pso2 *cell = pointer_to_object( pointer );
|
||||
|
||||
cell->payload.string.character = c;
|
||||
|
|
@ -106,8 +107,9 @@ struct pso_pointer make_string_like_thing( wint_t c, struct pso_pointer tail,
|
|||
* @param c the character to add (prepend);
|
||||
* @param tail the string which is being built.
|
||||
*/
|
||||
struct pso_pointer make_string( wint_t c, struct pso_pointer tail ) {
|
||||
return make_string_like_thing( c, tail, STRINGTAG );
|
||||
struct pso_pointer make_string( struct pso4 *frame_pointer, wint_t c,
|
||||
struct pso_pointer tail ) {
|
||||
return make_string_like_thing( frame_pointer, c, tail, STRINGTAG );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -118,8 +120,9 @@ struct pso_pointer make_string( wint_t c, struct pso_pointer tail ) {
|
|||
* @param c the character to add (prepend);
|
||||
* @param tail the keyword which is being built.
|
||||
*/
|
||||
struct pso_pointer make_keyword( wint_t c, struct pso_pointer tail ) {
|
||||
return make_string_like_thing( c, tail, KEYTAG );
|
||||
struct pso_pointer make_keyword( struct pso4 *frame_pointer, wint_t c,
|
||||
struct pso_pointer tail ) {
|
||||
return make_string_like_thing( frame_pointer, c, tail, KEYTAG );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -130,22 +133,26 @@ struct pso_pointer make_keyword( wint_t c, struct pso_pointer tail ) {
|
|||
* @param c the character to add (prepend);
|
||||
* @param tail the symbol which is being built.
|
||||
*/
|
||||
struct pso_pointer make_symbol( wint_t c, struct pso_pointer tail ) {
|
||||
return make_string_like_thing( c, tail, SYMBOLTAG );
|
||||
struct pso_pointer make_symbol( struct pso4 *frame_pointer, wint_t c,
|
||||
struct pso_pointer tail ) {
|
||||
return make_string_like_thing( frame_pointer, c, tail, SYMBOLTAG );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a lisp string representation of this wide character string.
|
||||
*/
|
||||
struct pso_pointer c_string_to_lisp_string( char32_t *string ) {
|
||||
struct pso_pointer c_string_to_lisp_string( struct pso4 *frame_pointer,
|
||||
char32_t *string ) {
|
||||
struct pso_pointer result = nil;
|
||||
|
||||
for ( int i = wcslen( string ) - 1; i >= 0; i-- ) {
|
||||
if ( string[i] != '"' ) {
|
||||
result = make_string( string[i], result );
|
||||
result = make_string( frame_pointer, string[i], result );
|
||||
} else {
|
||||
result = make_string( L'\\', make_string( string[i], result ) );
|
||||
result = make_string( frame_pointer, L'\\',
|
||||
make_string( frame_pointer, string[i],
|
||||
result ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,14 +164,15 @@ struct pso_pointer c_string_to_lisp_string( char32_t *string ) {
|
|||
* Return a lisp symbol representation of this wide character string. In
|
||||
* symbols, I am accepting only lower case characters.
|
||||
*/
|
||||
struct pso_pointer c_string_to_lisp_symbol( char32_t *symbol ) {
|
||||
struct pso_pointer c_string_to_lisp_symbol( struct pso4 *frame_pointer,
|
||||
char32_t *symbol ) {
|
||||
struct pso_pointer result = nil;
|
||||
|
||||
for ( int i = wcslen( symbol ) - 1; i >= 0; i-- ) {
|
||||
char32_t c = towlower( symbol[i] );
|
||||
|
||||
if ( iswalpha( c ) || c == L'-' || c == L'*' ) {
|
||||
result = make_symbol( c, result );
|
||||
result = make_symbol( frame_pointer, c, result );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,14 +183,15 @@ struct pso_pointer c_string_to_lisp_symbol( char32_t *symbol ) {
|
|||
* Return a lisp keyword representation of this wide character string. In
|
||||
* keywords, I am accepting only lower case characters and numbers.
|
||||
*/
|
||||
struct pso_pointer c_string_to_lisp_keyword( char32_t *symbol ) {
|
||||
struct pso_pointer c_string_to_lisp_keyword( struct pso4 *frame_pointer,
|
||||
char32_t *symbol ) {
|
||||
struct pso_pointer result = nil;
|
||||
|
||||
for ( int i = wcslen( symbol ) - 1; i >= 0; i-- ) {
|
||||
char32_t c = towlower( symbol[i] );
|
||||
|
||||
if ( iswalnum( c ) || c == L'-' ) {
|
||||
result = make_keyword( c, result );
|
||||
result = make_keyword( frame_pointer, c, result );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,19 +17,26 @@
|
|||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
struct pso_pointer make_string_like_thing( wint_t c, struct pso_pointer tail,
|
||||
struct pso_pointer make_string_like_thing( struct pso4 *frame_pointer,
|
||||
wint_t c, struct pso_pointer tail,
|
||||
char *tag );
|
||||
|
||||
struct pso_pointer make_string( wint_t c, struct pso_pointer tail );
|
||||
struct pso_pointer make_string( struct pso4 *frame_pointer, wint_t c,
|
||||
struct pso_pointer tail );
|
||||
|
||||
struct pso_pointer make_keyword( wint_t c, struct pso_pointer tail );
|
||||
struct pso_pointer make_keyword( struct pso4 *frame_pointer, wint_t c,
|
||||
struct pso_pointer tail );
|
||||
|
||||
struct pso_pointer make_symbol( wint_t c, struct pso_pointer tail );
|
||||
struct pso_pointer make_symbol( struct pso4 *frame_pointer, wint_t c,
|
||||
struct pso_pointer tail );
|
||||
|
||||
struct pso_pointer c_string_to_lisp_string( char32_t *string );
|
||||
struct pso_pointer c_string_to_lisp_string( struct pso4 *frame_pointer,
|
||||
char32_t * string );
|
||||
|
||||
struct pso_pointer c_string_to_lisp_keyword( char32_t *symbol );
|
||||
struct pso_pointer c_string_to_lisp_keyword( struct pso4 *frame_pointer,
|
||||
char32_t * symbol );
|
||||
|
||||
struct pso_pointer c_string_to_lisp_symbol( char32_t *symbol );
|
||||
struct pso_pointer c_string_to_lisp_symbol( struct pso4 *frame_pointer,
|
||||
char32_t * symbol );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue