implemented const
This commit is contained in:
parent
1fa6f4ec2a
commit
53983d8e92
|
|
@ -38,6 +38,7 @@ Boolean builtin_bitor(InterpreterState *interpreter_state);
|
|||
Boolean builtin_bitxor(InterpreterState *interpreter_state);
|
||||
Boolean builtin_ceil(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_concat(InterpreterState *interpreter_state);
|
||||
Boolean builtin_const(InterpreterState *interpreter_state);
|
||||
Boolean builtin_cos(InterpreterState *interpreter_state);
|
||||
Boolean builtin_depth(InterpreterState *interpreter_state);
|
||||
Boolean builtin_drop(InterpreterState *interpreter_state);
|
||||
|
|
@ -259,6 +260,12 @@ Boolean load_builtins(InterpreterState *interpreter_state) {
|
|||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("ceil"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_const};
|
||||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("const"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_cos};
|
||||
|
|
@ -1474,6 +1481,28 @@ Boolean builtin_ceil(InterpreterState *interpreter_state) {
|
|||
FLOAT_FUNCTION(ceil);
|
||||
}
|
||||
|
||||
Boolean builtin_const(InterpreterState *interpreter_state) {
|
||||
if (interpreter_state->stack == NULL) return FALSE;
|
||||
StackItem *name = interpreter_state->stack;
|
||||
if (name->type != STACK_IDENTIFIER) return FALSE;
|
||||
if (name->next == NULL) return FALSE;
|
||||
StackItem *item = name->next;
|
||||
if (item->type != STACK_CALLABLE) return FALSE;
|
||||
if (hash_table_get(interpreter_state->functions, name->identifier.name, NULL) != NULL) return FALSE;
|
||||
|
||||
FunctionItem *function_item = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (function_item == NULL) return FALSE;
|
||||
function_item->type = FUNCTION_TOKEN_STRING;
|
||||
function_item->token_string = item->token_string;
|
||||
|
||||
interpreter_state->stack = item->next;
|
||||
name->next = NULL;
|
||||
|
||||
Boolean return_value = hash_table_put_funcs(interpreter_state->functions, name->identifier.name, function_item);
|
||||
clean_stack(name);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
Boolean builtin_cos(InterpreterState *interpreter_state) {
|
||||
NUMERIC_TYPE;
|
||||
FLOAT_FUNCTION(cos);
|
||||
|
|
|
|||
Loading…
Reference in New Issue