ayecue / greybel-js

GreyScript transpiler/minifier/interpreter for Grey Hack written in JS.
http://editor.greyscript.org
MIT License
28 stars 7 forks source link

Interpretor improperly evaluates "isa" in unbuilt files using "import" #222

Closed smiley8D closed 1 month ago

smiley8D commented 2 months ago

The interpreter does not appear to correctly evaluate "isa" for different imports for the same library.

lib.src

Lib = {}

module.exports = Lib

mid.src

#import Lib from lib.src

liba = new Lib

module.exports = liba

main.src

#import Lib from lib.src
#import liba from mid.src

print (liba isa Lib)

When main.src is is executed by the interpreter, the output is:

0

If main.src is built first and then run (uglify, dlo):

C={}
D={}
E=function(r)
if (not C.hasIndex(r)) then
exit("Module "+r+" cannot be found...")
end if
G=@C[r]
return @G(r).exports
end function
C["B"]=function(r)
G={}
if (D.hasIndex(r)) then
G=D[r]
end if
if (not G.hasIndex("exports")) then
I={}
G.exports=I
end if
D[r]=G
return D[r]
end function
C["C"]=function(r)
G={}
if (D.hasIndex(r)) then
G=D[r]
end if
if (not G.hasIndex("exports")) then
I=E("B")
J=new I
G.exports=J
end if
D[r]=G
return D[r]
end function
I=E("B")
J=E("C")
print((J isa I))

The output is:

1

My uneducated guess is the interpreter is not recognizing that the imports of Lib in main.src and mid.src refer to the same class, so isa evaluates to false. This was all done with the visual studio code extension.

ayecue commented 1 month ago

Hey,

thanks for reporting.

Seems like there is an issue with the interpreter when it comes to generating bytecode for an import statement. I'll look into the issue.

ayecue commented 1 month ago

Just released a new version for greybel-js, greybel-vs and miniscript-vs. Should fix the issue for all of those. In case you're still expiring the same problems feel free to reopen this issue.

smiley8D commented 1 month ago

I confirm that the interpreter is behaving as expected with v2.5.1 both in the above example and in my project where I originally noticed the issue. Thanks!