Phix : a conundrum

new topic     » topic index » view thread      » older message » newer message

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

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu