diff --git a/appinfo.json b/appinfo.json index dcfa861..15793ef 100644 --- a/appinfo.json +++ b/appinfo.json @@ -3,7 +3,7 @@ "capabilities": [ "" ], - "companyName": "Save V.", + "companyName": "Sage V.", "enableMultiJS": false, "longName": "PebbLisp", "projectType": "native", diff --git a/resources/images/appicon.png b/resources/images/appicon.png index 65e044b..58e43c6 100644 Binary files a/resources/images/appicon.png and b/resources/images/appicon.png differ diff --git a/src/.pebblisp.c.swp b/src/.pebblisp.c.swp index f15e356..7ab91f5 100644 Binary files a/src/.pebblisp.c.swp and b/src/.pebblisp.c.swp differ diff --git a/src/.pebblisp.h.swp b/src/.pebblisp.h.swp deleted file mode 100644 index 14ae095..0000000 Binary files a/src/.pebblisp.h.swp and /dev/null differ diff --git a/src/calc.c b/src/calc.c index 64f9f75..0b77c17 100644 --- a/src/calc.c +++ b/src/calc.c @@ -35,6 +35,17 @@ static void up_down_handler(ClickRecognizerRef recognizer, void *context){ updateText(); } +static void back_handler(ClickRecognizerRef recognizer, void *context) { + if(mytext[0] == '\0') { + window_stack_remove(window_stack_get_top_window(), true); + } else { + int i = 0; + while(mytext[++i] != '\0') { ; } + mytext[i-1] = '\0'; + updateText(); + } +} + // Adds the current string to the main string static void enter(){ strcat(mytext, getToken(selected_token)); @@ -45,10 +56,10 @@ static void enter(){ //Calculate result, display it and reset static void calculate(){ Object obj = parseEval(mytext, &env); - snprintf(mytext, MAX_LENGTH, "R:%d", obj.number); + snprintf(resulttext, MAX_LENGTH, "R:%d", obj.number); selected_token = 0; //strcpy(mytext, HAHA); - updateText(); + text_layer_set_text(s_result_text_layer, resulttext); } // Button press handler @@ -64,22 +75,31 @@ static void click_config_provider(void *context) { window_single_repeating_click_subscribe(BUTTON_ID_UP, 100, up_down_handler); window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 100, up_down_handler); window_single_click_subscribe(BUTTON_ID_SELECT, select_handler); + window_single_click_subscribe(BUTTON_ID_BACK, back_handler); } static void init(void) { // Create a window and get information about the window s_window = window_create(); - Layer *window_layer = window_get_root_layer(s_window); + // Layer *window_layer = window_get_root_layer(s_window); // Register click config provider window_set_click_config_provider(s_window, click_config_provider); // Input text layer setup - GRect text_bounds = GRect(6, 6, 132, 132); + GRect text_bounds = GRect(6, 6, 132, 127); s_input_text_layer = text_layer_create(text_bounds); text_layer_set_text(s_input_text_layer, getToken(1)); - text_layer_set_font(s_input_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); + text_layer_set_font(s_input_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_input_text_layer)); + // Result text layer setup + GRect result_bounds = GRect(6, 128, 132, 132); + s_result_text_layer = text_layer_create(result_bounds); + text_layer_set_text(s_result_text_layer, "R: "); + text_layer_set_font(s_result_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); + text_layer_set_text_alignment(s_result_text_layer, GTextAlignmentRight); + layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_result_text_layer)); + // Push the window, setting the window animation to 'true' window_stack_push(s_window, true); env = defaultEnv(); diff --git a/src/calc.h b/src/calc.h index 6b4c1cc..7a23f11 100644 --- a/src/calc.h +++ b/src/calc.h @@ -8,11 +8,11 @@ // Layers Window *s_window; TextLayer *s_input_text_layer; - -const char *HAHA = "STONKS"; +TextLayer *s_result_text_layer; char mytext[SMAX_LENGTH] = ""; char temptext[SMAX_LENGTH] = ""; +char resulttext[MAX_LENGTH] = ""; char *tokens[] = { " ", "(", ")", diff --git a/src/pebblisp.c b/src/pebblisp.c index 1bdda30..9c8517d 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -46,7 +46,7 @@ Object fetchFromEnvironment(const char *name, struct Environment *env) Result parse(struct Slice *slices) { - // printf("parse()\n"); + printf("parse() START\n"); struct Slice *token = slices; struct Slice *rest; if(token->text != NULL) { @@ -62,11 +62,12 @@ Result parse(struct Slice *slices) } else { // todo error on closed paren return R(parseAtom(token), rest); } + printf("parse() END\n"); } Result readSeq(struct Slice *tokens) { - // printf("readSeq()\n"); + printf("readSeq() START\n"); Object res; res.forward = NULL; res.type = TYPE_LIST; @@ -80,13 +81,16 @@ Result readSeq(struct Slice *tokens) return R(res, rest); } Result r = parse(tokens); - march->forward = malloc(sizeof(Object)); + printf("readSeq() before malloc\n"); + march->forward = malloc(sizeof(struct Object)); + printf("readSeq() after malloc\n"); *march->forward = r.obj; // char out[MAX_TOK_LEN]; // printf("stringObj: %s\n", stringObj(out, &r.obj)); tokens = r.slices; march = march->forward; } + printf("readSeq() END\n"); } Object parseAtom(struct Slice *s) @@ -111,6 +115,8 @@ Object parseAtom(struct Slice *s) Object eval(Object *obj, struct Environment *env) { + printf("eval(): "); + printObj(obj); Object o = *obj; switch(obj->type) { case TYPE_NUMBER: @@ -122,7 +128,9 @@ Object eval(Object *obj, struct Environment *env) // printf("TYPE_LIST\n"); Object first_form = *obj->forward; Object first_eval = eval(&first_form, env); - return first_eval.func(*first_form.forward, *first_form.forward->forward); + Object arg1 = eval(first_form.forward, env); + Object arg2 = eval(first_form.forward->forward, env); + return first_eval.func(arg1, arg2); } case TYPE_SYMBOL: { @@ -145,6 +153,22 @@ char* stringObj(char *dest, Object *obj) return dest; } +void printObj(Object *obj) +{ + if(obj->type == TYPE_NUMBER) { + printf("TYPE_NUMBER"); + } else if(obj->type == TYPE_LIST) { + printf("TYPE_NUMBER"); + } else if(obj->type == TYPE_SYMBOL) { + printf("TYPE_NUMBER"); + } else { + printf("TYPE_OTHER"); + } + char temp[20]; + stringObj(temp, obj); + printf(": %s\n", temp); +} + Result resultFromObjAndSlices(Object obj, struct Slice *slices) { Result r; @@ -211,6 +235,9 @@ void addFunc(const char *name, Object (*func)(Object, Object), struct Environment defaultEnv() { struct Environment e; e.strings = malloc(sizeof(char*) * MAX_ENV_ELM); + for(int i = 0; i < MAX_ENV_ELM; i++) { + e.strings[i] = NULL; + } e.objects = malloc(sizeof(Object) * MAX_ENV_ELM); addFunc("+", &add, &e); addFunc("-", &sub, &e); @@ -248,6 +275,7 @@ Object parseEval(const char *input, struct Environment *env) // printf("parseEval() parse()\n"); #endif Object parsed = parse(tokens).obj; + free(tokens); return eval(&parsed, env); } diff --git a/src/pebblisp.h b/src/pebblisp.h index da97a6c..f1891e1 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -3,9 +3,9 @@ // #define STANDALONE -#define MAX_TOK_LEN 3 -#define MAX_TOK_CNT 7 // 128 -#define MAX_ENV_ELM 3 // 50 +#define MAX_TOK_LEN 4 +#define MAX_TOK_CNT 128 // 128 +#define MAX_ENV_ELM 15 // 50 // static const char* tokenFail = "Missing ')'\n"; @@ -69,6 +69,7 @@ Object parseAtom(struct Slice *slice); void copySlice(char * dest, struct Slice *src); Object parseEval(const char *input, struct Environment *env); struct Environment defaultEnv(); +void printObj(Object *obj); Result resultFromObjAndSlices(Object obj, struct Slice *slices); Object add(Object obj1, Object obj2);