function definitions now remember the Lip_Object symbols and keys
not only the strings.. wtf was I thinkingh before?
This commit is contained in:
+4
-4
@@ -851,17 +851,17 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
printf("Postitional: {");
|
||||
if (fun->value.function.positional_arguments->next_index != 0) {
|
||||
printf("%s",
|
||||
Memory::get_c_str(fun->value.function.positional_arguments->identifiers[0]));
|
||||
Memory::get_c_str(fun->value.function.positional_arguments->symbols[0]->value.symbol.identifier));
|
||||
for (int i = 1; i < fun->value.function.positional_arguments->next_index; ++i) {
|
||||
printf(", %s",
|
||||
Memory::get_c_str(fun->value.function.positional_arguments->identifiers[i]));
|
||||
Memory::get_c_str(fun->value.function.positional_arguments->symbols[i]->value.symbol.identifier));
|
||||
}
|
||||
}
|
||||
printf("}\n");
|
||||
printf("Keyword: {");
|
||||
if (fun->value.function.keyword_arguments->next_index != 0) {
|
||||
printf("%s",
|
||||
Memory::get_c_str(fun->value.function.keyword_arguments->identifiers[0]));
|
||||
Memory::get_c_str(fun->value.function.keyword_arguments->keywords[0]->value.symbol.identifier));
|
||||
if (fun->value.function.keyword_arguments->values->data[0]) {
|
||||
printf(" (");
|
||||
print(fun->value.function.keyword_arguments->values->data[0]);
|
||||
@@ -869,7 +869,7 @@ proc load_built_ins_into_environment(Environment* env) -> void {
|
||||
}
|
||||
for (int i = 1; i < fun->value.function.keyword_arguments->next_index; ++i) {
|
||||
printf(", %s",
|
||||
Memory::get_c_str(fun->value.function.keyword_arguments->identifiers[i]));
|
||||
Memory::get_c_str(fun->value.function.keyword_arguments->keywords[i]->value.symbol.identifier));
|
||||
if (fun->value.function.keyword_arguments->values->data[i]) {
|
||||
printf(" (");
|
||||
print(fun->value.function.keyword_arguments->values->data[i]);
|
||||
|
||||
@@ -93,23 +93,23 @@ proc generate_docs(Environment* env, String* path) -> void {
|
||||
if (!printed_at_least_some_args)
|
||||
fprintf(f, ":");
|
||||
fprintf(f, "\n - postitional :: ");
|
||||
fprintf(f, "=%s=", Memory::get_c_str(fun->value.function.positional_arguments->identifiers[0]));
|
||||
fprintf(f, "=%s=", Memory::get_c_str(fun->value.function.positional_arguments->symbols[0]->value.symbol.identifier));
|
||||
for (int i = 1; i < fun->value.function.positional_arguments->next_index; ++i) {
|
||||
fprintf(f, ", =%s=", Memory::get_c_str(fun->value.function.positional_arguments->identifiers[i]));
|
||||
fprintf(f, ", =%s=", Memory::get_c_str(fun->value.function.positional_arguments->symbols[i]->value.symbol.identifier));
|
||||
}
|
||||
}
|
||||
if (fun->value.function.keyword_arguments->next_index != 0) {
|
||||
if (!printed_at_least_some_args)
|
||||
fprintf(f, ":");
|
||||
fprintf(f, "\n - keyword :: ");
|
||||
fprintf(f, "=%s=", Memory::get_c_str(fun->value.function.keyword_arguments->identifiers[0]));
|
||||
fprintf(f, "=%s=", Memory::get_c_str(fun->value.function.keyword_arguments->keywords[0]->value.symbol.identifier));
|
||||
if (fun->value.function.keyword_arguments->values->data[0]) {
|
||||
fprintf(f, " =(");
|
||||
print(fun->value.function.keyword_arguments->values->data[0], true, f);
|
||||
fprintf(f, ")=");
|
||||
}
|
||||
for (int i = 1; i < fun->value.function.keyword_arguments->next_index; ++i) {
|
||||
fprintf(f, ", =%s=", Memory::get_c_str(fun->value.function.keyword_arguments->identifiers[i]));
|
||||
fprintf(f, ", =%s=", Memory::get_c_str(fun->value.function.keyword_arguments->keywords[i]->value.symbol.identifier));
|
||||
if (fun->value.function.keyword_arguments->values->data[i]) {
|
||||
fprintf(f, " =(");
|
||||
print(fun->value.function.keyword_arguments->values->data[i], true, f);
|
||||
|
||||
+6
-6
@@ -19,7 +19,7 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Function* function) ->
|
||||
|
||||
// NOTE(Felix): We have to copy all the arguments, otherwise
|
||||
// we change the program code.
|
||||
try_void sym = Memory::get_or_create_lisp_object_symbol(function->positional_arguments->identifiers[i]);
|
||||
try_void sym = function->positional_arguments->symbols[i];
|
||||
define_symbol(
|
||||
sym,
|
||||
Memory::copy_lisp_object_except_pairs(arguments->value.pair.first),
|
||||
@@ -54,7 +54,7 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Function* function) ->
|
||||
for (int i = 0; i < function->keyword_arguments->next_index; ++i) {
|
||||
if (string_equal(
|
||||
arguments->value.pair.first->value.symbol.identifier,
|
||||
function->keyword_arguments->identifiers[i]))
|
||||
function->keyword_arguments->keywords[i]->value.symbol.identifier))
|
||||
{
|
||||
accepted = true;
|
||||
break;
|
||||
@@ -127,7 +127,7 @@ proc apply_arguments_to_function(Lisp_Object* arguments, Function* function) ->
|
||||
proc check_keyword_args = [&]() -> void {
|
||||
// check if all necessary keywords have been read in
|
||||
for (int i = 0; i < function->keyword_arguments->next_index; ++i) {
|
||||
String* defined_keyword = function->keyword_arguments->identifiers[i];
|
||||
String* defined_keyword = function->keyword_arguments->keywords[i]->value.symbol.identifier;
|
||||
bool was_set = false;
|
||||
for (int j = 0; j < read_in_keywords->next_index; ++j) {
|
||||
if (string_equal(
|
||||
@@ -231,7 +231,7 @@ proc parse_argument_list(Lisp_Object* arguments, Function* function) -> void {
|
||||
// okay wow we found an actual symbol
|
||||
append_to_positional_argument_list(
|
||||
function->positional_arguments,
|
||||
arguments->value.pair.first->value.symbol.identifier);
|
||||
arguments->value.pair.first);
|
||||
|
||||
arguments = arguments->value.pair.rest;
|
||||
}
|
||||
@@ -293,7 +293,7 @@ proc parse_argument_list(Lisp_Object* arguments, Function* function) -> void {
|
||||
Lisp_Object* ret;
|
||||
try_void ret = eval_expr(next->value.pair.first, function->parent_environment);
|
||||
append_to_keyword_argument_list(function->keyword_arguments,
|
||||
arguments->value.pair.first->value.symbol.identifier,
|
||||
arguments->value.pair.first,
|
||||
ret);
|
||||
arguments = next->value.pair.rest;
|
||||
} else {
|
||||
@@ -303,7 +303,7 @@ proc parse_argument_list(Lisp_Object* arguments, Function* function) -> void {
|
||||
} else {
|
||||
// No :defaults-to, so just add it to the list
|
||||
append_to_keyword_argument_list(function->keyword_arguments,
|
||||
arguments->value.pair.first->value.symbol.identifier,
|
||||
arguments->value.pair.first,
|
||||
nullptr);
|
||||
arguments = next;
|
||||
}
|
||||
|
||||
+8
-8
@@ -26,23 +26,23 @@ proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char* {
|
||||
|
||||
proc create_positional_argument_list(int initial_capacity) -> Positional_Arguments* {
|
||||
Positional_Arguments* ret = new(Positional_Arguments);
|
||||
ret->identifiers = (String**)malloc(initial_capacity * sizeof(String*));
|
||||
ret->symbols = (Lisp_Object**)malloc(initial_capacity * sizeof(Lisp_Object*));
|
||||
ret->next_index = 0;
|
||||
ret->length = initial_capacity;
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc append_to_positional_argument_list(Positional_Arguments* args, String* identifier) -> void {
|
||||
proc append_to_positional_argument_list(Positional_Arguments* args, Lisp_Object* sym) -> void {
|
||||
if (args->next_index == args->length) {
|
||||
args->length *= 2;
|
||||
args->identifiers = (String**)realloc(args->identifiers, args->length * sizeof(String*));
|
||||
args->symbols = (Lisp_Object**)realloc(args->symbols, args->length * sizeof(Lisp_Object*));
|
||||
}
|
||||
args->identifiers[args->next_index++] = identifier;
|
||||
args->symbols[args->next_index++] = sym;
|
||||
}
|
||||
|
||||
proc create_keyword_argument_list(int initial_capacity) -> Keyword_Arguments* {
|
||||
Keyword_Arguments* ret = new(Keyword_Arguments);
|
||||
ret->identifiers = (String**)malloc(initial_capacity * sizeof(String*));
|
||||
ret->keywords = (Lisp_Object**)malloc(initial_capacity * sizeof(Lisp_Object*));
|
||||
ret->values = create_Lisp_Object_array_list(initial_capacity);
|
||||
ret->next_index = 0;
|
||||
ret->length = initial_capacity;
|
||||
@@ -50,14 +50,14 @@ proc create_keyword_argument_list(int initial_capacity) -> Keyword_Arguments* {
|
||||
}
|
||||
|
||||
proc append_to_keyword_argument_list(Keyword_Arguments* args,
|
||||
String* identifier,
|
||||
Lisp_Object* keyword,
|
||||
Lisp_Object* default_value) -> void
|
||||
{
|
||||
if (args->next_index == args->length) {
|
||||
args->length *= 2;
|
||||
args->identifiers = (String**)realloc(args->identifiers, args->length * sizeof(String*));
|
||||
args->keywords = (Lisp_Object**)realloc(args->keywords, args->length * sizeof(Lisp_Object*));
|
||||
}
|
||||
|
||||
args->identifiers[args->next_index++] = identifier;
|
||||
args->keywords[args->next_index++] = keyword;
|
||||
append_to_array_list(args->values, default_value);
|
||||
}
|
||||
|
||||
+2
-8
@@ -65,25 +65,19 @@ struct Keyword {
|
||||
u64 hash;
|
||||
};
|
||||
|
||||
// struct Number {
|
||||
// double value;
|
||||
// };
|
||||
|
||||
struct Pair {
|
||||
Lisp_Object* first;
|
||||
Lisp_Object* rest;
|
||||
};
|
||||
|
||||
struct Positional_Arguments {
|
||||
// TODO(Felix) use Lisp_Object_symbols here instead, so we don't have
|
||||
// to convert them to strings and back to symbols
|
||||
String** identifiers; // Array of Pointers to String
|
||||
Lisp_Object** symbols; // Array of Pointers to Lisp_Object<Symbol>
|
||||
int next_index;
|
||||
int length;
|
||||
};
|
||||
|
||||
struct Keyword_Arguments {
|
||||
String** identifiers; // Array of Pointers to String
|
||||
Lisp_Object** keywords; // Array of Pointers to Lisp_Object<Keyword>
|
||||
// NOTE(Felix): values[i] will be nullptr if no defalut value was
|
||||
// declared for key identifiers[i]
|
||||
Lisp_Object_Array_List* values;
|
||||
|
||||
Reference in New Issue
Block a user