git @ Cat's Eye Technologies Tamsin / 59d4bc2
Refactor libtamsin starting with small stuff. Cat's Eye Technologies 10 years ago
2 changed file(s) with 9 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
128128 assert(lhs->subterms == NULL);
129129 assert(rhs->subterms == NULL);
130130
131 if (lhs->storing != NULL) {
132 lhs = lhs->storing;
133 }
134 if (rhs->storing != NULL) {
135 rhs = rhs->storing;
136 }
137
138131 new_size = lhs->size + rhs->size;
139132 new_atom = malloc(new_size);
140133 memcpy(new_atom, lhs->atom, lhs->size);
152145 struct term *term_flatten(const struct term *t) {
153146 struct term_list *tl;
154147
155 if (t->storing != NULL) { /* it's a variable; get its value */
156 return term_flatten(t->storing);
157 } else if (t->subterms == NULL) { /* it's an atom */
148 if (t->subterms == NULL) { /* it's an atom */
158149 return term_new(t->atom, t->size);
159150 } else { /* it's a constructor */
160151 struct term *n;
265256 struct term *term_repr(const struct term *t) {
266257 struct term_list *tl;
267258
268 if (t->storing != NULL) { /* it's a variable; get its value */
269 return term_repr(t->storing);
270 } else if (t->subterms == NULL) { /* it's an atom */
259 if (t->subterms == NULL) { /* it's an atom */
271260 return term_escape_atom(t);
272261 } else { /* it's a constructor */
273262 struct term *n;
66 GLOB="eg/*.tamsin lib/*.tamsin mains/*.tamsin"
77
88 mkdir -p tmp
9 make all || exit 1
109
1110 if [ x$1 = 'x-f' ]; then
1211 shift
7978 fi
8079
8180 if [ $MODE = "compiled" ]; then
81 make c_src/libtamsin.a || exit 1
8282 echo "*** Compiling $SRC (with $LIBS)"
8383 echo "*** and testing it against '$CMD'..."
8484 bin/tamsin compile $LIBS $SRC > tmp/foo.c && \
110110 exit 0
111111 }
112112
113 if [ x$1 = xcompiler ]; then
113 if [ x$1 = xinterpreter -o x$1 = xi ]; then
114 echo "*** Testing Python interpreter..."
115 falderal $VERBOSE --substring-error fixture/tamsin.py.markdown $FILES
116 elif [ x$1 = xcompiler ]; then
117 make c_src/libtamsin.a || exit 1
114118 echo "*** Testing compiler..."
115119 falderal $VERBOSE --substring-error fixture/compiler.py.markdown $FILES
116 elif [ x$1 = xinterpreter -o x$1 = xi ]; then
117 echo "*** Testing Python interpreter..."
118 falderal $VERBOSE --substring-error fixture/tamsin.py.markdown $FILES
119120 elif [ x$1 = xgrammar ]; then
120121 test_it $MODE "mains/grammar.tamsin" \
121122 "lib/tamsin_scanner.tamsin" \
152153 echo "*** Testing Bootstrapped Tamsin-in-Tamsin compiler..."
153154 falderal $VERBOSE --substring-error fixture/bootstrapped.markdown $FILES
154155 elif [ x$1 = xmicro ]; then
156 make bin/micro-tamsin || exit 1
155157 echo "*** Testing Micro-Tamsin interpreter..."
156158 FILES="doc/Micro-Tamsin.markdown"
157159 falderal $VERBOSE --substring-error fixture/micro-tamsin.markdown $FILES