hguven / jaql

Automatically exported from code.google.com/p/jaql
0 stars 0 forks source link

Decompile bug for keywords shadowed by a variable #60

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Most of Jaql's keywords are soft in the sense that they can be shadowed by
a variable. The purpose of this feature is to be able to run old scripts
with new keywords. However, there are problems with decompilation. 

The following example illustrates the problem.

f = fn(x) x -> transform (1);

produces a function that takes an array and produces an array of the same
size with all elements being replaced by 1. Now suppose we define

transform = fn(x,y) "test";

This is valid because transform is a soft keyword. Running 

[1, 2, 3] -> transform (1)

produces "test" because the transform variable has precedence. (This is
OK.) Problems arise when decompiling f:

f;

gives

const( fn(x) (x -> transform (1)) )

This is incorrect because, when interpreted again, transform would be
treated as a variable instead of the keyword.

Original issue reported on code.google.com by Rainer.G...@gmx.de on 1 Oct 2009 at 10:48

GoogleCodeExporter commented 8 years ago
The proposed solution is to add a keyword marker similar to the variable 
markers used
in issue 61. The function f above would decompile to 

const( fn(x) (x -> #transform (1)) ).

The keyword marker will be added during decompile if and only if there is a 
global
variable with the same name as the keyword in scope. Local variables that 
coincides
with keyword names are tagged so that

explain ( transform=randomLong(), [ transform, transform ] );

gives

(
  transform#0 = system::randomLong(),
  [transform#0, transform#0]
);

Original comment by Rainer.G...@gmx.de on 15 Oct 2009 at 10:47

GoogleCodeExporter commented 8 years ago
Fixed in r396.

Original comment by Rainer.G...@gmx.de on 15 Oct 2009 at 10:52