bug fix in map select/insert routines

This commit is contained in:
cozis
2021-12-05 17:26:04 +01:00
parent 014287509a
commit eb15233a76
5 changed files with 138 additions and 36 deletions
+18 -1
View File
@@ -268,7 +268,8 @@ _Bool Debug_Callback(Runtime *runtime, void *userp)
"quit .............. Stop execution\n"
"continue .......... Run until a breakpoint or the end of the code is reached\n"
"breakpoint ........ Add a breakpoint\n"
"stack ............. Show the contents of the stack\n");
"stack ............. Show the contents of the stack\n"
"disassembly ....... Show the current file's bytecode\n");
}
else if(!strcmp(argv[1], "help"))
{
@@ -316,6 +317,17 @@ _Bool Debug_Callback(Runtime *runtime, void *userp)
" | reached.\n"
"\n");
}
else if(!strcmp(argv[1], "disassembly"))
{
fprintf(stderr,
"\n"
" Command | disassembly\n"
" | \n"
" Usage | > disassembly\n"
" | \n"
" Description | Show the current file's bytecode.\n"
"\n");
}
else if(!strcmp(argv[1], "breakpoint"))
{
fprintf(stderr,
@@ -444,6 +456,11 @@ _Bool Debug_Callback(Runtime *runtime, void *userp)
dbg->continuing = 1;
return 1;
}
else if(!strcmp(argv[0], "disassembly"))
{
Executable_Dump(Runtime_GetCurrentExecutable(runtime));
return 1;
}
else if(!strcmp(argv[0], "step"))
{
return 1;
+23 -1
View File
@@ -18,6 +18,7 @@ static Object *bin_socket(Runtime *runtime, Object **argv, unsigned int argc, Er
static Object *bin_accept(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
static Object *bin_connect(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
static Object *bin_inet_aton(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
static Object *bin_inet_ntoa(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
static Object *bin_htonl(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
static Object *bin_ntohl(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
static Object *bin_htons(Runtime *runtime, Object **argv, unsigned int argc, Error *error);
@@ -135,6 +136,10 @@ static Object *select_(Object *self, Object *key, Heap *heap, Error *err)
{
if(!strcmp(s, "inet_aton"))
return Object_FromNativeFunction(bm->runtime, bin_inet_aton, 2, heap, err);
if(!strcmp(s, "inet_ntoa"))
return Object_FromNativeFunction(bm->runtime, bin_inet_ntoa, 1, heap, err);
return NULL;
}
@@ -513,6 +518,23 @@ static Object *bin_inet_aton(Runtime *runtime, Object **argv, unsigned int argc,
return Object_FromInt(r, heap, error);
}
static Object *bin_inet_ntoa(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
{
assert(argc == 1);
Heap *heap = Runtime_GetHeap(runtime);
struct in_addr in_addr;
if(!get_in_addr_from_map(argv[0], &in_addr, heap, error))
return NULL;
const char *addr = inet_ntoa(in_addr);
assert(addr != NULL);
return Object_FromString(addr, -1, heap, error);
}
static Object *bin_htonl(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
{
assert(argc == 1);
@@ -632,7 +654,7 @@ static Object *bin_accept(Runtime *runtime, Object **argv, unsigned int argc, Er
Heap *heap = Runtime_GetHeap(runtime);
int sockfd = Object_ToInt(argv[0], error);
long long int sockfd = Object_ToInt(argv[0], error);
if(error->occurred) return NULL;
struct sockaddr_in addr;
+6 -6
View File
@@ -78,9 +78,9 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
MapObject *map = (MapObject*) self;
int mask = map->mapper_size - 1;
int hash = Object_Hash(key, error);
int pert = hash;
unsigned int mask = map->mapper_size - 1;
unsigned int hash = Object_Hash(key, error);
unsigned int pert = hash;
if(error->occurred)
// No hash function.
@@ -200,9 +200,9 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e
if(!grow(map, heap, error))
return 0;
int mask = map->mapper_size - 1;
int hash = Object_Hash(key, error);
int pert = hash;
unsigned int mask = map->mapper_size - 1;
unsigned int hash = Object_Hash(key, error);
unsigned int pert = hash;
if(error->occurred)
// No hash function.