2020-05-10 13:51:33 -04:00
|
|
|
#ifndef ENVIRONMENT_H
|
|
|
|
#define ENVIRONMENT_H
|
|
|
|
|
|
|
|
#include "object.h"
|
2022-04-04 14:15:02 -04:00
|
|
|
#include "hash.h"
|
|
|
|
|
2022-04-08 11:49:02 -04:00
|
|
|
struct StrippedObject {
|
|
|
|
Type type;
|
|
|
|
void* data;
|
|
|
|
};
|
|
|
|
|
2022-04-04 14:15:02 -04:00
|
|
|
struct EnvElement {
|
|
|
|
char* symbol;
|
2022-04-08 11:49:02 -04:00
|
|
|
struct StrippedObject object;
|
2022-04-04 14:15:02 -04:00
|
|
|
};
|
2020-05-10 13:51:33 -04:00
|
|
|
|
|
|
|
struct Environment;
|
2022-04-09 17:24:18 -04:00
|
|
|
|
2020-05-10 13:51:33 -04:00
|
|
|
struct Environment {
|
2022-01-07 16:55:03 -05:00
|
|
|
struct Environment* outer;
|
2022-04-04 14:15:02 -04:00
|
|
|
struct ObjectTable table;
|
2022-03-27 18:52:56 -04:00
|
|
|
int refs;
|
|
|
|
};
|
|
|
|
|
2022-04-08 11:49:02 -04:00
|
|
|
Object deStrip(struct StrippedObject object);
|
|
|
|
|
2022-03-15 21:43:53 -04:00
|
|
|
struct Environment* global();
|
2022-03-19 22:25:20 -04:00
|
|
|
|
|
|
|
void setGlobal(struct Environment* env);
|
2020-05-10 13:51:33 -04:00
|
|
|
|
2022-01-07 16:55:03 -05:00
|
|
|
Object fetchFromEnvironment(const char* name, struct Environment* env);
|
|
|
|
|
2022-04-07 01:20:59 -04:00
|
|
|
struct Environment envForLambda(const Object* params, const Object* arguments, int paramCount,
|
2022-01-07 16:55:03 -05:00
|
|
|
struct Environment* outer);
|
|
|
|
|
2022-03-19 22:25:20 -04:00
|
|
|
void addToEnv(struct Environment* env, const char* name, Object obj);
|
2022-01-07 16:55:03 -05:00
|
|
|
|
2022-04-18 15:36:54 -04:00
|
|
|
void setInEnv(struct Environment* env, const char* name, Object obj);
|
|
|
|
|
2022-03-31 13:23:15 -04:00
|
|
|
void printEnv(struct Environment* env, int printPointers);
|
2022-01-07 16:55:03 -05:00
|
|
|
|
|
|
|
void addFunc(const char* name,
|
2022-03-24 16:56:52 -04:00
|
|
|
Object (* func)(Object*, int, struct Environment*),
|
2022-04-11 16:38:41 -04:00
|
|
|
struct Environment* env);
|
2022-01-07 16:55:03 -05:00
|
|
|
|
|
|
|
void deleteEnv(struct Environment* e);
|
|
|
|
|
2022-03-27 18:52:56 -04:00
|
|
|
void shredDictionary();
|
|
|
|
|
2020-05-10 13:51:33 -04:00
|
|
|
struct Environment defaultEnv();
|
|
|
|
|
2022-04-04 14:15:02 -04:00
|
|
|
struct Environment defaultEnvPreAllocated(struct EnvElement* elements);
|
2022-04-03 19:17:02 -04:00
|
|
|
|
2022-03-27 18:52:56 -04:00
|
|
|
int getStructIndex(const char* name);
|
|
|
|
|
|
|
|
struct StructDef* getStructAt(int i);
|
|
|
|
|
|
|
|
void addStructDef(struct StructDef def);
|
2022-03-18 11:23:19 -04:00
|
|
|
|
2022-03-25 13:33:26 -04:00
|
|
|
void printColored(const char* code);
|
|
|
|
|
2022-04-11 16:38:41 -04:00
|
|
|
int runTests(int detailed, int specificTest);
|
2022-03-21 12:33:35 -04:00
|
|
|
|
2022-04-04 14:15:02 -04:00
|
|
|
fn(segfault, "seg",
|
2022-04-07 01:20:59 -04:00
|
|
|
"Induces a segfault."
|
2022-04-04 14:15:02 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
fn(help, "?",
|
2022-04-13 15:16:32 -04:00
|
|
|
"Gets a string with help text or a string representation for the object.\n"
|
|
|
|
"\n"
|
|
|
|
" Function help:\n"
|
|
|
|
" (? islist) => \"(islist (1 2 3)) => T\"\n"
|
|
|
|
"\n"
|
|
|
|
" Struct fields:\n"
|
|
|
|
" (? Output) => \"{ stdout stderr }\"\n"
|
|
|
|
"\n"
|
|
|
|
" Other objects:\n"
|
2022-04-13 16:48:09 -04:00
|
|
|
" (? \"Hello\") => \"Hello\"\n"
|
|
|
|
"\n"
|
|
|
|
"Note: The included repl allows you to drop the parentheses."
|
2022-04-04 14:15:02 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2020-05-10 13:51:33 -04:00
|
|
|
#endif
|