Compare commits

..

No commits in common. "af21e506efbf22884d5eb30fb1cbb504afe43a51" and "3665326c55b30dc485365926db0f6beff24aaa90" have entirely different histories.

5 changed files with 40 additions and 65 deletions

View file

@ -9,7 +9,6 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include "arith/integer.h" #include "arith/integer.h"
#include "arith/peano.h" #include "arith/peano.h"
@ -364,38 +363,22 @@ bool equal( struct cons_pointer a, struct cons_pointer b ) {
/* TODO: it is not OK to do this on the stack since list-like /* TODO: it is not OK to do this on the stack since list-like
* structures can be of indefinite extent. It *must* be done by * structures can be of indefinite extent. It *must* be done by
* iteration (and even that is problematic) */ * iteration (and even that is problematic) */
if (cell_a->payload.string.hash == cell_b->payload.string.hash) {
wchar_t a_buff[ STRING_SHIPYARD_SIZE], b_buff[ STRING_SHIPYARD_SIZE];
uint32_t tag = cell_a->tag.value;
int i = 0;
memset(a_buff,0,sizeof(a_buff));
memset(b_buff,0,sizeof(b_buff));
for (; (i < (STRING_SHIPYARD_SIZE - 1)) && !nilp( a) && !nilp( b); i++) {
a_buff[i] = cell_a->payload.string.character;
a = c_cdr(a);
cell_a = &pointer2cell( a );
b_buff[i] = cell_b->payload.string.character;
b = c_cdr( b);
cell_b = &pointer2cell( b);
}
#ifdef DEBUG #ifdef DEBUG
debug_print( L"Comparing '", DEBUG_ARITH); debug_print( L"Comparing '", DEBUG_ARITH);
debug_print( a_buff, DEBUG_ARITH); debug_print_object( a, DEBUG_ARITH);
debug_print( L"' to '", DEBUG_ARITH); debug_print( L"' to '", DEBUG_ARITH);
debug_print( b_buff, DEBUG_ARITH); debug_print_object( b, DEBUG_ARITH);
debug_print( L"'\n", DEBUG_ARITH);
#endif #endif
result =
/* OK, now we have wchar string buffers loaded from the objects. We cell_a->payload.string.hash == cell_b->payload.string.hash
* may not have exhausted either string, so the buffers being equal && cell_a->payload.string.character ==
* isn't sufficient. So we recurse at least once. */ cell_b->payload.string.character
&&
result = (wcsncmp( a_buff, b_buff, i) == 0) && equal( c_cdr(a), c_cdr(b)); ( equal
} ( cell_a->payload.string.cdr,
cell_b->payload.string.cdr )
|| ( end_of_string( cell_a->payload.string.cdr )
&& end_of_string( cell_b->payload.string.cdr ) ) );
break; break;
case VECTORPOINTTV: case VECTORPOINTTV:
if ( cell_b->tag.value == VECTORPOINTTV) { if ( cell_b->tag.value == VECTORPOINTTV) {

View file

@ -15,12 +15,6 @@
#ifndef __equal_h #ifndef __equal_h
#define __equal_h #define __equal_h
/**
* size of buffer for assembling strings. Likely to be useful to
* read, too.
*/
#define STRING_SHIPYARD_SIZE 1024
/** /**
* Shallow, and thus cheap, equality: true if these two objects are * Shallow, and thus cheap, equality: true if these two objects are
* the same object, else false. * the same object, else false.

View file

@ -1639,6 +1639,7 @@ struct cons_pointer lisp_let( struct stack_frame *frame,
bindings = bindings =
make_cons( make_cons( symbol, val ), bindings ); make_cons( make_cons( symbol, val ), bindings );
} else { } else {
result = result =
throw_exception( c_string_to_lisp_string throw_exception( c_string_to_lisp_string
@ -1648,8 +1649,6 @@ struct cons_pointer lisp_let( struct stack_frame *frame,
} }
} }
debug_print( L"\nlet: bindings complete.\n", DEBUG_BIND);
/* i.e., no exception yet */ /* i.e., no exception yet */
for ( int form = 1; !exceptionp( result ) && form < frame->args; form++ ) { for ( int form = 1; !exceptionp( result ) && form < frame->args; form++ ) {
result = result =
@ -1657,11 +1656,10 @@ struct cons_pointer lisp_let( struct stack_frame *frame,
bindings ); bindings );
} }
/* release the local bindings as they go out of scope! **BUT** // release the local bindings as they go out of scope!
* bindings were consed onto the front of env, so caution... */ for (struct cons_pointer cursor = bindings; !eq( cursor, env); cursor = c_cdr(cursor)) {
// for (struct cons_pointer cursor = bindings; !eq( cursor, env); cursor = c_cdr(cursor)) { dec_ref( cursor);
// dec_ref( cursor); }
// }
return result; return result;

View file

@ -2,28 +2,28 @@
result=0 result=0
echo -n "$0: let with two bindings, one form in body..." # echo -n "$0: let with two bindings, one form in body..."
expected='11' # expected='11'
actual=`echo "(let ((a . 5)(b . 6)) (+ a b))" | target/psse 2>/dev/null | tail -1` # actual=`echo "(let ((a . 5)(b . 6)) (+ a b))" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ] # if [ "${expected}" = "${actual}" ]
then # then
echo "OK" # echo "OK"
else # else
echo "Fail: expected '$expected', got '$actual'" # echo "Fail: expected '$expected', got '$actual'"
result=`echo "${result} + 1" | bc` # result=`echo "${result} + 1" | bc`
fi # fi
echo -n "$0: let with two bindings, two forms in body..." # echo -n "$0: let with two bindings, two forms in body..."
expected='1' # expected='1'
actual=`echo "(let ((a . 5)(b . 6)) (+ a b) (- b a))" | target/psse 2>/dev/null | tail -1` # actual=`echo "(let ((a . 5)(b . 6)) (+ a b) (- b a))" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ] # if [ "${expected}" = "${actual}" ]
then # then
echo "OK" # echo "OK"
else # else
echo "Fail: expected '$expected', got '$actual'" # echo "Fail: expected '$expected', got '$actual'"
result=`echo "${result} + 1" | bc` # result=`echo "${result} + 1" | bc`
fi # fi
exit ${result} exit ${result}