[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#11171: Incorrect ECMAScript compilation
From: |
Andy Wingo |
Subject: |
bug#11171: Incorrect ECMAScript compilation |
Date: |
Thu, 05 Jul 2012 21:04:03 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) |
On Wed 04 Apr 2012 18:07, Steve Jothen <address@hidden> writes:
> I was playing around with the ECMAScript implementation in 2.0.5, and
> found a bug when calling anonymous functions:
>
> ecmascript@(guile-user)> var foo = (function(x) { return x+1; })(1);
> $5 = 2
> ecmascript@(guile-user)> foo;
> ;;; <unknown-location>: warning: possibly unbound variable `foo'
> ERROR: In procedure #<procedure 8f4c140 ()>:
> ERROR: In procedure module-lookup: Unbound variable: foo
Very interesting bug, and interesting analysis as well.
> I did a bit of hacking and found out the problem occurs during the
> tree-il optimization step: Here's the tree-il code before
> optimization:
This is almost right. The real problem is actually in the
ecmascript->tree-il compiler, that it uses this crazy `return' primcall
that we never should have used. Primcalls are not supposed to affect
control flow!
The answer is to replace the use of `return' with prompt and abort.
It's a lose in the general case for speed, but a gain for correctness.
I also added some optimizations that are able to remove the prompt in
this particular case, so you can now:
> ,c var foo = (function(x) { return x+1; })(1);
[...]
Embedded program #{826}#:
0 (assert-nargs-ee/locals 0) ;; 0 args, 0 locals
2 (new-frame)
3 (toplevel-ref 7)
5 (mv-call 0 :L823) ;; MV -> 15
10 (drop)
11 (br :L824) ;; -> 18
15 (truncate-values 0 0)
18 (make-int8 2) ;; 2
20 (object-ref 8)
22 (define)
23 (void)
24 (return)
Here you see it inlined to var foo = 2.
Thanks for the interesting bug report, and sorry for the delay!
Andy
--
http://wingolog.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#11171: Incorrect ECMAScript compilation,
Andy Wingo <=