aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser.c2
-rw-r--r--src/program.c4
-rw-r--r--src/std/hash_map.c7
3 files changed, 11 insertions, 2 deletions
diff --git a/src/parser.c b/src/parser.c
index cdf7c5b..03b835e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -521,7 +521,7 @@ static void parser_parse_else_if_statement_loop(Parser *self, IfStatement *if_st
if(!next_else_if)
break;
else_if_stmt->next_else_if_stmt = next_else_if;
- /* else statement, which because they have no conditions; can't be followed by another else statement */
+ /* else statement that has no condition can't be followed by another else statement */
if(!else_if_stmt->condition)
break;
else_if_stmt = next_else_if;
diff --git a/src/program.c b/src/program.c
index 9ec1b41..17aee03 100644
--- a/src/program.c
+++ b/src/program.c
@@ -91,6 +91,10 @@ int amal_program_add_extern_func(amal_program *self, BufferView name, void *func
ProgramExternFunc extern_func;
extern_func.func = func_ptr;
extern_func.args_byte_size = args_byte_size;
+
+ if(hash_map_contains(&self->extern_funcs_map, name))
+ return AMAL_PROGRAM_EXTERN_FUNC_ALREADY_EXISTS;
+
return hash_map_insert(&self->extern_funcs_map, name, &extern_func);
}
diff --git a/src/std/hash_map.c b/src/std/hash_map.c
index 2b29f2e..48e9e38 100644
--- a/src/std/hash_map.c
+++ b/src/std/hash_map.c
@@ -192,7 +192,8 @@ bool hash_map_get(HashMap *self, BufferView key, void *value) {
BufferView bucket_key;
bucket_key = bucket_node_get_key(bucket_node);
if(hash == bucket_node_get_hash(bucket_node) && self->compare_func(&key, &bucket_key) == 0) {
- am_memcpy(value, bucket_node_get_value(bucket_node), self->value_type_size);
+ if(value)
+ am_memcpy(value, bucket_node_get_value(bucket_node), self->value_type_size);
return bool_true;
}
}
@@ -200,6 +201,10 @@ bool hash_map_get(HashMap *self, BufferView key, void *value) {
return bool_false;
}
+bool hash_map_contains(HashMap *self, BufferView key) {
+ return hash_map_get(self, key, NULL);
+}
+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int hash_map_compare_string(const void *a, const void *b) {