diff --git a/src/calc.c b/src/calc.c index 0f8fe5a..b19208c 100644 --- a/src/calc.c +++ b/src/calc.c @@ -334,6 +334,10 @@ Object add_window(Object obj1, Object obj2, struct Environment *env) static void inbox_received_callback(DictionaryIterator *iter, void *context) { Tuple *script_tuple = dict_find(iter, MESSAGE_KEY_ScriptText); if(script_tuple) { + if(!s_code_window) { + current_code = 0; + code_window_push(); + } char *script_text = script_tuple->value->cstring; snprintf(temptext, sizeof(temptext), "%s", script_text); snprintf(mytext, sizeof(mytext), "%s", script_text); diff --git a/src/object.c b/src/object.c index 23bdf30..22db730 100644 --- a/src/object.c +++ b/src/object.c @@ -105,6 +105,8 @@ inline int isEmpty(const Object *obj) return obj->string == NULL || obj->string[0] == '\0'; case TYPE_FUNC: return obj->func == NULL; + case TYPE_OTHER: + return obj->other == NULL; case TYPE_ERROR: return obj->err == 0; } @@ -302,6 +304,10 @@ char* stringObj(char *dest, const Object *obj) case TYPE_FUNC: case TYPE_LAMBDA: snprintf(dest, RESULT_LENGTH, "X%d", obj->number); + break; + case TYPE_OTHER: + snprintf(dest, RESULT_LENGTH, "%p", obj->other->data); + break; } if(!isValidType(*obj)) @@ -350,6 +356,8 @@ void _printObj(const Object *obj, int newline) printd("Lambda Body: \n"); printObj(&obj->lambda->body); return; + case TYPE_OTHER: + printd("TYPE_OTHER: "); case TYPE_ERROR: printd("TYPE_ERROR: "); break; @@ -429,6 +437,10 @@ void cleanObject(Object *target) cleanObject(&target->lambda->body); free(target->lambda); break; + case TYPE_OTHER: + target->other->cleanup(target); + free(target->other); + break; case TYPE_BOOL: case TYPE_NUMBER: case TYPE_FUNC: @@ -573,6 +585,7 @@ inline int isValidType(const Object test) case TYPE_SYMBOL: case TYPE_LAMBDA: case TYPE_STRING: + case TYPE_OTHER: case TYPE_ERROR: return 1; } @@ -618,6 +631,7 @@ inline Object cloneObject(const Object src) case TYPE_BOOL: case TYPE_NUMBER: case TYPE_FUNC: + case TYPE_OTHER: case TYPE_ERROR: ; // Fall through to plain return } @@ -677,6 +691,13 @@ inline int isError(const Object obj, const enum errorCode err) return obj.type == TYPE_ERROR && obj.err == err; } +inline Object otherObject() +{ + Object o = newObject(TYPE_OTHER); + o.other = malloc(sizeof(struct Other)); + return o; +} + inline Object errorObject(enum errorCode err) { Object o = newObject(TYPE_ERROR); diff --git a/src/object.h b/src/object.h index ed4fa2f..b5bb1bd 100644 --- a/src/object.h +++ b/src/object.h @@ -50,6 +50,7 @@ typedef enum Type { TYPE_SYMBOL, TYPE_LAMBDA, TYPE_STRING, + TYPE_OTHER, TYPE_ERROR } Type; @@ -57,6 +58,7 @@ typedef struct Object Object; struct Lambda; struct Environment; struct Slice; +struct Other; struct Object { Type type; @@ -67,6 +69,7 @@ struct Object { char *string; Object (*func)(Object, Object, struct Environment *); struct Lambda *lambda; + struct Other *other; enum errorCode err; }; }; @@ -76,6 +79,11 @@ struct Lambda { Object body; }; +struct Other { + void (*cleanup)(Object*); + void *data; +}; + char* stringObj(char *dest, const Object *obj); void printList(const Object *list); void printObj(const Object *obj); @@ -110,12 +118,11 @@ Object cloneObject(const Object src); Object newObject(Type type); Object listObject(); Object startList(const Object start); -Object lambdaObject(); -Object symbolObject(); Object objFromSlice(const char *string, int len); Object symFromSlice(const char *string, int len); Object boolObject(int b); Object numberObject(int num); +Object otherObject(); Object errorObject(enum errorCode err); Object constructLambda(const Object *params, const Object *body); diff --git a/src/pebblisp.c b/src/pebblisp.c index 9c154a3..aeea5de 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -172,6 +172,7 @@ Object eval(const Object *obj, struct Environment *env) case TYPE_FUNC: return *obj; + case TYPE_OTHER: case TYPE_NUMBER: case TYPE_BOOL: case TYPE_STRING: