Commit 9235eed0 authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Fixed bug where top-level defuns and defvars inside toplevel lets were being...

Fixed bug where top-level defuns and defvars inside toplevel lets were being wrapped in lambdas and not defined at the toplevel.
parent 83f4ea34
......@@ -450,9 +450,12 @@ Parenscript now implements implicit return, update your code! Things like (lambd
(setf ,@(mapcan (lambda (x) `(,(var x) ,(rename x)))
dynamic-bindings)))))
renamed-body))))
(ps-compile (if in-function-scope?
let-body
(with-lambda-scope let-body)))))))
(ps-compile (cond (in-function-scope? let-body)
((find-if (lambda (x)
(member x '(defun defvar defparameter)))
(flatten let-body))
let-body)
(t (with-lambda-scope let-body))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; iteration
......
......@@ -271,6 +271,18 @@
(return (1+ x)))
6)
(test-js-eval let-defun-toplevel
(progn (let ((foo 0))
(defun bar () foo))
(bar))
0)
(test-js-eval let-defvar-toplevel
(progn (let ((foo 0))
(defvar bar (1+ foo)))
bar)
1)
;;; broken
(test-js-eval equality-nary1
......
......@@ -578,22 +578,6 @@ return element.innerHTML = ['<TEXTAREA', disabled || !authorized ? [' DISABLED=\
(setf x (+ x "middle" "after"))
"x = x + 'middle' + 'after';")
(test-ps-js setf-side-effects
(progn
(let ((x 10))
(defun side-effect()
(setf x 4)
3)
(setf x (+ 2 (side-effect) x 5))))
"(function () {
var x = 10;
function sideEffect() {
x = 4;
return 3;
};
return x = 2 + sideEffect() + x + 5;
})();")
(test-ps-js method-call-op-form
(funcall (getprop (+ "" x) 'to-string))
"('' + x).toString();")
......@@ -3467,4 +3451,38 @@ for (var x = null, _js_arrvar2 = [5, 2, 3], _js_idx1 = 0; _js_idx1 < _js_arrvar2
break;
};
return loopResultVar3;
})();")
\ No newline at end of file
})();")
;;; broken
(test-ps-js let-defun-toplevel
(progn (let ((foo 0))
(defun bar () foo))
(bar))
"var bar_foo1 = 0;
function bar() {
return bar_foo1;
};
bar();")
(test-ps-js let-defvar-toplevel
(progn (let ((foo 0))
(defvar bar (1+ foo)))
bar)
"var bar_foo1 = 0;
var bar = bar_foo1 + 1;
bar;")
(test-ps-js setf-side-effects
(progn
(let ((x 10))
(defun side-effect()
(setf x 4)
3)
(setf x (+ 2 (side-effect) x 5))))
"var sideEffect_x1 = 10;
function sideEffect() {
sideEffect_x1 = 4;
return 3;
};
sideEffect_x1 = 2 + sideEffect() + x + 5;")
Supports Markdown
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