diff --git a/src/env.c b/src/env.c index d15f4ee..a8ae1be 100644 --- a/src/env.c +++ b/src/env.c @@ -242,6 +242,7 @@ struct Environment defaultEnv() #endif #ifdef STANDALONE pf(segfault), + pf(typeOf), pf(print), pf(numToChar), pf(printEnvO), diff --git a/src/object.c b/src/object.c index c8cc3be..ba2b95f 100644 --- a/src/object.c +++ b/src/object.c @@ -734,7 +734,7 @@ inline Object withLen(size_t len, enum Type type) inline Object constructLambda(const Object* params, const Object* body, struct Environment* env) { if (!params || !body) { - return errorObject(NULL_LAMBDA_LIST); + throw(NULL_LAMBDA_LIST, "fn params and body cannot be null"); } if (params->type != TYPE_LIST) { diff --git a/src/pebblemain.c b/src/pebblemain.c index c51cc26..ed97ce4 100644 --- a/src/pebblemain.c +++ b/src/pebblemain.c @@ -379,7 +379,7 @@ static Object run_script(Object* params, int length, free(code); return o; } - return errorObject(SCRIPT_NOT_FOUND); + throw(SCRIPT_NOT_FOUND, ""); } static void code_window_unload(Window* window) diff --git a/src/plfunc/general.c b/src/plfunc/general.c index cf8b004..ba049d8 100644 --- a/src/plfunc/general.c +++ b/src/plfunc/general.c @@ -277,7 +277,7 @@ int areEqual(const Object* obj1, const Object* obj2) Object equ(Object* params, int length, unused struct Environment* env) { if (length < 2) { - return errorObject(NOT_ENOUGH_ARGUMENTS); + throw(NOT_ENOUGH_ARGUMENTS, "expected at least 2"); } for (int i = 0; i < length - 1; i++) { diff --git a/src/plfunc/pc.c b/src/plfunc/pc.c index 64d3181..83b512e 100644 --- a/src/plfunc/pc.c +++ b/src/plfunc/pc.c @@ -12,6 +12,12 @@ Object print(Object* params, int length, unused struct Environment* env) return numberObject(0); } +Object typeOf(Object* params, unused int length, unused struct Environment* env) +{ + const char* typeString = getTypeName(&(params[0])); + return nullTerminated(typeString); +} + Object numToChar(Object* params, unused int length, unused struct Environment* env) { checkTypes(numToChar); diff --git a/src/plfunc/pc.h b/src/plfunc/pc.h index fcbed79..752786b 100644 --- a/src/plfunc/pc.h +++ b/src/plfunc/pc.h @@ -7,6 +7,14 @@ fn(print, "prn", "Prints the string representation of the given object to stdout."); +tfn(typeOf, "type-of", + ({ anyType, returns(isStringy) }), + "Gets a string indicating the type of the given object", + "(type-of 10)", "TYPE_NUMBER", + "(type-of \"string\")", "TYPE_STRING", + "(type-of (fn () ()))", "TYPE_LAMBDA", +); + tfn(numToChar, "ch", ({ expect(isNumber), returns(isStringy) }), "Gets a string containing the ascii character for the given number value.", diff --git a/src/plfunc/pebbleobject.c b/src/plfunc/pebbleobject.c index 7309ca4..0adc8ae 100644 --- a/src/plfunc/pebbleobject.c +++ b/src/plfunc/pebbleobject.c @@ -94,7 +94,7 @@ Object addTextLayer(Object* params, int length, struct Environment* env) Object window = params[0]; Object text = params[1]; if (getPebbleType(window) != WINDOW) { - return errorObject(0); + throw(BAD_TYPE, "Expected a pebble window, but received %s", getTypeName(&window)); } Layer* window_layer = window_get_root_layer(accessPebbleObject(window)->window); @@ -179,6 +179,6 @@ Object doVibe(Object* params, int length, struct Environment* env) (VibePattern) {.durations = pattern, .num_segments = l}); return trueObject(); } else { - return errorObject(NOT_A_LIST); + throw(NOT_A_LIST, "(vibe) requires a non-empty list!"); } }