Commit 074e8d03 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai

avoid temporary variables in tr setters when possible (try to topological sort them)

parent 5af7ced6
......@@ -16,6 +16,7 @@ import Sapl.SaplTokenizer, Sapl.SaplParser, Sapl.Target.Flavour, Sapl.Optimizati
import Sapl.Transform.Let
import Sapl.Target.JS.Lifting
import Sapl.Transform.AddSelectors
import Sapl.Transform.TailRecursion
import StdDebug
from Data.List import elem_by, partition
......@@ -582,10 +583,15 @@ where
builtin = 'DM'.get (unpackVar name) s.cs_builtins
make_tr_app args s a
# (tr_function_args, args) = unzip (filter (not o isSame) (zip2 tr_function_args args))
= a <++ "var " <++ mta_1 tr_function_args args 0 s <++ ";"
<++ mta_2 tr_function_args 0 s <++ "continue;"
# setters = filter (not o isSame) (zip2 tr_function_args args)
= case sortSetters setters of
Nothing
# (tr_function_args, args) = unzip setters
= a <++ "var " <++ mta_1 tr_function_args args 0 s <++ ";"
<++ mta_2 tr_function_args 0 s <++ "continue;"
// Reverse topological order is probably safe
(Just ordered) = a <++ gen_setters (reverse ordered) s <++ "continue;"
where
mta_1 [TypedVar (StrictVar _ _) _:fargs] [aa:aargs] i s a
# a = if (i>0) (a <++ ",") a
......@@ -602,6 +608,12 @@ where
isSame (TypedVar var1 _, SVar var2) = unpackVar var1 == unpackVar var2
isSame _ = False
gen_setters [(TypedVar (StrictVar vn _) _,expr):ss] s a
= a <++ escapeName s.cs_prefix vn <++ "=" <++ forceTermCoder expr s <++ ";" <++ gen_setters ss s
gen_setters [(TypedVar (NormalVar vn _) _,expr):ss] s a
= a <++ escapeName s.cs_prefix vn <++ "=" <++ termCoder expr s <++ ";" <++ gen_setters ss s
gen_setters [] s a = a
forceTermCoder (SApplication sel=:(SSelect _ _ _) args) s a
= a <++ "Sapl.fapp(" <++ forceTermCoder sel s <++ ",["
<++ termArrayCoder args "," s
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment