Verified Commit b1a71d3b authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Fix dynamic returns getting precedence over lexical ones

parent 573d66cd
......@@ -181,7 +181,7 @@
`((and ,_ps_err (eql ',tag
(getprop ,_ps_err :__ps_block_tag)))
(return-from ,tag
(values-list (getprop ,_ps_err :__ps_values))))))
(getprop ,_ps_err :__ps_value)))))
`(ps-js:block
(ps-js:try
,body
......@@ -225,33 +225,39 @@
,firstval))))
(defun return-exp (tag &optional (value nil value?))
(acond
((eql tag *current-block-tag*)
(compile-statement
`(progn
,@(when (and (not returning-values?) clear-multiple-values?)
'((setf __PS_MV_REG '())))
,@(when value? (list value))
(break ,tag))))
((assoc tag *dynamic-return-tags*)
(setf (cdr it) t)
(ps-compile
`(progn
,@(when (and (not returning-values?) clear-multiple-values?)
'((setf __PS_MV_REG '())))
(throw (create
:__ps_block_tag ',tag
:__ps_values (multiple-value-list ,value))))))
(t
(unless (or (eql '%function tag)
(member tag *function-block-names*))
(warn "Returning from unknown block ~A" tag))
(let ((X (when value? (list (compile-expression value)))))
(if (and (not returning-values?) clear-multiple-values?)
`(ps-js:block
(ps-js:= __PS_MV_REG [])
(ps-js:return ,@X))
`(ps-js:return ,@X))))))
(flet ((lexical-return ()
(let ((X (when value? (list (compile-expression value)))))
(if (and (not returning-values?) clear-multiple-values?)
`(ps-js:block
(ps-js:= __PS_MV_REG [])
(ps-js:return ,@X))
`(ps-js:return ,@X)))))
(acond
((eql tag *current-block-tag*)
(compile-statement
`(progn
,@(when (and (not returning-values?) clear-multiple-values?)
'((setf __PS_MV_REG '())))
,@(when value? (list value))
(break ,tag))))
((or (eql '%function tag)
(member tag *function-block-names*))
(lexical-return))
((assoc tag *dynamic-return-tags*)
(setf (cdr it) t)
(ps-compile
`(progn
,@(when (and (not returning-values?) clear-multiple-values?)
'((setf __PS_MV_REG '())))
(throw (create
:__ps_block_tag ',tag
:__ps_value ,value)))))
(t
(warn "Returning from unknown block ~A" tag)
(lexical-return)))))
(defun try-expressionizing-if? (exp &optional (score 0)) ;; poor man's codewalker
"Heuristic that tries not to expressionize deeply nested if expressions."
......
This diff is collapsed.
......@@ -92,6 +92,7 @@ foo.my_library_foo;")
(defun parenscript.tests.obfuscate-me::libfun2 (a b parenscript.tests.obfuscate-me::foo)
(+ a (parenscript.tests.my-library::library-function b parenscript.tests.obfuscate-me::foo)))
"function mjcgvo3(a, b, gpp) {
__PS_MV_REG = [];
return a + my_library_libraryFunction(b, gpp);
};")
......@@ -105,6 +106,7 @@ foo.my_library_foo;")
(parenscript.tests.obfuscate-me::libfun2 parenscript.tests.obfuscate-and-prefix::b a)
(parenscript.tests.my-library::library-function parenscript.tests.my-library::d parenscript.tests.obfuscate-and-prefix::b)))
"function __FOO___ygvo(a, __FOO___c, my_library_d) {
__PS_MV_REG = [];
return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
};")
......@@ -159,6 +161,7 @@ return !foo1 && foo1.prefix_bar + prefix_someOtherVar;
")
(ps-compile-stream s))
"function __FOO___ygvo(a, __FOO___c, my_library_d) {
__PS_MV_REG = [];
return a * mjcgvo3(__FOO___c, a) * my_library_libraryFunction(my_library_d, __FOO___c);
};
function interfaceFunction(prefix_baz) {
......
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