Remove readFromEnvironment().
Something about it was buggy. Might be worth coming back to.
This commit is contained in:
parent
f12d8bea7f
commit
857219a4e8
11
src/env.c
11
src/env.c
|
@ -23,11 +23,6 @@ void setGlobal(struct Environment* env)
|
||||||
struct Dictionary dictionary;
|
struct Dictionary dictionary;
|
||||||
|
|
||||||
Object fetchFromEnvironment(const char* name, struct Environment* env)
|
Object fetchFromEnvironment(const char* name, struct Environment* env)
|
||||||
{
|
|
||||||
return cloneObject(readFromEnvironment(name, env));
|
|
||||||
}
|
|
||||||
|
|
||||||
Object readFromEnvironment(const char* name, struct Environment* env)
|
|
||||||
{
|
{
|
||||||
if (!env) {
|
if (!env) {
|
||||||
return errorObject(NULL_ENV);
|
return errorObject(NULL_ENV);
|
||||||
|
@ -35,7 +30,7 @@ Object readFromEnvironment(const char* name, struct Environment* env)
|
||||||
|
|
||||||
if (env->capacity == 0) {
|
if (env->capacity == 0) {
|
||||||
if (env->outer) {
|
if (env->outer) {
|
||||||
return readFromEnvironment(name, env->outer);
|
return fetchFromEnvironment(name, env->outer);
|
||||||
} else {
|
} else {
|
||||||
return errorObject(EMPTY_ENV);
|
return errorObject(EMPTY_ENV);
|
||||||
}
|
}
|
||||||
|
@ -48,13 +43,13 @@ Object readFromEnvironment(const char* name, struct Environment* env)
|
||||||
|
|
||||||
printd("Try %d (%s)\n", i, env->strings[i]);
|
printd("Try %d (%s)\n", i, env->strings[i]);
|
||||||
if (strcmp(name, env->strings[i]) == 0) { printd("Returning!\n");
|
if (strcmp(name, env->strings[i]) == 0) { printd("Returning!\n");
|
||||||
return env->objects[i];
|
return cloneObject(env->objects[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printd("Trying outer %p\n", env->outer);
|
printd("Trying outer %p\n", env->outer);
|
||||||
if (env->outer) {
|
if (env->outer) {
|
||||||
return readFromEnvironment(name, env->outer);
|
return fetchFromEnvironment(name, env->outer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorWithContext(DID_NOT_FIND_SYMBOL, name);
|
return errorWithContext(DID_NOT_FIND_SYMBOL, name);
|
||||||
|
|
|
@ -23,9 +23,6 @@ struct Environment* global();
|
||||||
|
|
||||||
void setGlobal(struct Environment* env);
|
void setGlobal(struct Environment* env);
|
||||||
|
|
||||||
/// Does NOT clone
|
|
||||||
Object readFromEnvironment(const char* name, struct Environment* env);
|
|
||||||
|
|
||||||
Object fetchFromEnvironment(const char* name, struct Environment* env);
|
Object fetchFromEnvironment(const char* name, struct Environment* env);
|
||||||
|
|
||||||
struct Environment envForLambda(const Object* params, const Object* arg_forms, int paramCount,
|
struct Environment envForLambda(const Object* params, const Object* arg_forms, int paramCount,
|
||||||
|
|
|
@ -600,7 +600,9 @@ void repl(struct Environment* env)
|
||||||
{
|
{
|
||||||
char* buf;
|
char* buf;
|
||||||
using_history();
|
using_history();
|
||||||
while ((buf = readline(readFromEnvironment("prompt", env).string)) != NULL) {
|
Object prompt;
|
||||||
|
while ((buf = readline((prompt = fetchFromEnvironment("prompt", env)).string)) != NULL) {
|
||||||
|
cleanObject(&prompt);
|
||||||
if (strcmp("q", buf) == 0) {
|
if (strcmp("q", buf) == 0) {
|
||||||
free(buf);
|
free(buf);
|
||||||
break;
|
break;
|
||||||
|
@ -618,11 +620,13 @@ void repl(struct Environment* env)
|
||||||
size_t length;
|
size_t length;
|
||||||
char *output = stringObj(&o, &length);
|
char *output = stringObj(&o, &length);
|
||||||
printColored(output);
|
printColored(output);
|
||||||
free(output);
|
|
||||||
printf("[0m\n");
|
printf("[0m\n");
|
||||||
|
|
||||||
cleanObject(&o);
|
cleanObject(&o);
|
||||||
|
free(output);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
cleanObject(&prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadArgsIntoEnv(int argc, const char* argv[], struct Environment* env)
|
void loadArgsIntoEnv(int argc, const char* argv[], struct Environment* env)
|
||||||
|
@ -660,19 +664,15 @@ int main(int argc, const char* argv[])
|
||||||
struct Environment env = defaultEnv();
|
struct Environment env = defaultEnv();
|
||||||
setGlobal(&env);
|
setGlobal(&env);
|
||||||
|
|
||||||
int ret = -1;
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (strcmp(argv[1], "--run-tests") == 0) {
|
const char* runTestsArg = "--run-tests";
|
||||||
ret = runTests(0);
|
if (strncmp(argv[1], runTestsArg, strlen(runTestsArg)) == 0) {
|
||||||
} else if (strcmp(argv[1], "--run-tests=detailed") == 0) {
|
int ret = runTests(strcmp(argv[1] + strlen(runTestsArg), "=detailed") == 0);
|
||||||
ret = runTests(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ret != -1) {
|
|
||||||
shredDictionary();
|
shredDictionary();
|
||||||
deleteEnv(global());
|
deleteEnv(global());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
memset(&action, 0, sizeof(struct sigaction));
|
memset(&action, 0, sizeof(struct sigaction));
|
||||||
|
@ -682,7 +682,8 @@ int main(int argc, const char* argv[])
|
||||||
|
|
||||||
readFile(SCRIPTDIR "/lib.pbl", &env);
|
readFile(SCRIPTDIR "/lib.pbl", &env);
|
||||||
|
|
||||||
parseEval("(def prompt \"pebblisp::> \")", &env);
|
Object o = parseEval("(def prompt \"pebblisp::> \")", &env);
|
||||||
|
cleanObject(&o);
|
||||||
|
|
||||||
char config[strlen(getenv("HOME")) + 15];
|
char config[strlen(getenv("HOME")) + 15];
|
||||||
sprintf(config, "%s/.pebblisp.pbl", getenv("HOME"));
|
sprintf(config, "%s/.pebblisp.pbl", getenv("HOME"));
|
||||||
|
@ -691,11 +692,11 @@ int main(int argc, const char* argv[])
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
FILE* file = fopen(argv[1], "r");
|
FILE* file = fopen(argv[1], "r");
|
||||||
if (file) {
|
if (file) {
|
||||||
// Executing a file
|
// Execute a file
|
||||||
loadArgsIntoEnv(argc, argv, &env);
|
loadArgsIntoEnv(argc, argv, &env);
|
||||||
_readFile(file, &env);
|
_readFile(file, &env);
|
||||||
} else {
|
} else {
|
||||||
// Running arguments directly as pl code
|
// Run arguments directly as pl code
|
||||||
Object r = numberObject(0);
|
Object r = numberObject(0);
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
r = parseEval(argv[i], &env);
|
r = parseEval(argv[i], &env);
|
||||||
|
@ -703,7 +704,7 @@ int main(int argc, const char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Running a repl
|
// Run a repl
|
||||||
loadArgsIntoEnv(argc, argv, &env);
|
loadArgsIntoEnv(argc, argv, &env);
|
||||||
repl(&env);
|
repl(&env);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue