Hashmaps sort-of work but there are still bugs and one test is failing that wasn't.
This commit is contained in:
parent
bfd7304da1
commit
4fc9545be8
12 changed files with 206 additions and 487 deletions
|
|
@ -25,7 +25,6 @@
|
|||
#include "equal.h"
|
||||
#include "hashmap.h"
|
||||
#include "lispops.h"
|
||||
#include "map.h"
|
||||
#include "print.h"
|
||||
|
||||
/**
|
||||
|
|
@ -109,7 +108,7 @@ struct cons_pointer c_assoc( struct cons_pointer key,
|
|||
}
|
||||
}
|
||||
} else if (hashmapp( store)) {
|
||||
result = assoc_in_map( key, store);
|
||||
result = hashmap_get( store, key);
|
||||
} else {
|
||||
result = throw_exception(c_string_to_lisp_string(L"Store is of unknown type"), NIL);
|
||||
}
|
||||
|
|
@ -140,8 +139,8 @@ struct cons_pointer
|
|||
|
||||
if (nilp( store) || consp(store)) {
|
||||
result = make_cons( make_cons( key, value ), store );
|
||||
} else if (vectorpointp( store)) {
|
||||
result = bind_in_map( store, key, value);
|
||||
} else if (hashmapp( store)) {
|
||||
result = hashmap_put( store, key, value);
|
||||
}
|
||||
|
||||
debug_print( L"set returning ", DEBUG_BIND);
|
||||
|
|
@ -196,3 +195,4 @@ intern( struct cons_pointer key, struct cons_pointer environment ) {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
#include "intern.h"
|
||||
#include "io.h"
|
||||
#include "lispops.h"
|
||||
#include "map.h"
|
||||
#include "print.h"
|
||||
#include "read.h"
|
||||
#include "stack.h"
|
||||
|
|
@ -378,7 +377,7 @@ struct cons_pointer
|
|||
|
||||
case VECTORPOINTTV:
|
||||
switch ( pointer_to_vso(fn_pointer)->header.tag.value) {
|
||||
case MAPTV:
|
||||
case HASHTV:
|
||||
/* \todo: if arg[0] is a CONS, treat it as a path */
|
||||
result = c_assoc( eval_form(frame,
|
||||
frame_pointer,
|
||||
|
|
@ -803,6 +802,26 @@ lisp_assoc( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
|||
return c_assoc( frame->arg[0], frame->arg[1] );
|
||||
}
|
||||
|
||||
struct cons_pointer c_keys(struct cons_pointer store) {
|
||||
struct cons_pointer result = NIL;
|
||||
|
||||
if ( hashmapp( store ) ) {
|
||||
result = hashmap_keys( store );
|
||||
} else if ( consp( store ) ) {
|
||||
for ( struct cons_pointer c = store; !nilp( c ); c = c_cdr( c ) ) {
|
||||
result = make_cons( c_car( c ), result );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct cons_pointer lisp_keys( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env ) {
|
||||
return c_keys( frame->arg[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function; are these two objects the same object? Shallow, cheap equality.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,12 +26,14 @@
|
|||
* utilities
|
||||
*/
|
||||
|
||||
struct cons_pointer c_keys( struct cons_pointer store );
|
||||
|
||||
struct cons_pointer c_reverse( struct cons_pointer arg );
|
||||
|
||||
struct cons_pointer
|
||||
c_progn( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer expressions, struct cons_pointer env );
|
||||
struct cons_pointer c_progn( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer expressions,
|
||||
struct cons_pointer env );
|
||||
|
||||
/**
|
||||
* Useful building block; evaluate this single form in the context of this
|
||||
|
|
@ -56,7 +58,6 @@ struct cons_pointer eval_forms( struct stack_frame *frame,
|
|||
struct cons_pointer list,
|
||||
struct cons_pointer env );
|
||||
|
||||
|
||||
/*
|
||||
* special forms
|
||||
*/
|
||||
|
|
@ -67,17 +68,21 @@ struct cons_pointer lisp_apply( struct stack_frame *frame,
|
|||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer
|
||||
lisp_oblist( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_keys( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer
|
||||
lisp_set( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_oblist( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer
|
||||
lisp_set_shriek( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_set( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer lisp_set_shriek( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
/**
|
||||
* Construct an interpretable function.
|
||||
|
|
@ -90,17 +95,17 @@ struct cons_pointer lisp_lambda( struct stack_frame *frame,
|
|||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_length( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
/**
|
||||
* Construct an interpretable special form.
|
||||
*
|
||||
* @param frame the stack frame in which the expression is to be interpreted;
|
||||
* @param env the environment in which it is to be intepreted.
|
||||
*/
|
||||
struct cons_pointer
|
||||
lisp_nlambda( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_nlambda( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer lisp_quote( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
|
|
@ -146,10 +151,9 @@ struct cons_pointer lisp_reverse( struct stack_frame *frame,
|
|||
* @param env My environment (ignored).
|
||||
* @return As a Lisp string, the tag of the object which is the argument.
|
||||
*/
|
||||
struct cons_pointer
|
||||
lisp_type( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer lisp_type( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
/**
|
||||
* Function; evaluate the forms which are listed in my single argument
|
||||
|
|
@ -161,9 +165,9 @@ lisp_type( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
|||
* @return the value of the last form on the sequence which is my single
|
||||
* argument.
|
||||
*/
|
||||
struct cons_pointer
|
||||
lisp_progn( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_progn( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
/**
|
||||
* Special form: conditional. Each arg is expected to be a list; if the first
|
||||
|
|
@ -174,22 +178,22 @@ lisp_progn( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
|||
* @param env My environment (ignored).
|
||||
* @return the value of the last form of the first successful clause.
|
||||
*/
|
||||
struct cons_pointer
|
||||
lisp_cond( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_cond( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
/**
|
||||
* Throw an exception.
|
||||
* `throw_exception` is a misnomer, because it doesn't obey the calling signature of a
|
||||
* lisp function; but it is nevertheless to be preferred to make_exception. A
|
||||
* real `throw_exception`, which does, will be needed.
|
||||
* `throw_exception` is a misnomer, because it doesn't obey the calling
|
||||
* signature of a lisp function; but it is nevertheless to be preferred to
|
||||
* make_exception. A real `throw_exception`, which does, will be needed.
|
||||
*/
|
||||
struct cons_pointer throw_exception( struct cons_pointer message,
|
||||
struct cons_pointer frame_pointer );
|
||||
|
||||
struct cons_pointer
|
||||
lisp_exception( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
struct cons_pointer lisp_exception( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
struct cons_pointer env );
|
||||
|
||||
struct cons_pointer lisp_source( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue