Intermediate; pattern matching in x86

This commit is contained in:
Dmitry Boulytchev 2018-05-16 09:24:40 +03:00
parent 34767b9dcb
commit 1f1ef2ce57
7 changed files with 184 additions and 303 deletions

View file

@ -7,7 +7,7 @@ RC=../src/rc.opt
check: $(TESTS)
$(TESTS): %: %.expr
#@$(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log
@$(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log
cat $@.input | $(RC) -i $< > $@.log && diff $@.log orig/$@.log
cat $@.input | $(RC) -s $< > $@.log && diff $@.log orig/$@.log

View file

@ -1,23 +0,0 @@
fun append (x, y) {
case x of
`nil -> return y
| `cons (h, t) -> return `cons (h, append (t, y))
esac
}
fun printList (x) {
case x of
`nil -> skip
| `cons (h, t) -> write (h); printList (t)
esac
}
n := read ();
x := `cons (1, `cons (2, `nil));
y := `cons (3, `cons (4, `nil));
printList (x);
printList (y);
printList (append (x, y));
printList (append (y, x))

View file

@ -1,31 +0,0 @@
fun insert (t, x) {
case t of
`leaf -> return `node (x, `leaf, `leaf)
| `node (y, l, r) -> if x > y
then return `node (y, insert (l, x), r)
else return `node (y, l, insert (r, x))
fi
esac
}
fun find (t, x) {
case t of
`leaf -> return 0
| `node (y, l, r) -> if x == y then return 1
elif x > y then return find (l, x)
else return find (r, x)
fi
esac
}
n := read ();
t := insert (insert (insert (insert (`leaf, 5), 4), 6), 3);
write (find (t, 5));
write (find (t, 4));
write (find (t, 6));
write (find (t, 3));
write (find (t, 2));
write (find (t, 1))