Page 1 of 2 12>
Topic Options
#134579 - 2005-02-25 07:09 PM How the new INCLUDE statement works...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
This is my take on how the new INCLUDE statement works in 4.50 ... works just like the CALL statement, except that if your tokenizing a script, it will "embed" or "include" these external scripts inside the generated KX (tokenized) script itself, by way of example:

1) Create a script called SUB.KIX that contains the following:

SUB.KIX

$X = 100
$Y = 200

2) Create a "mainline" script called MAIN.KIX that "uses" this external script, will use the CALL statement for this first example:


MAIN.KIX

break on

call "sub.kix"

?"x=" $X
?"y=" $Y


3) If you just run the mainline script, you would get this expected result:


C:\>kix32 main.kix

x=100
y=200



4) Now, change the CALL statement in MAIN, to be an INCLUDE statement, and run it again (the same result, INCLUDE is like a CALL):


MAIN.KIX

break on

include "sub.kix"

?"x=" $X
?"y=" $Y


C:\>kix32 main.kix

x=100
y=200


5) Now here is the neat part, tokenize MAIN.KIX into MAIN.KX, like this:


C:\>kix32 /t main.kix


6) Then run MAIN.KX and you get this:


C:\>kix32 main.kx

x=100
y=200


7) Now - the really cool part, delete (or rename away) the original SUB.KIX file, the MAIN tokenized script still works because SUB.KIX is "part of" (it's been included into), MAIN.KX, like this:


C:\> ren sub.kix sub.tmp

C:\> kix32 main.kx

x=100
y=200


If you ran the original (untokenized) MAIN.KIX again, it would fail, because SUB.KIX is not there !

Here's more, been doing much testing with using FUNCTION calls in INCLUDED scripts, and I am getting nasty Kixtart crashes - so think Ruud had some more work to do with functions in included files.

-Shawn




Top
#134580 - 2005-02-25 07:49 PM Re: How the new INCLUDE statement works...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just by way of more example, here is a dir listing of the tokenized MAIN.KX file, using the CALL sub.kix statement (reference):

2005/02/25 01:38 PM 84 main.kx

Here is the dir listing of the tokenized MAIN.KX file, using the INCLUDE sub.kix statement:

2005/02/25 01:38 PM 122 main.kx

Its bigger because SUB.KIX is physically "part of" (included into), MAIN.KX.

Top
#134581 - 2005-02-25 07:52 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
From my experience (verified by Allen), you cannot substitute INCLUDE for CALL if the called/included script contains UDFs. I think the pre-parse routine that would load the UDFs into memory does not pre-parse the includes.

So, it looks like the present incarnation of INCLUDE will join together pasta into one long noodle and not much more.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134582 - 2005-02-25 07:58 PM Re: How the new INCLUDE statement works...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Thats mostly because Kixtart is crashing (for me anyways), check your eventlog after running this (untokenized):

SUB.KIX

break on

function add($a, $b)

$add = $a + $b

endfunction


MAIN.KIX

break on

include "sub.kix"

?"value=" add(1,2)

exit 1


If you change the INCLUDE to be a CALL, it runs fine - my guess is that Ruud intended include to be like a call (that doesn't crash).

-Shawn

Top
#134583 - 2005-02-25 08:04 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Right you are... KiX is crashing with the error:
Fatal exception occurred.
Error : (0xc0000005/-1073741819)

If you run the untokenized version of the main script in debug mode, the INCLUDE line,if calling a tokenized sub, shows hieroglyphics.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134584 - 2005-02-26 04:50 PM Re: How the new INCLUDE statement works...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Les and I were doing some more testing with INCLUDE, and found that maybe INCLUDE is NOT like CALL after all. It more like the C #INCLUDE, that actually INLINES or embeds external scripts right into your code, like a MACRO substitution would ...

We found that if you include a script that has an EXIT 0 at the end, it will actually exit your main script as well - if you had of used CALL, the EXIT would have only exited the called script !

Don't know if this was intended behavior or not - not sure about what other "scope" concerns there are.

Top
#134585 - 2005-02-26 04:57 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ja, so far it looks like it is just a spaghetti joiner with a broken pre-parser.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134586 - 2005-02-26 05:21 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Just as EXIT behaves different in a CALLed script than an INCLUDEd script, so too with var scope.

Test.kix Code:
break on
dim $var
$var = 'test'
'in test - before call - '+ $var ?
call 'test2.kix'
'in test - after call - '+ $var ?
include 'test2.kix'
'in test - after include - '+ $var ?



Test2.kix Code:
break on
$var = "test2"
'in test2 - ' + $var ?



Results:
in test - before call - test
in test2 - test2
in test - after call - test
in test2 - test2
in test - after include - test2

C:\KiXScripts>
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134587 - 2005-02-26 05:33 PM Re: How the new INCLUDE statement works...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
nice test - the more i think about, the more i think maybe this is all by-design behavior. so the lesson's are:

1) Called scripts cannot be seamlessly included.

2) Included scripts have to be engineered to be "included".

3) The only thing you would want to put in an included file, are UDF's and maybe global $var declares - else the result is code that has been simply stitched together.

*** Ruud - can you shed any light on these tests/observations ?

Top
#134588 - 2005-02-26 06:38 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ja, figure the in-lining of code and the var scope is "by-design" as you say, but somehow cannot accept that the inability to pre-parse UDFs is by-design. I see the concept of INCLUDEing UDF libraries as a highly desirable feature. After all, who would want to simply join spaghetti into one big long noodle?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134589 - 2005-02-26 06:41 PM Re: How the new INCLUDE statement works...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Maybe by design idk, but I figure that making INCLUDE behave more like CALL, in terms of behavior but especially in terms of scope, would be a much more "usefull" feature in the long-run, ja ? - just thinking out loud here.
Top
#134590 - 2005-02-26 06:56 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
K, so lets think about it a bit...

EXIT in CALL returns but in INCLUDE quits... Change or keep? I think it would be confusing to change it.

Var scope in CALL local but in INCLUDE the same as parent... CALL is like a GOSUB on a file level. Again, to change it would be confusing.

So... the only real benefit in using INCLUDE over CALL is when tokenizing, it generates a monolithic file. Otherwise, a not tokenized running would make CALL redundant if it were the same as INCLUDE.

If a monolithic file is the only desired effect, I think we should take it a step further with my MakeEXE idea to package it into a single EXE.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134591 - 2005-02-27 06:17 AM Re: How the new INCLUDE statement works...
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I am interested to see what INCLUDE does. CALL, I am seeing some behaviors where VARs are not be passed to CALLed scripts. I will have to test and see.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#134592 - 2005-02-27 03:23 PM Re: How the new INCLUDE statement works...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
K, well... extending my example from above...

Test.kix Code:
break on

dim $var
$var = 'test'
'in test before call - ['+ $var +']' ?
call 'test2.kix'
'in test after call - ['+ $var +']' ?
include 'test2.kix'
'in test after include - ['+ $var +']' ?



Test2.kix Code:
break on

'in test2 before redef - [' + $var +']' ?
$var = "test2"
'in test2 after redef - [' + $var +']' ?


Results
Quote:

in test before call - [test]
in test2 before redef - []
in test2 after redef - [test2]
in test after call - [test]
in test2 before redef - [test]
in test2 after redef - [test2]
in test after include - [test2]

C:\KiXScripts>



_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134593 - 2005-02-28 10:40 PM Re: How the new INCLUDE statement works...
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Maybe I am a bit asleep here..

Did some testst with this:
Code:

IF RIGHT(@SCRIPTNAME,2)='kx'
INCLUDE @LDRIVE+'newscript\function.kx'
ELSE
INCLUDE @LDRIVE+'newscript\function.kix'
ENDIF


Results:
Quote:


ERROR : expected string!
Script: \\<DC>\netlogon\newscript\kent\kixtart.kix





If I change it to (I know VARS in strings are evil):
Code:

IF RIGHT(@SCRIPTNAME,2)='kx'
INCLUDE '@scriptdir\function.kx'
ELSE
INCLUDE '@scriptdir\function.kix'
ENDIF


Results:
Quote:


ERROR : failed to find/open script ["]!
Script: \\<DC>\netlogon\newscript\kent\kixtart.kix





Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#134594 - 2005-03-08 05:16 PM Re: How the new INCLUDE statement works...
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
On the last post: this is by design. I mentioned in the email that INCLUDE is processed before run-time, so you can only use 'flat' strings to refer to included files, no vars, no macro's, no UDF's, etc).

Apart from this: INCLUDE is indeed broken (at least for Include-files containing UDF's). I'm working on a fix for the next build.

Ruud

Top
#134595 - 2005-03-09 10:06 AM Re: How the new INCLUDE statement works...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
As an alternative to the built-in INCLUDE I strongly recommend that anyone who needs more flexible static include type processing looks at using "make" (aka makefile) for collating the files before tokenizing.

If your projects are big enough to require multiple source files, they will probably also benefit from the features offered by "make". This is especially true where you have common UDF libraries.

Top
#134596 - 2005-03-10 01:34 AM Re: How the new INCLUDE statement works...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Translation:

This is an invitation to write new and/or publish an existing KiXtart script that is the equivalent of 'make'

_________________________
There are two types of vessels, submarines and targets.

Top
#134597 - 2005-03-10 02:41 AM Re: How the new INCLUDE statement works...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Glenn Barnas already does this with a batch file.

I'm sure he will be glad to share his experience in this area. In fact not sure of the link but I think he has already posted about it at least once or twice in the past, but think most of us overlooked it because we don't typically write such large complex scripts that benefit from this.

Top
#134598 - 2005-03-10 09:42 AM Re: How the new INCLUDE statement works...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

This is an invitation to write new and/or publish an existing KiXtart script that is the equivalent of 'make'




Not at all.

"Make" is a generic project management tool, and handles KiXtart files perfectly well.

When Ruud first proposed the INCLUDE statement I posted details of how to use "make" to generate monolithic scripts suitable for tokenising. Can't find the blasted post now however.

Top
Page 1 of 2 12>


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 980 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.248 seconds in which 0.195 seconds were spent on a total of 13 queries. Zlib compression enabled.