Add script-calling. Tweak font size thresholds
Other clean-up
This commit is contained in:
parent
5644a46c3c
commit
b92768c5ec
18
src/calc.c
18
src/calc.c
|
@ -71,8 +71,8 @@ static void adjustFont()
|
|||
size++;
|
||||
}
|
||||
int f = size < 50 ? smallestFont - 3 :
|
||||
size < 100 ? smallestFont - 2 :
|
||||
size < 130 ? smallestFont - 1 :
|
||||
size < 80 ? smallestFont - 2 :
|
||||
size < 100 ? smallestFont - 1 :
|
||||
smallestFont;
|
||||
text_layer_set_font(s_input_text_layer,
|
||||
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)
|
||||
{
|
||||
// Save the current code text
|
||||
|
@ -352,7 +364,9 @@ static struct Environment pebbleEnv()
|
|||
struct Environment e = defaultEnv();
|
||||
// Needs two args
|
||||
addFunc("window", &add_window, &e);
|
||||
addFunc("sc", &run_script, &e);
|
||||
parseEval("(def win (fn (a) (window a 1)))", &e);
|
||||
parseEval("(def s (fn (a) (sc a 0)))", &e);
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ const char *tokens[] = {
|
|||
"a", "b", "c", "d", "e",
|
||||
"= ", "< ", "> ",
|
||||
"\"",
|
||||
"s",
|
||||
"cat", "map", "fil",
|
||||
"fn", "def", "if", "\n",
|
||||
"...",
|
||||
|
@ -65,7 +66,7 @@ const char *func_tokens[] = {
|
|||
};
|
||||
|
||||
const uint32_t inbox_size = 1024;
|
||||
const uint32_t outbox_size = 64;
|
||||
const uint32_t outbox_size = 1024;
|
||||
|
||||
bool using_func_tokens = false;
|
||||
|
||||
|
|
31
src/env.c
31
src/env.c
|
@ -188,23 +188,24 @@ struct Environment defaultEnv()
|
|||
e.objects = malloc(sizeof(Object) * MAX_ENV_ELM);
|
||||
e.size = MAX_ENV_ELM;
|
||||
|
||||
addFunc("+", &add, &e);
|
||||
addFunc("-", &sub, &e);
|
||||
addFunc("*", &mul, &e);
|
||||
addFunc("/", &dvi, &e);
|
||||
addFunc("%", &mod, &e);
|
||||
addFunc("=", &equ, &e);
|
||||
addFunc(">", >h, &e);
|
||||
addFunc("<", <h, &e);
|
||||
#define af(S, F) addFunc(S, F, &e)
|
||||
af("+", &add); af("-", &sub);
|
||||
af("*", &mul); af("/", &dvi);
|
||||
af("%", &mod);
|
||||
|
||||
addFunc("cat", &catObjects, &e);
|
||||
addFunc("fil", &filter, &e);
|
||||
af("=", &equ);
|
||||
af(">", >h);
|
||||
af("<", <h);
|
||||
|
||||
addFunc("len", &len, &e);
|
||||
addFunc("ap", &append, &e);
|
||||
addFunc("at", &at, &e);
|
||||
addFunc("rest", &rest, &e);
|
||||
addFunc("rev", &reverse, &e);
|
||||
af("cat", &catObjects);
|
||||
af("fil", &filter);
|
||||
|
||||
af("len", &len);
|
||||
af("ap", &append);
|
||||
af("at", &at);
|
||||
af("rest", &rest);
|
||||
af("rev", &reverse);
|
||||
#undef af
|
||||
|
||||
int i = 0;
|
||||
while(codes[i]) {
|
||||
|
|
|
@ -217,7 +217,8 @@ static const char *errorText[] = {
|
|||
"UNSUPPORTED_NUMBER_TYPE",
|
||||
"NOT_A_SYMBOL",
|
||||
"ONLY_ONE_ARGUMENT",
|
||||
"NOT_A_LIST"
|
||||
"NOT_A_LIST",
|
||||
"SCRIPT_NOT_FOUND"
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,8 @@ enum errorCode {
|
|||
UNSUPPORTED_NUMBER_TYPE,
|
||||
NOT_A_SYMBOL,
|
||||
ONLY_ONE_ARGUMENT,
|
||||
NOT_A_LIST
|
||||
NOT_A_LIST,
|
||||
SCRIPT_NOT_FOUND
|
||||
};
|
||||
|
||||
#define MALLOC_FLAG 64
|
||||
|
|
Loading…
Reference in New Issue