|
@@ -1,4 +1,7 @@
|
|
|
+#include "version.h"
|
|
|
#include <ctype.h>
|
|
|
+#include <errno.h>
|
|
|
+#include <gc.h>
|
|
|
#include <limits.h>
|
|
|
#include <math.h>
|
|
|
#include <setjmp.h>
|
|
@@ -7,12 +10,9 @@
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
+#include <sys/wait.h>
|
|
|
#include <time.h>
|
|
|
#include <unistd.h>
|
|
|
-#include <sys/wait.h>
|
|
|
-#include <errno.h>
|
|
|
-#include <gc.h>
|
|
|
-#include "version.h"
|
|
|
|
|
|
jmp_buf interactive_checkpoint;
|
|
|
bool is_interactive;
|
|
@@ -76,9 +76,7 @@ list_t *list_new(void) {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-bool list_empty(list_t *list) {
|
|
|
- return (!(list)->value);
|
|
|
-}
|
|
|
+bool list_empty(list_t *list) { return (!(list)->value); }
|
|
|
|
|
|
size_t list_length(list_t *list) {
|
|
|
size_t length = 0;
|
|
@@ -419,9 +417,7 @@ jmp_buf *guard() {
|
|
|
return lb;
|
|
|
}
|
|
|
|
|
|
-jmp_buf *guarding() {
|
|
|
- return list_index(guards, -1);
|
|
|
-}
|
|
|
+jmp_buf *guarding() { return list_index(guards, -1); }
|
|
|
|
|
|
void unguard() {
|
|
|
jmp_buf *lb = list_pop(guards);
|
|
@@ -589,13 +585,9 @@ table_t *table_new(void) {
|
|
|
return table;
|
|
|
}
|
|
|
|
|
|
-size_t table_length(table_t *table) {
|
|
|
- return table->used;
|
|
|
-}
|
|
|
+size_t table_length(table_t *table) { return table->used; }
|
|
|
|
|
|
-bool table_empty(table_t *table) {
|
|
|
- return table->used == 0;
|
|
|
-}
|
|
|
+bool table_empty(table_t *table) { return table->used == 0; }
|
|
|
|
|
|
static uint64_t MM86128(void *key, const int len, uint32_t seed) {
|
|
|
#define ROTL32(x, r) ((x << r) | (x >> (32 - r)))
|
|
@@ -1883,7 +1875,8 @@ value_t *interpreter_walk(interpreter_t *state, node_t *node) {
|
|
|
r->val.verb->mark = true;
|
|
|
|
|
|
value_t *ov = table_get(state->env, l->val.symbol);
|
|
|
- if (ov && ov->tag == VERB && ov->val.verb->is_fun && r->tag == VERB && r->val.verb->is_fun) {
|
|
|
+ if (ov && ov->tag == VERB && ov->val.verb->is_fun && r->tag == VERB &&
|
|
|
+ r->val.verb->is_fun) {
|
|
|
if (!ov->val.verb->monad && r->val.verb->monad) {
|
|
|
list_set(ov->val.verb->bonds, 0, r->val.verb->bonds->value);
|
|
|
|
|
@@ -1940,21 +1933,22 @@ value_t *verb_bind(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
return state->udf;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
table_t *Inverses;
|
|
|
|
|
|
-value_t *verb_obverse(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
+value_t *verb_obverse(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
if (x->tag == VERB && y->tag == VERB) {
|
|
|
verb_t *vx = x->val.verb;
|
|
|
|
|
|
- if (!y->val.verb->monad)
|
|
|
+ if (!y->val.verb->monad)
|
|
|
return state->udf;
|
|
|
|
|
|
- if (strcmp(vx->name, ":...") == 0 || strcmp(vx->name, ":x") == 0 || strcmp(vx->name, ":xy") == 0)
|
|
|
+ if (strcmp(vx->name, ":...") == 0 || strcmp(vx->name, ":x") == 0 ||
|
|
|
+ strcmp(vx->name, ":xy") == 0)
|
|
|
return state->udf;
|
|
|
|
|
|
if (table_has(Inverses, vx->name))
|
|
|
- return state->udf;
|
|
|
+ return state->udf;
|
|
|
|
|
|
table_set(Inverses, vx->name, y->val.verb);
|
|
|
|
|
@@ -2017,7 +2011,7 @@ value_t *verb_plus(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
|
|
|
value_t *verb_sign(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
if (x->tag == NUMBER)
|
|
|
- return x->val.number < 0? NNUMS[0]: x->val.number > 0? NUMS[1]: NUMS[0];
|
|
|
+ return x->val.number < 0 ? NNUMS[0] : x->val.number > 0 ? NUMS[1] : NUMS[0];
|
|
|
|
|
|
return _NAN;
|
|
|
}
|
|
@@ -2287,7 +2281,8 @@ value_t *verb_odometer(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
|
|
|
p *= (size_t)(it->val.number);
|
|
|
|
|
|
- t = t->next; xl++;
|
|
|
+ t = t->next;
|
|
|
+ xl++;
|
|
|
}
|
|
|
|
|
|
if (p < 1)
|
|
@@ -2306,23 +2301,25 @@ value_t *verb_odometer(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
for (size_t i = 0; i < p; i++)
|
|
|
z[i] = malloc_checked_atomic(sizeof(uint64_t) * xl);
|
|
|
|
|
|
- for (size_t i = 0; i < p-1; i++) {
|
|
|
+ for (size_t i = 0; i < p - 1; i++) {
|
|
|
uint64_t *r = z[i];
|
|
|
uint64_t *s = z[i + 1];
|
|
|
|
|
|
bool carry = true;
|
|
|
|
|
|
for (size_t j = 0; j < xl; j++) {
|
|
|
- uint64_t a = xl-1-j;
|
|
|
+ uint64_t a = xl - 1 - j;
|
|
|
|
|
|
s[a] = r[a];
|
|
|
|
|
|
if (carry) {
|
|
|
- s[a]++; carry = false;
|
|
|
+ s[a]++;
|
|
|
+ carry = false;
|
|
|
}
|
|
|
|
|
|
if (s[a] >= lims[a]) {
|
|
|
- s[a] = 0; carry = true;
|
|
|
+ s[a] = 0;
|
|
|
+ carry = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -2346,7 +2343,8 @@ value_t *verb_odometer(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
return value_new_array(r);
|
|
|
}
|
|
|
|
|
|
-value_t *verb_chunks(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
+value_t *verb_chunks(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
if (x->tag != NUMBER)
|
|
|
return state->udf;
|
|
|
|
|
@@ -2360,7 +2358,8 @@ value_t *verb_chunks(interpreter_t *state, verb_t *self, value_t *x, value_t *y)
|
|
|
size_t l = list_length(y->val.array);
|
|
|
size_t cl = fabs(x->val.number);
|
|
|
for (size_t i = 0; i < l; i += cl)
|
|
|
- list_push(r, verb_take(state, NULL, value_new_number(cl), verb_drop(state, NULL, value_new_number(i), y)));
|
|
|
+ list_push(r, verb_take(state, NULL, value_new_number(cl),
|
|
|
+ verb_drop(state, NULL, value_new_number(i), y)));
|
|
|
|
|
|
return value_new_array(r);
|
|
|
}
|
|
@@ -2530,7 +2529,7 @@ value_t *verb_buckets(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
t = t->next;
|
|
|
}
|
|
|
|
|
|
- for (size_t i = 0; i < mx+1; i++)
|
|
|
+ for (size_t i = 0; i < mx + 1; i++)
|
|
|
list_push(r, list_new());
|
|
|
|
|
|
if (list_empty(r)) {
|
|
@@ -2555,7 +2554,8 @@ value_t *verb_buckets(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
list_push(b, ty->value);
|
|
|
}
|
|
|
|
|
|
- t = t->next; ty = ty->next;
|
|
|
+ t = t->next;
|
|
|
+ ty = ty->next;
|
|
|
}
|
|
|
|
|
|
if (ty) {
|
|
@@ -2588,7 +2588,7 @@ value_t *verb_permute(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
if (x->tag != ARRAY || list_empty(x->val.array) || !x->val.array->next)
|
|
|
return x;
|
|
|
|
|
|
- list_t* permutation = list_copy(x->val.array);
|
|
|
+ list_t *permutation = list_copy(x->val.array);
|
|
|
size_t length = list_length(permutation);
|
|
|
|
|
|
list_t *result = list_new();
|
|
@@ -2719,8 +2719,7 @@ value_t *verb_occurences(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
return value_new_array(r);
|
|
|
}
|
|
|
|
|
|
-value_t *verb_mask(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
- value_t *y) {
|
|
|
+value_t *verb_mask(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
if (x->tag != ARRAY)
|
|
|
x = verb_enlist(state, NULL, x);
|
|
|
else if (list_empty(x->val.array))
|
|
@@ -2737,7 +2736,8 @@ value_t *verb_mask(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
|
|
|
size_t k = list_length(x->val.array);
|
|
|
for (size_t i = 0; i < k; i++) {
|
|
|
- value_t *s = verb_take(state, NULL, l, verb_drop(state, NULL, value_new_number(i), x));
|
|
|
+ value_t *s = verb_take(state, NULL, l,
|
|
|
+ verb_drop(state, NULL, value_new_number(i), x));
|
|
|
if (value_equals(s, y)) {
|
|
|
n++;
|
|
|
|
|
@@ -2745,7 +2745,8 @@ value_t *verb_mask(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
list_push(r, value_new_number(n));
|
|
|
|
|
|
i--;
|
|
|
- } else list_push(r, NUMS[0]);
|
|
|
+ } else
|
|
|
+ list_push(r, NUMS[0]);
|
|
|
}
|
|
|
|
|
|
return value_new_array(r);
|
|
@@ -3171,7 +3172,8 @@ value_t *verb_take(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
if (y->tag != ARRAY) {
|
|
|
if (x->val.number == 0)
|
|
|
return state->unit;
|
|
|
- else return x;
|
|
|
+ else
|
|
|
+ return x;
|
|
|
}
|
|
|
|
|
|
if (x->val.number == 0 || list_empty(y->val.array))
|
|
@@ -3316,7 +3318,8 @@ value_t *verb_drop(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
if (y->tag != ARRAY) {
|
|
|
if (x->val.number == 0)
|
|
|
return y;
|
|
|
- else return state->unit;
|
|
|
+ else
|
|
|
+ return state->unit;
|
|
|
}
|
|
|
|
|
|
if (x->val.number == 0)
|
|
@@ -3519,7 +3522,8 @@ value_t *verb_rotate(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
return value_new_array(r);
|
|
|
}
|
|
|
|
|
|
-value_t *verb_windows(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
+value_t *verb_windows(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
if (y->tag != ARRAY)
|
|
|
y = verb_enlist(state, NULL, y);
|
|
|
else if (list_empty(y->val.array))
|
|
@@ -3534,7 +3538,8 @@ value_t *verb_windows(interpreter_t *state, verb_t *self, value_t *x, value_t *y
|
|
|
if (i + k > l)
|
|
|
break;
|
|
|
|
|
|
- list_push(r, verb_take(state, NULL, value_new_number(k), verb_drop(state, NULL, value_new_number(i), y)));
|
|
|
+ list_push(r, verb_take(state, NULL, value_new_number(k),
|
|
|
+ verb_drop(state, NULL, value_new_number(i), y)));
|
|
|
}
|
|
|
|
|
|
return value_new_array(r);
|
|
@@ -3634,7 +3639,8 @@ value_t *verb_shuffle(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
while (t) {
|
|
|
list_push(r, t->value);
|
|
|
|
|
|
- t = t->next; l++;
|
|
|
+ t = t->next;
|
|
|
+ l++;
|
|
|
}
|
|
|
|
|
|
for (size_t i = 0; i < l; i++) {
|
|
@@ -3675,21 +3681,24 @@ value_t *verb_bin(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
s = vs->val.number;
|
|
|
else if (vs->tag == CHAR)
|
|
|
s = vs->val._char;
|
|
|
- else return state->udf;
|
|
|
+ else
|
|
|
+ return state->udf;
|
|
|
|
|
|
- value_t *ve = i == xl - 1? value_new_number(s + 1): list_index(x->val.array, i + 1);
|
|
|
+ value_t *ve =
|
|
|
+ i == xl - 1 ? value_new_number(s + 1) : list_index(x->val.array, i + 1);
|
|
|
if (ve->tag == NUMBER)
|
|
|
e = fabs(ve->val.number);
|
|
|
else if (ve->tag == CHAR)
|
|
|
e = ve->val._char;
|
|
|
- else return state->udf;
|
|
|
+ else
|
|
|
+ return state->udf;
|
|
|
|
|
|
if (list_length(bins) > 0) {
|
|
|
list_t *pp = list_index(bins, -1);
|
|
|
double *pe = pp->value;
|
|
|
|
|
|
if (s <= (*pe))
|
|
|
- return state->udf;
|
|
|
+ return state->udf;
|
|
|
}
|
|
|
|
|
|
double *sn = malloc_checked(sizeof(double));
|
|
@@ -3718,7 +3727,8 @@ value_t *verb_bin(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
itv = it->val.number;
|
|
|
else if (it->tag == CHAR)
|
|
|
itv = it->val._char;
|
|
|
- else return state->udf;
|
|
|
+ else
|
|
|
+ return state->udf;
|
|
|
|
|
|
list_t *b = bins->value;
|
|
|
double *s = b->value;
|
|
@@ -3747,7 +3757,8 @@ value_t *verb_bin(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
double *e = b->next->value;
|
|
|
|
|
|
if (itv >= (*s) && itv < (*e)) {
|
|
|
- v = j; break;
|
|
|
+ v = j;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3892,7 +3903,7 @@ value_t *verb_right(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
return y;
|
|
|
}
|
|
|
|
|
|
-value_t *verb_symbol(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
+value_t *verb_symbol(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
char *s = value_show(x);
|
|
|
|
|
|
return value_new_symbol(s);
|
|
@@ -3971,7 +3982,8 @@ value_t *verb_reshape(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
size_t k = fabs(a->val.number);
|
|
|
size_t l = fabs(b->val.number);
|
|
|
|
|
|
- y = verb_reshape(state, self, verb_enlist(state, NULL, value_new_number(k * l)), y);
|
|
|
+ y = verb_reshape(state, self,
|
|
|
+ verb_enlist(state, NULL, value_new_number(k * l)), y);
|
|
|
|
|
|
list_t *t = y->val.array;
|
|
|
|
|
@@ -4315,7 +4327,8 @@ value_t *verb_read(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
if (c < 0)
|
|
|
break;
|
|
|
|
|
|
- buffer_append(buf, c); size++;
|
|
|
+ buffer_append(buf, c);
|
|
|
+ size++;
|
|
|
}
|
|
|
|
|
|
char *s = buffer_read(buf);
|
|
@@ -4327,8 +4340,7 @@ value_t *verb_read(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
GC_FREE(s);
|
|
|
|
|
|
return value_new_array(r);
|
|
|
- }
|
|
|
- else if (x == NUMS[1]) {
|
|
|
+ } else if (x == NUMS[1]) {
|
|
|
char line[512];
|
|
|
|
|
|
if (!fgets(line, sizeof(line), stdin))
|
|
@@ -4354,7 +4366,7 @@ value_t *verb_read(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
|
|
|
size_t size = ftell(fd);
|
|
|
|
|
|
- fseek(fd, 0, SEEK_SET);
|
|
|
+ fseek(fd, 0, SEEK_SET);
|
|
|
|
|
|
unsigned char *buf = malloc_checked(size + 1);
|
|
|
if (!buf)
|
|
@@ -4381,18 +4393,18 @@ value_t *verb_write(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
char *path = NULL;
|
|
|
|
|
|
if (x->tag != ARRAY)
|
|
|
- x = verb_enlist(state, NULL, x);
|
|
|
+ x = verb_enlist(state, NULL, x);
|
|
|
|
|
|
if (y == NUMS[0])
|
|
|
fd = stderr;
|
|
|
- else {
|
|
|
+ else {
|
|
|
path = value_show(y);
|
|
|
|
|
|
fd = fopen(path, "wb");
|
|
|
if (!fd) {
|
|
|
GC_FREE(path);
|
|
|
|
|
|
- return NNUMS[0];
|
|
|
+ return NNUMS[0];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -4407,16 +4419,19 @@ value_t *verb_write(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
c = fabs(v->val.number);
|
|
|
else if (v->tag == CHAR)
|
|
|
c = v->val._char;
|
|
|
- else break;
|
|
|
+ else
|
|
|
+ break;
|
|
|
|
|
|
fputc(c, fd);
|
|
|
|
|
|
- t = t->next; k++;
|
|
|
+ t = t->next;
|
|
|
+ k++;
|
|
|
}
|
|
|
|
|
|
fclose(fd);
|
|
|
|
|
|
- if (path) GC_FREE(path);
|
|
|
+ if (path)
|
|
|
+ GC_FREE(path);
|
|
|
|
|
|
return value_new_number(k);
|
|
|
}
|
|
@@ -4453,20 +4468,21 @@ value_t *verb_system(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
if (!buffer)
|
|
|
buffer = malloc_checked(buffer_allocated);
|
|
|
else
|
|
|
- buffer = realloc_checked(buffer, buffer_allocated);
|
|
|
+ buffer = realloc_checked(buffer, buffer_allocated);
|
|
|
|
|
|
- if (!buffer){
|
|
|
+ if (!buffer) {
|
|
|
GC_FREE(cmd);
|
|
|
pclose(pd);
|
|
|
|
|
|
return state->udf;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
for (size_t i = 0; i < bytes_received; i++)
|
|
|
- buffer[head + i] = chunk[i];
|
|
|
+ buffer[head + i] = chunk[i];
|
|
|
|
|
|
- if (feof(pd)) break;
|
|
|
+ if (feof(pd))
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
pclose(pd);
|
|
@@ -4550,25 +4566,25 @@ static int _do_popen2(files_chain_t *link, const char *command) {
|
|
|
}
|
|
|
|
|
|
files_t *popen2(const char *command) {
|
|
|
- files_chain_t *link = (files_chain_t *) malloc(sizeof (files_chain_t));
|
|
|
+ files_chain_t *link = (files_chain_t *)malloc(sizeof(files_chain_t));
|
|
|
if (NULL == link)
|
|
|
return NULL;
|
|
|
|
|
|
if (0 > _do_popen2(link, command)) {
|
|
|
- free(link);
|
|
|
- return NULL;
|
|
|
+ free(link);
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
link->next = files_chain;
|
|
|
files_chain = link;
|
|
|
- return (files_t *) link;
|
|
|
+ return (files_t *)link;
|
|
|
}
|
|
|
|
|
|
int pclose2(files_t *fp) {
|
|
|
files_chain_t **p = &files_chain;
|
|
|
int found = 0;
|
|
|
while (*p) {
|
|
|
- if (*p == (files_chain_t *) fp) {
|
|
|
+ if (*p == (files_chain_t *)fp) {
|
|
|
*p = (*p)->next;
|
|
|
found = 1;
|
|
|
break;
|
|
@@ -4581,17 +4597,17 @@ int pclose2(files_t *fp) {
|
|
|
return -1;
|
|
|
|
|
|
if (0 > fclose(fp->out)) {
|
|
|
- free((files_chain_t *) fp);
|
|
|
+ free((files_chain_t *)fp);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
int status = -1;
|
|
|
pid_t wait_pid;
|
|
|
do {
|
|
|
- wait_pid = waitpid(((files_chain_t *) fp)->pid, &status, 0);
|
|
|
+ wait_pid = waitpid(((files_chain_t *)fp)->pid, &status, 0);
|
|
|
} while (-1 == wait_pid && EINTR == errno);
|
|
|
|
|
|
- free((files_chain_t *) fp);
|
|
|
+ free((files_chain_t *)fp);
|
|
|
|
|
|
if (wait_pid == -1)
|
|
|
return -1;
|
|
@@ -4599,7 +4615,8 @@ int pclose2(files_t *fp) {
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
-value_t *verb_system2(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
+value_t *verb_system2(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
char *cmd = value_show(y);
|
|
|
|
|
|
files_t *pd;
|
|
@@ -4619,7 +4636,8 @@ value_t *verb_system2(interpreter_t *state, verb_t *self, value_t *x, value_t *y
|
|
|
c = fabs(v->val.number);
|
|
|
else if (v->tag == CHAR)
|
|
|
c = v->val._char;
|
|
|
- else break;
|
|
|
+ else
|
|
|
+ break;
|
|
|
|
|
|
fputc(c, pd->in);
|
|
|
|
|
@@ -4650,20 +4668,21 @@ value_t *verb_system2(interpreter_t *state, verb_t *self, value_t *x, value_t *y
|
|
|
if (!buffer)
|
|
|
buffer = malloc_checked(buffer_allocated);
|
|
|
else
|
|
|
- buffer = realloc_checked(buffer, buffer_allocated);
|
|
|
+ buffer = realloc_checked(buffer, buffer_allocated);
|
|
|
|
|
|
- if (!buffer){
|
|
|
+ if (!buffer) {
|
|
|
GC_FREE(cmd);
|
|
|
pclose2(pd);
|
|
|
|
|
|
return state->udf;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
for (size_t i = 0; i < bytes_received; i++)
|
|
|
- buffer[head + i] = chunk[i];
|
|
|
+ buffer[head + i] = chunk[i];
|
|
|
|
|
|
- if (feof(pd->out)) break;
|
|
|
+ if (feof(pd->out))
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
pclose2(pd);
|
|
@@ -4749,12 +4768,12 @@ list_t *find_primes(uint64_t limit) {
|
|
|
value_t *verb_primes(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
if (x->tag == NUMBER && !is_bad_num(x->val.number))
|
|
|
return value_new_array(find_primes(fabs(x->val.number) + 1));
|
|
|
-
|
|
|
|
|
|
return state->udf;
|
|
|
}
|
|
|
|
|
|
-value_t *verb_parts(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
+value_t *verb_parts(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
if (x->tag != NUMBER)
|
|
|
return state->udf;
|
|
|
|
|
@@ -4799,7 +4818,8 @@ list_t *prime_factors(double n) {
|
|
|
list_push(factors, value_new_number(divisor));
|
|
|
|
|
|
n /= divisor;
|
|
|
- } else divisor++;
|
|
|
+ } else
|
|
|
+ divisor++;
|
|
|
}
|
|
|
|
|
|
return factors;
|
|
@@ -4814,7 +4834,8 @@ value_t *verb_factors(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
|
|
|
value_t *verb_combine(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
value_t *y) {
|
|
|
- if (x->tag == NUMBER && y->tag == NUMBER && !is_bad_num(x->val.number) && !is_bad_num(y->val.number)) {
|
|
|
+ if (x->tag == NUMBER && y->tag == NUMBER && !is_bad_num(x->val.number) &&
|
|
|
+ !is_bad_num(y->val.number)) {
|
|
|
value_t *n = verb_enpair(state, NULL, x, y);
|
|
|
|
|
|
return verb_unbase(state, NULL, NUMS[10], n);
|
|
@@ -4825,11 +4846,13 @@ value_t *verb_combine(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
|
|
|
value_t *verb_outof(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
value_t *y) {
|
|
|
- if (x->tag == NUMBER && y->tag == NUMBER && !is_bad_num(x->val.number) && !is_bad_num(y->val.number) && x->val.number > 0 && y->val.number > 0) {
|
|
|
+ if (x->tag == NUMBER && y->tag == NUMBER && !is_bad_num(x->val.number) &&
|
|
|
+ !is_bad_num(y->val.number) && x->val.number > 0 && y->val.number > 0) {
|
|
|
uint64_t a = (uint64_t)fabs(x->val.number);
|
|
|
uint64_t b = (uint64_t)fabs(y->val.number);
|
|
|
|
|
|
- return value_new_number(factorial(b) / (factorial(a) * (a >= b? 1: factorial(b - a))));
|
|
|
+ return value_new_number(factorial(b) /
|
|
|
+ (factorial(a) * (a >= b ? 1 : factorial(b - a))));
|
|
|
}
|
|
|
|
|
|
return _NAN;
|
|
@@ -4838,13 +4861,15 @@ value_t *verb_outof(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
value_t *verb_sort(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
value_t *i = verb_gradeup(state, NULL, x);
|
|
|
|
|
|
- return together(state, state->at, x, i, 0, 0, state->at->rank[1], state->at->rank[2]);
|
|
|
+ return together(state, state->at, x, i, 0, 0, state->at->rank[1],
|
|
|
+ state->at->rank[2]);
|
|
|
}
|
|
|
|
|
|
value_t *verb_unsort(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
value_t *i = verb_gradedown(state, NULL, x);
|
|
|
|
|
|
- return together(state, state->at, x, i, 0, 0, state->at->rank[1], state->at->rank[2]);
|
|
|
+ return together(state, state->at, x, i, 0, 0, state->at->rank[1],
|
|
|
+ state->at->rank[2]);
|
|
|
}
|
|
|
|
|
|
value_t *interpreter_run(interpreter_t *state, char *program);
|
|
@@ -4885,7 +4910,7 @@ value_t *verb_import(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
|
|
|
size_t size = ftell(fd);
|
|
|
|
|
|
- fseek(fd, 0, SEEK_SET);
|
|
|
+ fseek(fd, 0, SEEK_SET);
|
|
|
|
|
|
unsigned char *buf = malloc_checked(size + 1);
|
|
|
if (!buf)
|
|
@@ -4920,7 +4945,8 @@ value_t *verb_explode(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
|
|
|
t = list_new();
|
|
|
|
|
|
- i += dell-1; continue;
|
|
|
+ i += dell - 1;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
list_push(t, CHARS[s[i]]);
|
|
@@ -4998,87 +5024,88 @@ value_t *verb_udf2(interpreter_t *state, verb_t *self, value_t *x, value_t *y) {
|
|
|
|
|
|
#define X UINT_MAX
|
|
|
#define DEFVERB(__symb, __rm, __rl, __rr, __monad, __dyad) \
|
|
|
- {__symb, {__rm, __rl, __rr}, NULL, false, false, verb_##__monad, verb_##__dyad}
|
|
|
+ {__symb, {__rm, __rl, __rr}, NULL, false, \
|
|
|
+ false, verb_##__monad, verb_##__dyad}
|
|
|
#define DEFVERBD(__symb, __rm, __rl, __rr, __monad, __dyad) \
|
|
|
- {__symb ".", {__rm, __rl, __rr}, NULL, false, false, verb_##__monad, verb_##__dyad}
|
|
|
+ {__symb ".", {__rm, __rl, __rr}, NULL, false, \
|
|
|
+ false, verb_##__monad, verb_##__dyad}
|
|
|
#define DEFVERBC(__symb, __rm, __rl, __rr, __monad, __dyad) \
|
|
|
- {__symb ":", {__rm, __rl, __rr}, NULL, false, false, verb_##__monad, verb_##__dyad}
|
|
|
-
|
|
|
-verb_t VERBS[] = {
|
|
|
- DEFVERB(":", 0, 0, 0, const, bind),
|
|
|
- DEFVERBC(":", 0, 0, 0, udf1, obverse),
|
|
|
- DEFVERB("+", 0, X, X, flip, plus),
|
|
|
- DEFVERBD("+", X, X, X, fibonacci, gcd),
|
|
|
- DEFVERBC("+", X, X, X, sin, combine),
|
|
|
- DEFVERB("-", X, X, X, negate, minus),
|
|
|
- DEFVERBD("-", X, X, X, atan, atan2),
|
|
|
- DEFVERB("*", 0, X, X, first, times),
|
|
|
- DEFVERBD("*", X, X, X, factorial, lcm),
|
|
|
- DEFVERBC("*", X, X, 0, double, replicate),
|
|
|
- DEFVERB("%", X, X, X, reciprocal, divide),
|
|
|
- DEFVERBD("%", X, X, X, sqrt, root),
|
|
|
- DEFVERBC("%", X, X, X, halve, idivide),
|
|
|
- DEFVERB("!", X, X, X, enum, mod),
|
|
|
- DEFVERBD("!", X, X, X, iota, range),
|
|
|
- DEFVERBC("!", 0, X, 0, odometer, chunks),
|
|
|
- DEFVERB("^", X, X, X, exp, power),
|
|
|
- DEFVERBD("^", X, X, X, nlog, log),
|
|
|
- DEFVERB("=", 0, X, X, permute, equals),
|
|
|
- DEFVERBD("=", 0, 0, 0, occurences, mask),
|
|
|
- DEFVERBC("=", 0, 0, 0, classify, equals),
|
|
|
- DEFVERB("~", X, X, X, not, not_equals),
|
|
|
- DEFVERBD("~", X, 0, 0, sign, insert),
|
|
|
- DEFVERBC("~", 0, 0, 0, not, not_equals),
|
|
|
- DEFVERB("<", X, X, X, pred, less),
|
|
|
- DEFVERBD("<", X, X, X, floor, lesseq),
|
|
|
- DEFVERBC("<", 0, X, 0, gradedown, nudge_left),
|
|
|
- DEFVERB(">", X, X, X, succ, greater),
|
|
|
- DEFVERBD(">", X, X, X, ceil, greatereq),
|
|
|
- DEFVERBC(">", 0, X, 0, gradeup, nudge_right),
|
|
|
- DEFVERB(",", 0, 0, 0, enlist, join),
|
|
|
- DEFVERBD(",", X, 0, 0, enlist, enpair),
|
|
|
- DEFVERB("#", 0, X, 0, count, take),
|
|
|
- DEFVERBD("#", 0, 0, 0, where, copy),
|
|
|
- DEFVERBC("#", 0, 0, 0, group, buckets),
|
|
|
- DEFVERB("_", 0, X, 0, nub, drop),
|
|
|
- DEFVERBD("_", 0, X, 0, unbits, unbase),
|
|
|
- DEFVERBC("_", X, X, X, bits, base),
|
|
|
- DEFVERB("?", 0, 0, 0, unique, find),
|
|
|
- DEFVERB("&", 0, X, X, flatten, minand),
|
|
|
- DEFVERB("|", 0, X, X, reverse, maxor),
|
|
|
- DEFVERBD("|", X, X, 0, round, rotate),
|
|
|
- DEFVERBC("|", 0, X, 0, depth, windows),
|
|
|
- DEFVERB("@", X, 0, X, abs, at),
|
|
|
- DEFVERBD("@", 0, 0, 0, shuffle, member),
|
|
|
- DEFVERB("{", 0, 0, 0, head, bin),
|
|
|
- DEFVERBD("{", 0, 0, 0, tail, cut),
|
|
|
- DEFVERBC("{", 0, X, X, prefixes, shl),
|
|
|
- DEFVERB("}", 0, X, X, behead, xor),
|
|
|
- DEFVERBD("}", 0, 0, 0, curtail, band),
|
|
|
- DEFVERBC("}", 0, X, X, suffixes, shr),
|
|
|
- DEFVERB("[", X, 0, 0, factors, left),
|
|
|
- DEFVERBD("[", X, X, X, bnot, bor),
|
|
|
- DEFVERBC("[", X, X, 0, primes, parts),
|
|
|
- DEFVERB("]", 0, 0, 0, same, right),
|
|
|
- DEFVERBD("]", 0, X, X, sort, outof),
|
|
|
- DEFVERBC("]", 0, 0, 0, unsort, explode),
|
|
|
- DEFVERBD("`", 0, 0, 0, symbol, apply1),
|
|
|
- DEFVERBC("`", 0, 0, 0, square, apply2),
|
|
|
- DEFVERB("$", 0, 0, 0, shape, reshape),
|
|
|
- DEFVERBD("$", 0, 0, 0, repr, format),
|
|
|
- DEFVERBC("$", X, 0, 0, eye, implode),
|
|
|
-
|
|
|
- DEFVERBD("p", 0, 0, 0, print, udf2),
|
|
|
- DEFVERBD("P", 0, 0, 0, println, udf2),
|
|
|
- DEFVERBD("f", 0, 0, 0, selfref1, selfref2),
|
|
|
- DEFVERBD("F", 0, 0, 0, read, write),
|
|
|
- DEFVERBD("r", 0, X, X, deal, roll),
|
|
|
- DEFVERBD("t", 0, 0, 0, type, cast),
|
|
|
- DEFVERBD("E", 0, 0, 0, exit, udf2),
|
|
|
- DEFVERBD("y", 0, 0, 0, system, system2),
|
|
|
- DEFVERBD("e", 0, 0, 0, eval, udf2),
|
|
|
- DEFVERBD("i", 0, 0, 0, import, udf2)
|
|
|
-};
|
|
|
+ {__symb ":", {__rm, __rl, __rr}, NULL, false, \
|
|
|
+ false, verb_##__monad, verb_##__dyad}
|
|
|
+
|
|
|
+verb_t VERBS[] = {DEFVERB(":", 0, 0, 0, const, bind),
|
|
|
+ DEFVERBC(":", 0, 0, 0, udf1, obverse),
|
|
|
+ DEFVERB("+", 0, X, X, flip, plus),
|
|
|
+ DEFVERBD("+", X, X, X, fibonacci, gcd),
|
|
|
+ DEFVERBC("+", X, X, X, sin, combine),
|
|
|
+ DEFVERB("-", X, X, X, negate, minus),
|
|
|
+ DEFVERBD("-", X, X, X, atan, atan2),
|
|
|
+ DEFVERB("*", 0, X, X, first, times),
|
|
|
+ DEFVERBD("*", X, X, X, factorial, lcm),
|
|
|
+ DEFVERBC("*", X, X, 0, double, replicate),
|
|
|
+ DEFVERB("%", X, X, X, reciprocal, divide),
|
|
|
+ DEFVERBD("%", X, X, X, sqrt, root),
|
|
|
+ DEFVERBC("%", X, X, X, halve, idivide),
|
|
|
+ DEFVERB("!", X, X, X, enum, mod),
|
|
|
+ DEFVERBD("!", X, X, X, iota, range),
|
|
|
+ DEFVERBC("!", 0, X, 0, odometer, chunks),
|
|
|
+ DEFVERB("^", X, X, X, exp, power),
|
|
|
+ DEFVERBD("^", X, X, X, nlog, log),
|
|
|
+ DEFVERB("=", 0, X, X, permute, equals),
|
|
|
+ DEFVERBD("=", 0, 0, 0, occurences, mask),
|
|
|
+ DEFVERBC("=", 0, 0, 0, classify, equals),
|
|
|
+ DEFVERB("~", X, X, X, not, not_equals),
|
|
|
+ DEFVERBD("~", X, 0, 0, sign, insert),
|
|
|
+ DEFVERBC("~", 0, 0, 0, not, not_equals),
|
|
|
+ DEFVERB("<", X, X, X, pred, less),
|
|
|
+ DEFVERBD("<", X, X, X, floor, lesseq),
|
|
|
+ DEFVERBC("<", 0, X, 0, gradedown, nudge_left),
|
|
|
+ DEFVERB(">", X, X, X, succ, greater),
|
|
|
+ DEFVERBD(">", X, X, X, ceil, greatereq),
|
|
|
+ DEFVERBC(">", 0, X, 0, gradeup, nudge_right),
|
|
|
+ DEFVERB(",", 0, 0, 0, enlist, join),
|
|
|
+ DEFVERBD(",", X, 0, 0, enlist, enpair),
|
|
|
+ DEFVERB("#", 0, X, 0, count, take),
|
|
|
+ DEFVERBD("#", 0, 0, 0, where, copy),
|
|
|
+ DEFVERBC("#", 0, 0, 0, group, buckets),
|
|
|
+ DEFVERB("_", 0, X, 0, nub, drop),
|
|
|
+ DEFVERBD("_", 0, X, 0, unbits, unbase),
|
|
|
+ DEFVERBC("_", X, X, X, bits, base),
|
|
|
+ DEFVERB("?", 0, 0, 0, unique, find),
|
|
|
+ DEFVERB("&", 0, X, X, flatten, minand),
|
|
|
+ DEFVERB("|", 0, X, X, reverse, maxor),
|
|
|
+ DEFVERBD("|", X, X, 0, round, rotate),
|
|
|
+ DEFVERBC("|", 0, X, 0, depth, windows),
|
|
|
+ DEFVERB("@", X, 0, X, abs, at),
|
|
|
+ DEFVERBD("@", 0, 0, 0, shuffle, member),
|
|
|
+ DEFVERB("{", 0, 0, 0, head, bin),
|
|
|
+ DEFVERBD("{", 0, 0, 0, tail, cut),
|
|
|
+ DEFVERBC("{", 0, X, X, prefixes, shl),
|
|
|
+ DEFVERB("}", 0, X, X, behead, xor),
|
|
|
+ DEFVERBD("}", 0, 0, 0, curtail, band),
|
|
|
+ DEFVERBC("}", 0, X, X, suffixes, shr),
|
|
|
+ DEFVERB("[", X, 0, 0, factors, left),
|
|
|
+ DEFVERBD("[", X, X, X, bnot, bor),
|
|
|
+ DEFVERBC("[", X, X, 0, primes, parts),
|
|
|
+ DEFVERB("]", 0, 0, 0, same, right),
|
|
|
+ DEFVERBD("]", 0, X, X, sort, outof),
|
|
|
+ DEFVERBC("]", 0, 0, 0, unsort, explode),
|
|
|
+ DEFVERBD("`", 0, 0, 0, symbol, apply1),
|
|
|
+ DEFVERBC("`", 0, 0, 0, square, apply2),
|
|
|
+ DEFVERB("$", 0, 0, 0, shape, reshape),
|
|
|
+ DEFVERBD("$", 0, 0, 0, repr, format),
|
|
|
+ DEFVERBC("$", X, 0, 0, eye, implode),
|
|
|
+
|
|
|
+ DEFVERBD("p", 0, 0, 0, print, udf2),
|
|
|
+ DEFVERBD("P", 0, 0, 0, println, udf2),
|
|
|
+ DEFVERBD("f", 0, 0, 0, selfref1, selfref2),
|
|
|
+ DEFVERBD("F", 0, 0, 0, read, write),
|
|
|
+ DEFVERBD("r", 0, X, X, deal, roll),
|
|
|
+ DEFVERBD("t", 0, 0, 0, type, cast),
|
|
|
+ DEFVERBD("E", 0, 0, 0, exit, udf2),
|
|
|
+ DEFVERBD("y", 0, 0, 0, system, system2),
|
|
|
+ DEFVERBD("e", 0, 0, 0, eval, udf2),
|
|
|
+ DEFVERBD("i", 0, 0, 0, import, udf2)};
|
|
|
|
|
|
value_t *_adverb_fold_monad(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
if (x->tag != ARRAY || list_empty(x->val.array))
|
|
@@ -5452,7 +5479,7 @@ value_t *_adverb_filter_monad(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
}
|
|
|
|
|
|
value_t *_adverb_filter_dyad(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
- value_t *y) {
|
|
|
+ value_t *y) {
|
|
|
return state->udf;
|
|
|
}
|
|
|
|
|
@@ -5478,7 +5505,8 @@ value_t *_adverb_span_monad(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
list_push(r, value_new_array(p));
|
|
|
|
|
|
p = list_new();
|
|
|
- } else list_push(p, t->value);
|
|
|
+ } else
|
|
|
+ list_push(p, t->value);
|
|
|
|
|
|
t = t->next;
|
|
|
}
|
|
@@ -5497,7 +5525,7 @@ value_t *_adverb_span_dyad(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
verb_t *v = _v->val.verb;
|
|
|
value_t *r = verb_windows(state, NULL, x, y);
|
|
|
|
|
|
- return each_rank(state, v, r, 0, 1);
|
|
|
+ return each_rank(state, v, r, 0, 1);
|
|
|
}
|
|
|
|
|
|
value_t *_adverb_inverse_monad(interpreter_t *state, verb_t *self, value_t *x) {
|
|
@@ -5717,8 +5745,7 @@ value_t *_conjunction_monaddyad_dyad(interpreter_t *state, verb_t *self,
|
|
|
v->val.verb->rank[2]);
|
|
|
}
|
|
|
|
|
|
-value_t *_conjunction_if_monad(interpreter_t *state, verb_t *self,
|
|
|
- value_t *x) {
|
|
|
+value_t *_conjunction_if_monad(interpreter_t *state, verb_t *self, value_t *x) {
|
|
|
value_t *v1 = self->bonds->value;
|
|
|
value_t *v2 = self->bonds->next->value;
|
|
|
|
|
@@ -5733,8 +5760,8 @@ value_t *_conjunction_if_monad(interpreter_t *state, verb_t *self,
|
|
|
return apply_monad(state, v1, x);
|
|
|
}
|
|
|
|
|
|
-value_t *_conjunction_if_dyad(interpreter_t *state, verb_t *self,
|
|
|
- value_t *x, value_t *y) {
|
|
|
+value_t *_conjunction_if_dyad(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
value_t *v1 = self->bonds->value;
|
|
|
value_t *v2 = self->bonds->next->value;
|
|
|
|
|
@@ -5750,7 +5777,7 @@ value_t *_conjunction_if_dyad(interpreter_t *state, verb_t *self,
|
|
|
}
|
|
|
|
|
|
value_t *_conjunction_under_monad(interpreter_t *state, verb_t *self,
|
|
|
- value_t *x) {
|
|
|
+ value_t *x) {
|
|
|
value_t *v1 = self->bonds->value;
|
|
|
value_t *v2 = self->bonds->next->value;
|
|
|
|
|
@@ -5767,8 +5794,8 @@ value_t *_conjunction_under_monad(interpreter_t *state, verb_t *self,
|
|
|
return each_rank(state, iv, v, 0, iv->rank[0]);
|
|
|
}
|
|
|
|
|
|
-value_t *_conjunction_under_dyad(interpreter_t *state, verb_t *self,
|
|
|
- value_t *x, value_t *y) {
|
|
|
+value_t *_conjunction_under_dyad(interpreter_t *state, verb_t *self, value_t *x,
|
|
|
+ value_t *y) {
|
|
|
value_t *v1 = self->bonds->value;
|
|
|
value_t *v2 = self->bonds->next->value;
|
|
|
|
|
@@ -5816,18 +5843,16 @@ CONJUNCTION(monaddyad, ";:");
|
|
|
CONJUNCTION(if, "&:");
|
|
|
CONJUNCTION(under, "^:");
|
|
|
|
|
|
-adverb_t CONJUNCTIONS[] = {{";", NULL, conjunction_bond},
|
|
|
- {"?.", NULL, conjunction_pick},
|
|
|
- {"?:", NULL, conjunction_while},
|
|
|
- {"\":", NULL, conjunction_rank},
|
|
|
- {";:", NULL, conjunction_monaddyad},
|
|
|
- {"&:", NULL, conjunction_if},
|
|
|
- {"^:", NULL, conjunction_under}};
|
|
|
+adverb_t CONJUNCTIONS[] = {
|
|
|
+ {";", NULL, conjunction_bond}, {"?.", NULL, conjunction_pick},
|
|
|
+ {"?:", NULL, conjunction_while}, {"\":", NULL, conjunction_rank},
|
|
|
+ {";:", NULL, conjunction_monaddyad}, {"&:", NULL, conjunction_if},
|
|
|
+ {"^:", NULL, conjunction_under}};
|
|
|
|
|
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
|
|
#define FINDER(kind, rname, table) \
|
|
|
- kind *find_##rname (char *s) { \
|
|
|
+ kind *find_##rname(char *s) { \
|
|
|
for (size_t i = 0; i < countof(table); i++) { \
|
|
|
if (strcmp(table[i].name, s) == 0) \
|
|
|
return &table[i]; \
|
|
@@ -6252,7 +6277,8 @@ bool is_apply(node_t *n) {
|
|
|
}
|
|
|
|
|
|
bool is_obverse(node_t *n) {
|
|
|
- return n->tag == N_LITERAL && n->v->tag == VERB && strcmp(n->v->val.verb->name, "::") == 0;
|
|
|
+ return n->tag == N_LITERAL && n->v->tag == VERB &&
|
|
|
+ strcmp(n->v->val.verb->name, "::") == 0;
|
|
|
}
|
|
|
|
|
|
node_t *parser_parse_expr(parser_t *parser) {
|
|
@@ -6300,7 +6326,8 @@ node_t *parser_parse_expr(parser_t *parser) {
|
|
|
if (len < 2)
|
|
|
break;
|
|
|
|
|
|
- if (len >= 3 && is_apply(list_index(ns, -2)) || is_obverse(list_index(ns, -2))) {
|
|
|
+ if (len >= 3 && is_apply(list_index(ns, -2)) ||
|
|
|
+ is_obverse(list_index(ns, -2))) {
|
|
|
r = list_pop(ns);
|
|
|
m = list_pop(ns);
|
|
|
l = list_pop(ns);
|
|
@@ -6480,7 +6507,7 @@ int main(int argc, char **argv) {
|
|
|
table_set(state->env, "JKV", value_new_array(vs));
|
|
|
table_set(state->env, "E", value_new_number(exp(1)));
|
|
|
table_set(state->env, "pi", value_new_number(M_PI));
|
|
|
- table_set(state->env, "tau", value_new_number(M_PI*2));
|
|
|
+ table_set(state->env, "tau", value_new_number(M_PI * 2));
|
|
|
table_set(state->env, "nan", _NAN);
|
|
|
table_set(state->env, "inf", INF);
|
|
|
table_set(state->env, "nil", state->nil);
|
|
@@ -6540,7 +6567,8 @@ int main(int argc, char **argv) {
|
|
|
setjmp(interactive_checkpoint);
|
|
|
|
|
|
if (s) {
|
|
|
- GC_FREE(s); s = NULL;
|
|
|
+ GC_FREE(s);
|
|
|
+ s = NULL;
|
|
|
}
|
|
|
|
|
|
for (;;) {
|
|
@@ -6563,40 +6591,34 @@ int main(int argc, char **argv) {
|
|
|
printf("%s", HELP);
|
|
|
|
|
|
continue;
|
|
|
- }
|
|
|
- else if (strcmp(line, "\\0\n") == 0) {
|
|
|
+ } else if (strcmp(line, "\\0\n") == 0) {
|
|
|
printf("%s", SHELP);
|
|
|
|
|
|
continue;
|
|
|
- }
|
|
|
- else if (strcmp(line, "\\+\n") == 0) {
|
|
|
+ } else if (strcmp(line, "\\+\n") == 0) {
|
|
|
printf("%s", VHELP);
|
|
|
|
|
|
continue;
|
|
|
- }
|
|
|
- else if (strcmp(line, "\\a\n") == 0) {
|
|
|
+ } else if (strcmp(line, "\\a\n") == 0) {
|
|
|
printf("%s", V2HELP);
|
|
|
|
|
|
continue;
|
|
|
- }
|
|
|
- else if (strcmp(line, "\\\"\n") == 0) {
|
|
|
+ } else if (strcmp(line, "\\\"\n") == 0) {
|
|
|
printf("%s", AHELP);
|
|
|
|
|
|
continue;
|
|
|
- }
|
|
|
- else if (strcmp(line, "\\;\n") == 0) {
|
|
|
+ } else if (strcmp(line, "\\;\n") == 0) {
|
|
|
printf("%s", CHELP);
|
|
|
|
|
|
continue;
|
|
|
- }
|
|
|
- else if (strcmp(line, "\\-:\n") == 0) {
|
|
|
+ } else if (strcmp(line, "\\-:\n") == 0) {
|
|
|
printf("%s", IHELP);
|
|
|
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- while (strlen(line) > 2 && strcmp(line+strlen(line)-3, "..\n") == 0) {
|
|
|
+ while (strlen(line) > 2 && strcmp(line + strlen(line) - 3, "..\n") == 0) {
|
|
|
line[strlen(line) - 3] = 0;
|
|
|
|
|
|
buffer_append_str(buffer, line);
|
|
@@ -6614,7 +6636,8 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
value_t *v = interpreter_run(state, s);
|
|
|
|
|
|
- GC_FREE(s); s = NULL;
|
|
|
+ GC_FREE(s);
|
|
|
+ s = NULL;
|
|
|
|
|
|
if (v->tag != NIL) {
|
|
|
table_set(state->env, "it", v);
|