implemented logb, max, min, and rot
This commit is contained in:
parent
7f46fd7f84
commit
749d5b4185
|
|
@ -11,6 +11,7 @@
|
|||
#include "sls/hash_table.h"
|
||||
#include "sls/interpreter.h"
|
||||
#include "sls/lexer.h"
|
||||
#include "sls/file.h"
|
||||
|
||||
Boolean builtin_addition(InterpreterState *interpreter_state);
|
||||
Boolean builtin_subtraction(InterpreterState *interpreter_state);
|
||||
|
|
@ -54,7 +55,6 @@ Boolean builtin_floor(InterpreterState *interpreter_state);
|
|||
// Boolean builtin_fn(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_foldl(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_foldr(InterpreterState *interpreter_state);
|
||||
Boolean builtin_for(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_format(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_get(InterpreterState *interpreter_state);
|
||||
Boolean builtin_if(InterpreterState *interpreter_state);
|
||||
|
|
@ -65,12 +65,9 @@ Boolean builtin_lambda(InterpreterState *interpreter_state);
|
|||
// Boolean builtin_length(InterpreterState *interpreter_state);
|
||||
Boolean builtin_ln(InterpreterState *interpreter_state);
|
||||
Boolean builtin_log(InterpreterState *interpreter_state);
|
||||
Boolean builtin_logb(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_map(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_match(InterpreterState *interpreter_state);
|
||||
Boolean builtin_max(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_mean(InterpreterState *interpreter_state);
|
||||
Boolean builtin_min(InterpreterState *interpreter_state);
|
||||
Boolean builtin_not(InterpreterState *interpreter_state);
|
||||
Boolean builtin_or(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_over(InterpreterState *interpreter_state);
|
||||
|
|
@ -80,7 +77,6 @@ Boolean builtin_rand(InterpreterState *interpreter_state);
|
|||
// Boolean builtin_replace(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_reverse(InterpreterState *interpreter_state);
|
||||
Boolean builtin_roll(InterpreterState *interpreter_state);
|
||||
Boolean builtin_rot(InterpreterState *interpreter_state);
|
||||
Boolean builtin_round(InterpreterState *interpreter_state);
|
||||
Boolean builtin_seed(InterpreterState *interpreter_state);
|
||||
// Boolean builtin_set(InterpreterState *interpreter_state);
|
||||
|
|
@ -302,12 +298,6 @@ Boolean load_builtins(InterpreterState *interpreter_state) {
|
|||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("floor"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_for};
|
||||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("for"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_if};
|
||||
|
|
@ -332,24 +322,6 @@ Boolean load_builtins(InterpreterState *interpreter_state) {
|
|||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("log"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_logb};
|
||||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("logb"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_max};
|
||||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("max"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_min};
|
||||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("min"), func))
|
||||
return FALSE;
|
||||
|
||||
func = (FunctionItem *)malloc(sizeof(FunctionItem));
|
||||
if (func == NULL) return FALSE;
|
||||
*func = (FunctionItem){ .type = FUNCTION_BUILTIN, .builtin = *builtin_not};
|
||||
|
|
@ -440,6 +412,39 @@ Boolean load_builtins(InterpreterState *interpreter_state) {
|
|||
if (!hash_table_put_funcs(interpreter_state->functions, SLS_STR("while"), func))
|
||||
return FALSE;
|
||||
|
||||
LexerInfo lexer_info;
|
||||
init_lexer(&lexer_info, SLS_STR("__builtin.sls"), SLS_STR(
|
||||
"// Kyler Olsen\n"
|
||||
"// YREA SLS\n"
|
||||
"// SLS Defined Builtin Operators\n"
|
||||
"// November 2025\n"
|
||||
"\n"
|
||||
"// { } lambda ::for const\n"
|
||||
"{ ln swap ln swap / } lambda ::logb const\n"
|
||||
"{ 1 pick 1 pick < { swap drop } { drop } if } lambda ::max const\n"
|
||||
"{ 1 pick 1 pick < { drop } { swap drop } if } lambda ::min const\n"
|
||||
"{ 3 1 roll } lambda ::rot const\n"
|
||||
));
|
||||
LexerResult result = lexical_analysis(&lexer_info);
|
||||
if (result.type == SLS_ERROR) {
|
||||
sls_str_free(&result.error.message);
|
||||
return FALSE;
|
||||
} else {
|
||||
LexerTokenResult *head = result.result;
|
||||
while (head) {
|
||||
if (head->type == SLS_ERROR) {
|
||||
sls_str_free(&result.error.message);
|
||||
clean_token_result(result.result);
|
||||
return FALSE;
|
||||
} else if (!execute(interpreter_state, head)) {
|
||||
clean_token_result(result.result);
|
||||
return FALSE;
|
||||
}
|
||||
head = head->next;
|
||||
}
|
||||
clean_token_result(result.result);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1610,11 +1615,6 @@ Boolean builtin_floor(InterpreterState *interpreter_state) {
|
|||
FLOAT_FUNCTION(floor);
|
||||
}
|
||||
|
||||
Boolean builtin_for(InterpreterState *interpreter_state) {
|
||||
(void)interpreter_state;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Boolean builtin_if(InterpreterState *interpreter_state) {
|
||||
if (interpreter_state->stack == NULL) return FALSE;
|
||||
StackItem *else_block = interpreter_state->stack;
|
||||
|
|
@ -1676,21 +1676,6 @@ Boolean builtin_log(InterpreterState *interpreter_state) {
|
|||
FLOAT_FUNCTION(log10);
|
||||
}
|
||||
|
||||
Boolean builtin_logb(InterpreterState *interpreter_state) {
|
||||
(void)interpreter_state;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Boolean builtin_max(InterpreterState *interpreter_state) {
|
||||
(void)interpreter_state;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Boolean builtin_min(InterpreterState *interpreter_state) {
|
||||
(void)interpreter_state;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Boolean builtin_not(InterpreterState *interpreter_state) {
|
||||
NUMERIC_TYPE;
|
||||
|
||||
|
|
@ -1942,11 +1927,6 @@ Boolean builtin_roll(InterpreterState *interpreter_state) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
Boolean builtin_rot(InterpreterState *interpreter_state) {
|
||||
(void)interpreter_state;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Boolean builtin_round(InterpreterState *interpreter_state) {
|
||||
NUMERIC_TYPE;
|
||||
FLOAT_FUNCTION(round);
|
||||
|
|
|
|||
Loading…
Reference in New Issue