You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You must post issues only here. Questions, ideas must be posted in discussions.
GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.
Please answer the following before submitting your issue:
What version of GopherLua are you using? : v1.1.1
What version of Go are you using? : 1.22.2
What operating system and processor architecture are you using? : Ubuntu 22.04 x86_64
What did you do? :
functiongreaterThan(a, b)
returna>bendfunctionlessThan(a, b)
returna<bendfunctionbetweenViaOperators(val, a, b)
localresult=trueresult=resultand (val>aandval<b)
returnresultendfunctionbetweenViaFunctions(val, a, b)
localresult=trueresult=resultand (greaterThan(val, a) andlessThan(val, b))
returnresultendprint(betweenViaOperators(2, 3, 5))
print(betweenViaFunctions(2, 3, 5))
What did you expect to see? :
false
false
What did you see instead? :
false
true
It seems to happen because of some optimizations or something like that. In case of comparison via functions we have following bytecode for the betweenViaFunctions function:
Please pay attention for the 003 and 009 JMP instructions: they go to the 014 MOVE instruction, which is responisble for the result variable assignment. When JMP instructions are executed, the program counter points to the MOVE instruction, and then in the main loop (vm.go:30) the PC increments. After this operation the PC points to the 015 RETURN, that leads to the returning of wrong value.
For comparsion, there is the betweenViaOperators bytecode:
; function [2] definition (level 2)
; 0 upvalues, 3 params, 4 stacks
.local val ; 0
.local a ; 1
.local b ; 2
.local result ; 3
[001] LOADBOOL | 3, 1, 0; R(3) := (Bool)1; if (0) pc++ (line:11)
[002] TEST | 3, 3, 0; if not (R(3) <=> 0) then pc++ (line:12)
[003] JMP | 0, 6; pc+=6 (line:12)
[004] LT | 0, 1, 0; if ((RK(1) < RK(0)) ~= 0) then pc++ (line:12)
[005] JMP | 0, 2; pc+=2 (line:12)
[006] LT | 1, 0, 2; if ((RK(0) < RK(2)) ~= 1) then pc++ (line:12)
[007] JMP | 0, 1; pc+=1 (line:12)
[008] LOADBOOL | 3, 0, 1; R(3) := (Bool)0; if (1) pc++ (line:12)
[009] LOADBOOL | 3, 1, 0; R(3) := (Bool)1; if (0) pc++ (line:12)
[010] RETURN | 3, 2, 0; return R(3) ... R(3+2-2) (line:13)
[011] RETURN | 0, 1, 0; return R(0) ... R(0+1-2) (line:14)
; end of function
We can see that JMP instructions will lead to the 009 LOADBOOL instruction (considering PC increment in the main loop), which is correct and leads to the true returning.
The text was updated successfully, but these errors were encountered:
You must post issues only here. Questions, ideas must be posted in discussions.
Please answer the following before submitting your issue:
It seems to happen because of some optimizations or something like that. In case of comparison via functions we have following bytecode for the
betweenViaFunctions
function:Please pay attention for the 003 and 009 JMP instructions: they go to the 014 MOVE instruction, which is responisble for the result variable assignment. When JMP instructions are executed, the program counter points to the MOVE instruction, and then in the main loop (vm.go:30) the PC increments. After this operation the PC points to the 015 RETURN, that leads to the returning of wrong value.
For comparsion, there is the
betweenViaOperators
bytecode:We can see that JMP instructions will lead to the 009 LOADBOOL instruction (considering PC increment in the main loop), which is correct and leads to the true returning.
The text was updated successfully, but these errors were encountered: