fix seg fault when callng a function with not enough parameters

This commit is contained in:
William Bell
2025-10-22 03:52:47 +01:00
parent a9b1d23f79
commit b6714b390a
6 changed files with 13 additions and 5 deletions

View File

@@ -16,11 +16,11 @@ typedef enum {
__base__, __base__,
__class__, __class__,
__name__, __name__,
__binding__,
__function__,
BUILT_IN_ARRAY_COUNT, BUILT_IN_ARRAY_COUNT,
__binding__,
__function__,
__add__, __add__,
__string__, __string__,
__subtract__, __subtract__,

View File

@@ -121,6 +121,7 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv,
(int)object_name->value.as_str->length, (int)object_name->value.as_str->length,
object_name->value.as_str->data, object_name->value.as_str->data,
object->value.argon_fn->number_of_parameters, argc); object->value.argon_fn->number_of_parameters, argc);
return;
} }
Stack *scope = create_scope(object->value.argon_fn->stack, true); Stack *scope = create_scope(object->value.argon_fn->stack, true);
for (size_t i = 0; i < argc; i++) { for (size_t i = 0; i < argc; i++) {

View File

@@ -35,6 +35,8 @@ const char *built_in_field_names[BUILT_IN_FIELDS_COUNT] = {
"__class__", "__class__",
"__name__", "__name__",
"", // above is anything that gets stored in built in slots "", // above is anything that gets stored in built in slots
"__binding__",
"__function__",
"__add__", "__add__",
"__string__", "__string__",
"__subtract__", "__subtract__",
@@ -44,8 +46,6 @@ const char *built_in_field_names[BUILT_IN_FIELDS_COUNT] = {
"__init__", "__init__",
"__boolean__", "__boolean__",
"__get_attr__", "__get_attr__",
"__binding__",
"__function__",
"address", "address",
"__call__", "__call__",
"__number__", "__number__",

View File

@@ -13,6 +13,8 @@
extern ArgonObject *BASE_CLASS; extern ArgonObject *BASE_CLASS;
extern const char *built_in_field_names[BUILT_IN_FIELDS_COUNT];
typedef struct ArgonObject ArgonObject; typedef struct ArgonObject ArgonObject;
ArgonObject *new_class(); ArgonObject *new_class();

View File

@@ -615,7 +615,6 @@ void bootstrap_types() {
add_builtin_field(ARGON_METHOD_TYPE, __base__, BASE_CLASS); add_builtin_field(ARGON_METHOD_TYPE, __base__, BASE_CLASS);
add_builtin_field(ARGON_METHOD_TYPE, __name__, add_builtin_field(ARGON_METHOD_TYPE, __name__,
new_string_object_null_terminated("method")); new_string_object_null_terminated("method"));
create_ARGON_NUMBER_TYPE();
add_builtin_field( add_builtin_field(
BASE_CLASS, __new__, BASE_CLASS, __new__,
@@ -695,6 +694,7 @@ void bootstrap_types() {
BASE_CLASS, __set_attr__, BASE_CLASS, __set_attr__,
create_argon_native_function("__set_attr__", BASE_CLASS___set_attr__)); create_argon_native_function("__set_attr__", BASE_CLASS___set_attr__));
create_ARGON_DICTIONARY_TYPE(); create_ARGON_DICTIONARY_TYPE();
create_ARGON_NUMBER_TYPE();
} }
void add_to_hashmap(struct hashmap_GC *hashmap, char *name, ArgonObject *value) { void add_to_hashmap(struct hashmap_GC *hashmap, char *name, ArgonObject *value) {

5
tests/class_method.ar Normal file
View File

@@ -0,0 +1,5 @@
string.cool(self) = do
term.log(self, self.length)
return 10
'hello world'.cool()
string.cool('goodbye world')