Add script-calling. Tweak font size thresholds

Other clean-up
This commit is contained in:
= 2020-08-04 18:30:40 +01:00
parent 5644a46c3c
commit b92768c5ec
5 changed files with 38 additions and 20 deletions

View File

@ -71,8 +71,8 @@ static void adjustFont()
size++; size++;
} }
int f = size < 50 ? smallestFont - 3 : int f = size < 50 ? smallestFont - 3 :
size < 100 ? smallestFont - 2 : size < 80 ? smallestFont - 2 :
size < 130 ? smallestFont - 1 : size < 100 ? smallestFont - 1 :
smallestFont; smallestFont;
text_layer_set_font(s_input_text_layer, text_layer_set_font(s_input_text_layer,
fonts_get_system_font(fonts[f])); fonts_get_system_font(fonts[f]));
@ -206,6 +206,18 @@ static void code_window_load(Window *window)
} }
} }
static Object run_script(Object script_num, Object obj, struct Environment *e) {
int n = script_num.number - 1;
if(persist_exists(n)) {
char *code = malloc(sizeof(char) * SMAX_LENGTH);
persist_read_string(n, code, SMAX_LENGTH);
Object o = parseEval(code, e);
free(code);
return o;
}
return errorObject(SCRIPT_NOT_FOUND);
}
static void code_window_unload(Window *window) static void code_window_unload(Window *window)
{ {
// Save the current code text // Save the current code text
@ -352,7 +364,9 @@ static struct Environment pebbleEnv()
struct Environment e = defaultEnv(); struct Environment e = defaultEnv();
// Needs two args // Needs two args
addFunc("window", &add_window, &e); addFunc("window", &add_window, &e);
addFunc("sc", &run_script, &e);
parseEval("(def win (fn (a) (window a 1)))", &e); parseEval("(def win (fn (a) (window a 1)))", &e);
parseEval("(def s (fn (a) (sc a 0)))", &e);
return e; return e;
} }

View File

@ -52,6 +52,7 @@ const char *tokens[] = {
"a", "b", "c", "d", "e", "a", "b", "c", "d", "e",
"= ", "< ", "> ", "= ", "< ", "> ",
"\"", "\"",
"s",
"cat", "map", "fil", "cat", "map", "fil",
"fn", "def", "if", "\n", "fn", "def", "if", "\n",
"...", "...",
@ -65,7 +66,7 @@ const char *func_tokens[] = {
}; };
const uint32_t inbox_size = 1024; const uint32_t inbox_size = 1024;
const uint32_t outbox_size = 64; const uint32_t outbox_size = 1024;
bool using_func_tokens = false; bool using_func_tokens = false;

View File

@ -188,23 +188,24 @@ struct Environment defaultEnv()
e.objects = malloc(sizeof(Object) * MAX_ENV_ELM); e.objects = malloc(sizeof(Object) * MAX_ENV_ELM);
e.size = MAX_ENV_ELM; e.size = MAX_ENV_ELM;
addFunc("+", &add, &e); #define af(S, F) addFunc(S, F, &e)
addFunc("-", &sub, &e); af("+", &add); af("-", &sub);
addFunc("*", &mul, &e); af("*", &mul); af("/", &dvi);
addFunc("/", &dvi, &e); af("%", &mod);
addFunc("%", &mod, &e);
addFunc("=", &equ, &e);
addFunc(">", &gth, &e);
addFunc("<", &lth, &e);
addFunc("cat", &catObjects, &e); af("=", &equ);
addFunc("fil", &filter, &e); af(">", &gth);
af("<", &lth);
addFunc("len", &len, &e); af("cat", &catObjects);
addFunc("ap", &append, &e); af("fil", &filter);
addFunc("at", &at, &e);
addFunc("rest", &rest, &e); af("len", &len);
addFunc("rev", &reverse, &e); af("ap", &append);
af("at", &at);
af("rest", &rest);
af("rev", &reverse);
#undef af
int i = 0; int i = 0;
while(codes[i]) { while(codes[i]) {

View File

@ -217,7 +217,8 @@ static const char *errorText[] = {
"UNSUPPORTED_NUMBER_TYPE", "UNSUPPORTED_NUMBER_TYPE",
"NOT_A_SYMBOL", "NOT_A_SYMBOL",
"ONLY_ONE_ARGUMENT", "ONLY_ONE_ARGUMENT",
"NOT_A_LIST" "NOT_A_LIST",
"SCRIPT_NOT_FOUND"
}; };
/** /**

View File

@ -37,7 +37,8 @@ enum errorCode {
UNSUPPORTED_NUMBER_TYPE, UNSUPPORTED_NUMBER_TYPE,
NOT_A_SYMBOL, NOT_A_SYMBOL,
ONLY_ONE_ARGUMENT, ONLY_ONE_ARGUMENT,
NOT_A_LIST NOT_A_LIST,
SCRIPT_NOT_FOUND
}; };
#define MALLOC_FLAG 64 #define MALLOC_FLAG 64