implemented while
This commit is contained in:
parent
024af6a778
commit
5ea2d8fe2a
|
|
@ -2009,6 +2009,49 @@ Boolean builtin_type_of(InterpreterState *interpreter_state) {
|
|||
}
|
||||
|
||||
Boolean builtin_while(InterpreterState *interpreter_state) {
|
||||
(void)interpreter_state;
|
||||
return FALSE;
|
||||
if (interpreter_state->stack == NULL) return FALSE;
|
||||
StackItem *while_block = interpreter_state->stack;
|
||||
if (while_block->next == NULL) return FALSE;
|
||||
StackItem *conditional_block = while_block->next;
|
||||
|
||||
if (!(
|
||||
while_block->type == STACK_TOKEN_STRING ||
|
||||
while_block->type == STACK_CALLABLE ||
|
||||
while_block->type == STACK_IDENTIFIER
|
||||
)) return FALSE;
|
||||
|
||||
if (!(
|
||||
conditional_block->type == STACK_TOKEN_STRING ||
|
||||
conditional_block->type == STACK_CALLABLE ||
|
||||
conditional_block->type == STACK_IDENTIFIER
|
||||
)) return FALSE;
|
||||
|
||||
interpreter_state->stack = conditional_block->next;
|
||||
conditional_block->next = NULL;
|
||||
|
||||
Boolean return_value = FALSE;
|
||||
while (TRUE) {
|
||||
if (conditional_block->type == STACK_TOKEN_STRING || conditional_block->type == STACK_CALLABLE)
|
||||
return_value = execute_token_string(interpreter_state, conditional_block->token_string);
|
||||
else if (conditional_block->type == STACK_IDENTIFIER)
|
||||
return_value = execute_func(interpreter_state, conditional_block->identifier.name);
|
||||
if (!return_value) break;
|
||||
if (interpreter_state->stack == NULL) return FALSE;
|
||||
|
||||
StackItem *conditional = interpreter_state->stack;
|
||||
interpreter_state->stack = conditional->next;
|
||||
conditional->next = NULL;
|
||||
TRUTHY;
|
||||
clean_stack(conditional);
|
||||
if (!value) break;
|
||||
|
||||
if (while_block->type == STACK_TOKEN_STRING || while_block->type == STACK_CALLABLE)
|
||||
return_value = execute_token_string(interpreter_state, while_block->token_string);
|
||||
else if (while_block->type == STACK_IDENTIFIER)
|
||||
return_value = execute_func(interpreter_state, while_block->identifier.name);
|
||||
if (!return_value) break;
|
||||
}
|
||||
|
||||
clean_stack(while_block);
|
||||
return return_value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,13 +186,15 @@ Boolean execute_func(InterpreterState *interpreter_state, SlsStr key) {
|
|||
}
|
||||
|
||||
Boolean execute_token_string(InterpreterState *interpreter_state, TokenString token_string) {
|
||||
Boolean return_value = FALSE;
|
||||
for (size_t i = 0; i < token_string.length; i++) {
|
||||
if (token_string.tokens[i].type == TOKEN_IDENTIFIER && !token_string.tokens[i].identifier.is_literal)
|
||||
return execute_func(interpreter_state, token_string.tokens[i].identifier.name);
|
||||
return_value = execute_func(interpreter_state, token_string.tokens[i].identifier.name);
|
||||
else
|
||||
return push_token(interpreter_state, token_string.tokens[i]);
|
||||
return_value = push_token(interpreter_state, token_string.tokens[i]);
|
||||
if (!return_value) break;
|
||||
}
|
||||
return FALSE;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
Boolean execute(InterpreterState *interpreter_state, LexerTokenResult *token) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue