implements inner function definition in function condition
This commit is contained in:
parent
b7f11d1fc2
commit
2fefd8c04f
3 changed files with 58 additions and 9 deletions
|
@ -73,6 +73,16 @@ Token* Interpreter_ExpectToken(Interpreter* self, CallFrame* top_frame, size_t s
|
|||
return Interpreter_GetToken(self, top_frame->instruction_pointer);
|
||||
}
|
||||
|
||||
bool is_begin_of_nested_function_definition(Interpreter* self, CallFrame* top_frame, size_t stop_index) {
|
||||
Token* possible_colon = Interpreter_ExpectToken(self, top_frame, stop_index);
|
||||
return possible_colon != NULL && possible_colon->type == TOKENTYPE_COLON;
|
||||
}
|
||||
|
||||
bool is_end_of_nested_function_definition(Interpreter* self, CallFrame* top_frame, size_t stop_index) {
|
||||
Token* possible_semicolon = Interpreter_ExpectToken(self, top_frame, stop_index);
|
||||
return possible_semicolon != NULL && possible_semicolon->type == TOKENTYPE_SEMICOLON;
|
||||
}
|
||||
|
||||
int Interpreter_ParseFunction(Interpreter* self, CallFrame* top_frame, size_t stop_index)
|
||||
{
|
||||
FlupFunction* f = CallFrame_Reserve(top_frame, sizeof(FlupFunction), alignof(FlupFunction));
|
||||
|
@ -138,11 +148,14 @@ int Interpreter_ParseFunction(Interpreter* self, CallFrame* top_frame, size_t st
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int count_nested_functions = 0;
|
||||
|
||||
FlupFunctionAlternative** fdef = &f->alternatives;
|
||||
while (alternative_start->type == TOKENTYPE_PIPE) {
|
||||
top_frame->instruction_pointer++;
|
||||
top_frame->instruction_pointer++; // pipe Token überspringen
|
||||
size_t condition_start = top_frame->instruction_pointer;
|
||||
|
||||
// condition parsing
|
||||
Token* current;
|
||||
do {
|
||||
current = Interpreter_ExpectToken(self, top_frame, stop_index);
|
||||
|
@ -151,7 +164,13 @@ int Interpreter_ParseFunction(Interpreter* self, CallFrame* top_frame, size_t st
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
// TODO: Count inner colon and semicolon to allow for nested functions
|
||||
} while (current->type != TOKENTYPE_ARROW);
|
||||
if(is_begin_of_nested_function_definition(self, top_frame, stop_index)) {
|
||||
count_nested_functions++;
|
||||
}
|
||||
if(is_end_of_nested_function_definition(self, top_frame, stop_index)) {
|
||||
count_nested_functions--;
|
||||
}
|
||||
} while (current->type != TOKENTYPE_ARROW || count_nested_functions != 0);
|
||||
size_t condition_end = top_frame->instruction_pointer - 2;
|
||||
|
||||
size_t body_start = top_frame->instruction_pointer;
|
||||
|
@ -748,9 +767,10 @@ int Interpreter_RunFrame(Interpreter* self)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// char function_name[top_frame->self_function->name.length + 1];
|
||||
// memset(function_name, 0, sizeof(function_name));
|
||||
// StringView_Paste(function_name, top_frame->self_function->name);
|
||||
char function_name[top_frame->self_function->name.length + 1];
|
||||
memset(function_name, 0, sizeof(function_name));
|
||||
StringView_Paste(function_name, top_frame->self_function->name);
|
||||
printf("%s\n", function_name);
|
||||
|
||||
if (! _are_types_compatible(return_value.type, top_frame->self_function->return_type)) {
|
||||
// TODO: Error message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue