diff --git a/src/object.c b/src/object.c index fd4fe8f..82127f4 100644 --- a/src/object.c +++ b/src/object.c @@ -129,25 +129,26 @@ Object* nf_addToList(Object* dest, const Object src) } #ifndef SIMPLE_ERRORS -static const char* errorText[] = {"MISMATCHED_PARENS", - "NULL_ENV", - "EMPTY_ENV", - "NULL_PARSE", - "NULL_LAMBDA_LIST", - "NULL_MAP_ARGS", - "LAMBDA_ARGS_NOT_LIST", - "DID_NOT_FIND_SYMBOL", - "BAD_TYPE", - "BAD_PARAMS_ON", - "BAD_NUMBER", - "UNSUPPORTED_NUMBER_TYPE", - "NOT_ENOUGH_ARGUMENTS", - "NOT_A_LIST", - "SCRIPT_NOT_FOUND", - "NO_CLONE_SPECIFIED", - "CAN_ONLY_EVAL_STRINGS", - "UNEXPECTED_EOF", - "INDEX_PAST_END"}; +static const char* errorText[] = { + "MISMATCHED_PARENS", + "NULL_ENV", + "EMPTY_ENV", + "NULL_PARSE", + "NULL_LAMBDA_LIST", + "NULL_MAP_ARGS", + "LAMBDA_ARGS_NOT_LIST", + "DID_NOT_FIND_SYMBOL", + "BAD_TYPE", + "BAD_PARAMS_ON", + "BAD_NUMBER", + "UNSUPPORTED_NUMBER_TYPE", + "NOT_ENOUGH_ARGUMENTS", + "NOT_A_LIST", + "SCRIPT_NOT_FOUND", + "NO_CLONE_SPECIFIED", + "CAN_ONLY_EVAL_STRINGS", + "UNEXPECTED_EOF", + "INDEX_PAST_END"}; #endif size_t inflate(struct string* s, size_t additional) @@ -246,20 +247,20 @@ int stringNObj(struct string* s, const Object* obj) case TYPE_BOOL: s->cursor += sprintf(s->cursor, "%s", obj->number ? "T" : "F"); break; + case TYPE_SYMBOL: case TYPE_STRING: { size_t stringLen = strlen(obj->string); inflate(s, stringLen); - s->cursor += sprintf(s->cursor, "%s", obj->string); + const char* format = obj->type == TYPE_STRING ? "%s" : "`%s`"; + s->cursor += sprintf(s->cursor, format, obj->string); break; } - case TYPE_SYMBOL: - s->cursor += sprintf(s->cursor, "`%s`", obj->string); - break; case TYPE_STRUCT: stringStruct(s, obj); break; - case TYPE_LIST: case TYPE_SLIST: + s->cursor += sprintf(s->cursor, "'"); + case TYPE_LIST: stringList(s, obj); break; case TYPE_ERROR: { diff --git a/src/object.h b/src/object.h index 2ab775d..6f4d46e 100644 --- a/src/object.h +++ b/src/object.h @@ -13,6 +13,7 @@ #define printd(...) printf(__VA_ARGS__) #else #define printd(...) do { } while (0) +#define eprintf(...) fprintf(stderr, __VA_ARGS__) #endif #endif diff --git a/src/pebblisp.c b/src/pebblisp.c index 5e44f6c..49b08b4 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -15,9 +15,6 @@ #include #include -#include -#include - #include "web.h" #endif @@ -677,6 +674,10 @@ void loadArgsIntoEnv(int argc, const char* argv[], struct Environment* env) addToEnv(env, "args", args); } +#ifdef __x86_64__ +#include +#include + int nestedSegfault = 0; void handler(int nSignum, siginfo_t* si, void* vcontext) @@ -697,10 +698,29 @@ void handler(int nSignum, siginfo_t* si, void* vcontext) context->uc_mcontext.gregs[REG_RIP]++; exit(139); } +void setupSegfaultHandler() +{ + struct sigaction action; + memset(&action, 0, sizeof(struct sigaction)); + action.sa_flags = SA_SIGINFO; + action.sa_sigaction = handler; + sigaction(SIGSEGV, &action, NULL); -// TODO: Track crashes in ~/.plcrash or some such +} +#else +void setupSegfaultHandler() +{ +} +#endif + +// TODO: add --no-lib and --no-config and/or --config= int main(int argc, const char* argv[]) { + setupSegfaultHandler(); + + const char* const home = getenv("HOME"); + char config[strlen(home) + 15]; + struct Environment env = defaultEnv(); setGlobal(&env); @@ -714,12 +734,6 @@ int main(int argc, const char* argv[]) } } - struct sigaction action; - memset(&action, 0, sizeof(struct sigaction)); - action.sa_flags = SA_SIGINFO; - action.sa_sigaction = handler; - sigaction(SIGSEGV, &action, NULL); - readFile(SCRIPTDIR "/lib.pbl", &env); Object o = parseEval("(def prompt \"pebblisp::> \")", &env); @@ -727,8 +741,6 @@ int main(int argc, const char* argv[]) o = parseEval("(def preprocess (fn (text) (text)))", &env); cleanObject(&o); - const char* const home = getenv("HOME"); - char config[strlen(home) + 15]; sprintf(config, "%s/.pebblisp.pbl", home); readFile(config, &env); @@ -753,9 +765,9 @@ int main(int argc, const char* argv[]) } deleteEnv(&env); shredDictionary(); - // fprintf(stderr, "totalSearchDepth: %d of %d searches\n", getTotalSearchDepth(), getTotalSearches()); - // fprintf(stderr, "\nHEAP-ALLOCATED OBJECTS: %d\n", getAllocations()); - // fprintf(stderr, "TOTAL OBJECT.C ALLOC: %zu\n", getBytes()); + // eprintf("totalSearchDepth: %d of %d searches\n", getTotalSearchDepth(), getTotalSearches()); + // eprintf("\nHEAP-ALLOCATED OBJECTS: %d\n", getAllocations()); + // eprintf("TOTAL OBJECT.C ALLOC: %zu\n", getBytes()); } #endif