commit 9716958fb1b384b7082a34793255fe724979f549
parent 5fa86a458d383918eeb515c7b16d98501b51a828
Author: Ed van Bruggen <edvb@uw.edu>
Date: Wed, 3 Oct 2018 16:15:18 -0700
Make functions not needed externally static
Diffstat:
tisp.c | | | 70 | +++++++++++++++++++++++++++++++++++++++++++++------------------------- |
tisp.h | | | 20 | +------------------- |
2 files changed, 46 insertions(+), 44 deletions(-)
diff --git a/tisp.c b/tisp.c
@@ -31,10 +31,39 @@
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
+#define warnf(M, ...) do { \
+ fprintf(stderr, "tisp:%d: error: " M "\n", \
+ __LINE__, ##__VA_ARGS__); \
+ return NULL; \
+} while(0)
+#define warn(M) do { \
+ fprintf(stderr, "tisp:%d: error: " M "\n", \
+ __LINE__); \
+ return NULL; \
+} while(0)
+
+
/* functions */
+static void hash_add(Hash ht, char *key, Val val);
static Hash hash_extend(Hash ht, Val args, Val vals);
static void hash_merge(Hash ht, Hash ht2);
+char *
+type_str(Type t)
+{
+ switch (t) {
+ case NIL: return "nil";
+ case INTEGER: return "integer";
+ case RATIONAL: return "rational";
+ case STRING: return "string";
+ case SYMBOL: return "symbol";
+ case PRIMITIVE: return "primitive";
+ case FUNCTION: return "function";
+ case PAIR: return "pair";
+ default: return "invalid";
+ }
+}
+
static void
die(const char *fmt, ...)
{
@@ -80,7 +109,7 @@ erealloc(void *p, size_t size)
return p;
}
-void
+static void
skip_spaces(Str str)
{
str->d += strspn(str->d, " \t\n"); /* skip white space */
@@ -88,14 +117,14 @@ skip_spaces(Str str)
str->d += strcspn(str->d, "\n");
}
-int
+static int
issym(char c)
{
return BETWEEN(c, 'a', 'z') || BETWEEN(c, 'A', 'Z') ||
BETWEEN(c, '0', '9') || strchr("+-*/=<>?", c);
}
-int
+static int
list_len(Val v)
{
int len = 0;
@@ -136,7 +165,7 @@ static void
frac_reduce(int *num, int *den)
{
int a = abs(*num), b = abs(*den), c = a % b;
- while(c > 0) {
+ while (c > 0) {
a = b;
b = c;
c = a % b;
@@ -145,22 +174,6 @@ frac_reduce(int *num, int *den)
*den = *den / b;
}
-char *
-type_str(Type t)
-{
- switch (t) {
- case NIL: return "nil";
- case INTEGER: return "integer";
- case RATIONAL: return "rational";
- case STRING: return "string";
- case SYMBOL: return "symbol";
- case PRIMITIVE: return "primitive";
- case FUNCTION: return "function";
- case PAIR: return "pair";
- default: return "invalid";
- }
-}
-
/* return hashed number based on key */
static uint32_t
hash(char *key)
@@ -230,7 +243,7 @@ hash_grow(Hash ht)
}
/* create new key and value pair to the hash table */
-void
+static void
hash_add(Hash ht, char *key, Val val)
{
Entry e = entry_get(ht, key);
@@ -298,7 +311,8 @@ mk_rat(int num, int den)
return ret;
}
-Val mk_str(char *s) {
+Val
+mk_str(char *s) {
Val ret = emalloc(sizeof(struct Val));
ret->t = STRING;
ret->v.s = emalloc((strlen(s)+1) * sizeof(char));
@@ -391,7 +405,7 @@ read_str(Str str)
return mk_str(s);
}
-Val
+static Val
read_sym(Str str)
{
int n = 1;
@@ -408,7 +422,7 @@ read_sym(Str str)
return mk_sym(sym);
}
-Val
+static Val
read_list(Env env, Str str)
{
int n = 0;
@@ -446,7 +460,7 @@ tisp_read(Env env, Str str)
return NULL;
}
-Val
+static Val
eval_list(Env env, Val v)
{
int cap = 1, size = 0;
@@ -673,6 +687,12 @@ prim_load(Env env, Val args)
return NULL;
}
+void
+tisp_env_add(Env e, char *key, Val v)
+{
+ hash_add(e->h, key, v);
+}
+
Env
tisp_env_init(size_t cap)
{
diff --git a/tisp.h b/tisp.h
@@ -19,18 +19,6 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
-#define warnf(M, ...) do { \
- fprintf(stderr, "tisp:%d: error: " M "\n", \
- __LINE__, ##__VA_ARGS__); \
- return NULL; \
-} while(0)
-
-#define warn(M) do { \
- fprintf(stderr, "tisp:%d: error: " M "\n", \
- __LINE__); \
- return NULL; \
-} while(0)
-
#define car(P) ((P)->v.p.car)
#define cdr(P) ((P)->v.p.cdr)
#define nilp(P) ((P)->t == NIL)
@@ -109,12 +97,7 @@ struct Env {
size_t libhc;
};
-void skip_spaces(Str str);
char *type_str(Type t);
-int issym(char c);
-int list_len(Val v);
-
-void hash_add(Hash ht, char *key, Val val);
Val mk_int(int i);
Val mk_str(char *s);
@@ -125,11 +108,10 @@ Val mk_func(Val args, Val body, Env env);
Val mk_pair(Val a, Val b);
Val mk_list(Env env, int n, Val *a);
-Val eval_list(Env env, Val v);
-
Val tisp_read(Env env, Str str);
void tisp_print(Val v);
Val tisp_eval(Env env, Val v);
+void tisp_env_add(Env e, char *key, Val v);
Env tisp_env_init(size_t cap);
void tisp_env_free(Env env);