Now safely detecting (but not dealing with) integer overflow.

Also printing and reading integers with comma separators.
This commit is contained in:
Simon Brooke 2018-12-31 16:11:55 +00:00
parent 72ab4af20e
commit e5f40032e9
3 changed files with 48 additions and 22 deletions

View file

@ -359,9 +359,10 @@ c_apply( struct stack_frame *frame, struct cons_pointer frame_pointer,
result = next_pointer;
} else {
result =
( *fn_cell.payload.special.
executable ) ( get_stack_frame( next_pointer ),
next_pointer, env );
( *fn_cell.payload.
special.executable ) ( get_stack_frame
( next_pointer ),
next_pointer, env );
debug_print( L"Special form returning: ", DEBUG_EVAL );
debug_print_object( result, DEBUG_EVAL );
debug_println( DEBUG_EVAL );
@ -1015,7 +1016,7 @@ struct cons_pointer lisp_repl( struct stack_frame *frame,
struct cons_pointer prompt_name = c_string_to_lisp_symbol( L"*prompt*" );
struct cons_pointer old_oblist = oblist;
struct cons_pointer new_env = env;
inc_ref(env);
inc_ref( env );
inc_ref( input );
inc_ref( output );
@ -1047,8 +1048,8 @@ struct cons_pointer lisp_repl( struct stack_frame *frame,
debug_println( DEBUG_REPL );
new_env = make_cons( c_car( cursor ), new_env );
inc_ref( new_env);
dec_ref( old_new_env);
inc_ref( new_env );
dec_ref( old_new_env );
cursor = c_cdr( cursor );
}
old_oblist = oblist;

View file

@ -175,7 +175,7 @@ struct cons_pointer read_number( struct stack_frame *frame,
initial );
for ( c = initial; iswdigit( c )
|| c == btowc( '.' ) || c == btowc( '/' ); c = fgetwc( input ) ) {
|| c == L'.' || c == L'/' || c == L','; c = fgetwc( input ) ) {
if ( c == btowc( '.' ) ) {
if ( seen_period || dividend != 0 ) {
return throw_exception( c_string_to_lisp_string
@ -194,6 +194,8 @@ struct cons_pointer read_number( struct stack_frame *frame,
accumulator = 0;
}
} else if ( c == L',' ) {
// silently ignore it.
} else {
accumulator = accumulator * 10 + ( ( int ) c - ( int ) '0' );