Compiles and tests, but there are still major problems.
This commit is contained in:
parent
3f3b596ff0
commit
492460f37e
|
@ -11,6 +11,9 @@
|
|||
#ifndef __integer_h
|
||||
#define __integer_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct cons_pointer make_integer(int64_t value, struct cons_pointer more);
|
||||
|
||||
struct cons_pointer add_integers(struct cons_pointer a,
|
||||
|
|
|
@ -24,13 +24,30 @@
|
|||
#include "intern.h"
|
||||
#include "print.h"
|
||||
#include "stack.h"
|
||||
#include "vectorspace.h"
|
||||
|
||||
/**
|
||||
* True if the tag on the cell at this `pointer` is this `tag`, else false.
|
||||
* True if the tag on the cell at this `pointer` is this `tag`, or, if the tag
|
||||
* of the cell is `VECP`, if the tag of the vectorspace object indicated by the
|
||||
* cell is this `tag`, else false.
|
||||
*/
|
||||
bool check_tag( struct cons_pointer pointer, char *tag ) {
|
||||
bool result = false;
|
||||
struct cons_space_object cell = pointer2cell( pointer );
|
||||
return strncmp( &cell.tag.bytes[0], tag, TAGLENGTH ) == 0;
|
||||
|
||||
result = strncmp( &cell.tag.bytes[0], tag, TAGLENGTH ) == 0;
|
||||
|
||||
if ( !result ) {
|
||||
// if ( vectorpointp( pointer ) ) { <<< this line blows up!
|
||||
// // struct vector_space_object *vec = pointer_to_vso( pointer );
|
||||
|
||||
// // if ( vec != NULL ) {
|
||||
// // result = strncmp( &vec->header.tag.bytes[0], tag, TAGLENGTH ) == 0;
|
||||
// // }
|
||||
// }
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,9 +92,17 @@ struct cons_pointer c_type( struct cons_pointer pointer ) {
|
|||
struct cons_pointer result = NIL;
|
||||
struct cons_space_object cell = pointer2cell( pointer );
|
||||
|
||||
if ( strncmp( (char *)&cell.tag.bytes, VECTORPOINTTAG, TAGLENGTH ) == 0 ) {
|
||||
struct vector_space_object *vec = pointer_to_vso( pointer );
|
||||
|
||||
for ( int i = TAGLENGTH - 1; i >= 0; i-- ) {
|
||||
result = make_string( (wchar_t)vec->header.tag.bytes[i], result );
|
||||
}
|
||||
} else {
|
||||
for ( int i = TAGLENGTH - 1; i >= 0; i-- ) {
|
||||
result = make_string( (wchar_t)cell.tag.bytes[i], result );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -227,15 +252,18 @@ struct cons_pointer make_nlambda( struct cons_pointer args,
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a hash value for this string.
|
||||
* Return a hash value for this string like thing.
|
||||
*
|
||||
* What's important here is that two strings with the same characters in the
|
||||
* same order should have the same hash value, even if one was created using
|
||||
* `"foobar"` and the other by `(append "foo" "bar")`. I *think* this function
|
||||
* has that property. I doubt that it's the most efficient hash function to
|
||||
* have that property.
|
||||
*
|
||||
* returns 0 for things which are not string like.
|
||||
*/
|
||||
uint32_t calculate_hash( wint_t c, struct cons_pointer ptr) {
|
||||
uint32_t calculate_hash(wint_t c, struct cons_pointer ptr)
|
||||
{
|
||||
struct cons_space_object *cell = &pointer2cell(ptr);
|
||||
uint32_t result = 0;
|
||||
|
||||
|
@ -244,9 +272,12 @@ struct cons_space_object *cell = &pointer2cell(ptr);
|
|||
case KEYTV:
|
||||
case STRINGTV:
|
||||
case SYMBOLTV:
|
||||
if (nilp(ptr)) {
|
||||
if (nilp(ptr))
|
||||
{
|
||||
result = (uint32_t)c;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ((uint32_t)c *
|
||||
cell->payload.string.hash) &
|
||||
0xffffffff;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <wctype.h>
|
||||
|
||||
#include "io/fopen.h"
|
||||
#include "memory/conspage.h"
|
||||
// #include "memory/conspage.h"
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "arith/integer.h"
|
||||
#include "memory/consspaceobject.h"
|
||||
#include "memory/hashmap.h"
|
||||
#include "memory/vectorspace.h"
|
||||
|
||||
/**
|
||||
* Get the hash value for the cell indicated by this `ptr`; currently only
|
||||
|
@ -45,17 +46,32 @@ struct cons_pointer lisp_get_hash(struct stack_frame *frame,
|
|||
}
|
||||
|
||||
/**
|
||||
* Make a hashmap with this number of buckets.
|
||||
* Make a hashmap with this number of buckets, using this `hash_fn`. If
|
||||
* `hash_fn` is `NIL`, use the standard hash funtion.
|
||||
*/
|
||||
struct cons_pointer make_hashmap( uint32_t n_buckets) {
|
||||
struct cons_pointer make_hashmap( uint32_t n_buckets, struct cons_pointer hash_fn) {
|
||||
struct cons_pointer result = make_vso(HASHTAG,
|
||||
(sizeof(struct cons_pointer) * (n_buckets + 1)) +
|
||||
(sizeof(uint32_t) * 2));
|
||||
|
||||
// TODO: fill in the payload!
|
||||
|
||||
struct hashmap_payload *payload =
|
||||
(struct hashmap_payload *) &pointer_to_vso(result)->payload;
|
||||
|
||||
payload->hash_fn = hash_fn;
|
||||
payload->n_buckets = n_buckets;
|
||||
for (int i = 0; i < n_buckets; i++) {
|
||||
payload->buckets[i] = NIL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct cons_pointer clone_hashmap(struct cons_pointer ptr) {
|
||||
struct cons_pointer result = NIL;
|
||||
|
||||
if (hashmapp(ptr)) {
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
#ifndef __psse_hashmap_h
|
||||
#define __psse_hashmap_h
|
||||
|
||||
#include "arith/integer.h"
|
||||
#include "memory/conspage.h"
|
||||
#include "memory/consspaceobject.h"
|
||||
#include "memory/vectorspace.h"
|
||||
|
||||
|
|
|
@ -28,18 +28,24 @@
|
|||
#define HASHTAG "HASH"
|
||||
#define HASHTV 0
|
||||
|
||||
#define hashmapp(conspoint)((check_tag(conspoint,HASHTAG)))
|
||||
|
||||
/*
|
||||
* a namespace (i.e. a binding of names to values, implemented as a hashmap)
|
||||
*/
|
||||
#define NAMESPACETAG "NMSP"
|
||||
#define NAMESPACETV 0
|
||||
|
||||
#define namespacep(conspoint)(check_tag(conspoint,NAMESPACETAG))
|
||||
|
||||
/*
|
||||
* a vector of cons pointers.
|
||||
*/
|
||||
#define VECTORTAG "VECT"
|
||||
#define VECTORTV 0
|
||||
|
||||
#define vectorp(conspoint)(check_tag(conspoint,VECTORTAG))
|
||||
|
||||
/**
|
||||
* given a pointer to a vector space object, return the object.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue