Return expression eliminated

This commit is contained in:
Dmitry Boulytchev 2021-01-31 19:11:03 +03:00
parent 7eb3e223b8
commit 297139c72a
114 changed files with 37 additions and 1018 deletions

View file

@ -305,30 +305,30 @@ public fun emptyMemo () {
}
public fun lookupMemo (mm@[p, m], v) {
case p of
#fun -> if p (v) then return v fi
| _ -> skip
esac;
case v of
#unboxed -> v
| _ ->
case findMap (m, v) of
Some (w) -> w
| None ->
case v of
#string -> mm[1] := addMap (m, v, v); v
| _ ->
local vc = clone (v), i = case vc of #fun -> 1 | _ -> 0 esac;
for skip, i < v.length, i := i + 1 do
local vci = lookupMemo (mm, vc [i]);
vc [i] := vci
od;
mm [1] := addMap (m, vc, vc);
vc
esac
esac
esac
fun (x) {
case p of
#fun -> if p (v) then v else x () fi
| _ -> x ()
esac}
(fun () {case v of
#unboxed -> v
| _ ->
case findMap (m, v) of
Some (w) -> w
| None ->
case v of
#string -> mm[1] := addMap (m, v, v); v
| _ ->
local vc = clone (v), i = case vc of #fun -> 1 | _ -> 0 esac;
for skip, i < v.length, i := i + 1 do
local vci = lookupMemo (mm, vc [i]);
vc [i] := vci
od;
mm [1] := addMap (m, vc, vc);
vc
esac
esac
esac})
}
-- Maps of hashed pointers

View file

@ -1,5 +1,5 @@
fun f (x) {
return fun (y) {return x + y}
fun (y) {x + y}
}
write (compare (1, 2));

View file

@ -1,10 +1,10 @@
fun insert (tree, value) {
case tree of
Empty -> return Node (value, Empty, Empty)
Empty -> Node (value, Empty, Empty)
| Node (x, left, right) ->
if x > value
then return Node (x, insert (left, value), right)
else return Node (x, left, insert (right, value))
then Node (x, insert (left, value), right)
else Node (x, left, insert (right, value))
fi
esac
}

View file

@ -2,18 +2,18 @@ fun collect_ints_acc (v, tail) {
local i;
case v of
a@#unboxed -> return Cons (a, tail)
| #string -> return tail
a@#unboxed -> Cons (a, tail)
| #string -> tail
| _ ->
for i := 0, i < v.length, i := i + 1 do
tail := collect_ints_acc (v[i], tail)
od;
return tail
tail
esac
}
fun collect_ints (v) {
return collect_ints_acc (v, Nil)
collect_ints_acc (v, Nil)
}
case 1 of

View file

@ -1,12 +1,12 @@
fun hd (l) {
case l of
h : _ -> return h
h : _ -> h
esac
}
fun tl (l) {
case l of
_ : t -> return t
_ : t -> t
esac
}