1. Phix : a conundrum
- Posted by ChrisB (moderator) May 30, 2017
- 1236 views
Hi
I'm not sure if this is expected behaviour or not, but had me rubbing my head for a few hours. I boiled it down to the bare bones minimum to get reproducible results
First, a test input file, inptest.txt
This is a test file To load several lines To show that a file is loaded
next, a main program (follows the euwingui of main form program and code file
scopetest.exw
--scope test --this is the main file that is run --it just includes and runs the CF (code file) file --this is how euwingui creates it's executables --global sequence inpfile = {} puts(1, "local variable\n\n") --puts(1, "global variable\n\n") include scopetestCF.ew main()
next the codefile
scoptestCF.ew
--this is the scopetest code file, included by the main scopetest program --this is a sequence into which some data is stored --if this is uncommented, make sure the equivalent in the main file is commented --and vice versa sequence inpfile = {} ---------------------------------------------------- procedure load_inpfile() ---------------------------------------------------- inpfile = read_lines("inptest.txt") for i = 1 to length(inpfile) do puts(1, inpfile[i] & "\n") end for puts(1, "End of first section\n\n") end procedure ---------------------------------------------------- global procedure main() ---------------------------------------------------- load_inpfile() for i = 1 to length(inpfile) do puts(1, inpfile[i] & "\n") end for puts(1, "End of second section\n") if wait_key() then end if end procedure
Test 1
global sequence inpfile = {} in scopetest.exw - is commented
sequence inpfile = {} in scopetestCF.ew is uncommented
run interpreted, result is
local variable This is a test file To load several lines To show that a file is loaded End of first section This is a test file To load several lines To show that a file is loaded End of second section
run compiled, result is
local variable This is a test file To load several lines To show that a file is loaded End of first section End of second section
Test 2
global sequence inpfile = {} in scopetest.exw - is uncommented
sequence inpfile = {} in scopetestCF.ew is commented
run interpreted, result is
global variable This is a test file To load several lines To show that a file is loaded End of first section This is a test file To load several lines To show that a file is loaded End of second section
run compiled result is
global variable This is a test file To load several lines To show that a file is loaded End of first section This is a test file To load several lines To show that a file is loaded End of second section
Hope you can see the gotcha there - it seems the scope of inpfile has been altered at some point during compilation
Now I know the problem exists, I can work around it, or as I said at the beginning, is this expected behaviour?
Cheers
Chris
2. Re: Phix : a conundrum
- Posted by petelomax May 30, 2017
- 1201 views
Obviously that is a bug in the compiler. As buggy as a bug can be.
For some reason the compiler has decided that inpfile is always length 0 in main(), and rudely optimized away the second loop.
As a temporary fix, you could inpfile = append(inpfile,1), either immediately after the declaration, or as the first statement in main(), knowing that 1 will be thrown away, while I'm hunting it down.
FYI, you can compare the list.asm from p -d scopetest.exw with one from p -d! scopetest.exw and see the binary (in main()) is, well, gone.
Regards,
Pete
3. Re: Phix : a conundrum
- Posted by petelomax May 30, 2017
- 1200 views
Found it. opGetText in pilx86.e (line 14864) was not setting the destination type (at all):
elsif opcode=opGetText or opcode=opDcvar then --30/5/17: if opcode=opGetText then dest = s5[pc+1] getDest() slroot = T_Dsq+T_string setyp = T_integer+T_string slen = -2 sltype = slroot storeDest() end if
Thanks, Pete
4. Re: Phix : a conundrum
- Posted by ChrisB (moderator) May 30, 2017
- 1178 views
Nice one.
Cheers
Chris