Stefan Hajnoczi wrote:

The 'loopif' command does two things: a conditional and a loop. I wanted to
see how expensive a general form of control flow would be with if/goto.


One of the ideas I had about 'loopif' was that one could have a collection of specialized scripts and the top-level script could do something like:

#!gpxe
set keep-running 1
imgfree
imgload ${next-script}.gpxe
boot ${next-script}.gpxe
loopif ${keep-running}

Other scripts could then set next-script and keep-running as needed in order to perform something akin to 'goto'. I really wanted to offer something that could achieve flow control with minimal impact on gPXE code size. Having said that...

Expressing 'loopif' using if/goto looks like this:
#!gpxe
: start


I totally agree that this is a nice form for the user to define a 'goto' point.

[...]
if ${condition} goto start

The 'if' command can be used to predicate any command, not just a 'goto':
if ${initrd} initrd ${initrd}


Also totally agreed. If we ever have something akin to $(command) where it expands to command's return code, this could stay the same, too.

Similarly, 'goto' is its own command and can be used independent of 'if':
: loop
[...]
goto loop


Agreed again. Once you have these, it would seem that gPXE has more to offer to the sysadmin who wishes to support a variety of startup strategies. The only "problem" I perceive is the unpopularity of 'goto' and labels amongst those who prefer less primitive flow control semantics. It's not a problem for DOS batch files. Tracking named labels suggests a bit more of a code cost than breaking out of a "control block" or looping back to its beginning. Both can be enjoyable. :)

The uncompressed code size of my 'ifgoto' branch is +541 bytes:
http://git.etherboot.org/?p=people/stefanha/gpxe.git;a=shortlog;h=refs/heads/ifgoto


While more expensive in code size than 'exit' and 'loopif', it's not nearly as complicated for the script developer as the script I offered way above. Although 'exit' and 'loopif' example scripts could be offered on the wiki, who needs an example of ': label', 'goto' and 'if'? How much burden should be on the script developer versus on gPXE's size? :)

(Note that we don't have expression evaluation in mainline gPXE, so the 'if' command is not very useful yet.)


Also true for 'loopif' at this time. We also don't have strtol() and we don't have "%lu". Heheh.

The if/goto approach is not as nice as the control flow (if, while, for, and try) that Lynus Vaz developed for his Summer of Code project, but I am going to compare code size to see what the difference is.

Thoughts?


Whatever we go with, if anything, hopefully it's easy to re-implement if the script/CLI parsing system is ever rewritten entirely.

Thanks for this, Stefan.

- Shao Miller
_______________________________________________
gPXE-devel mailing list
[email protected]
http://etherboot.org/mailman/listinfo/gpxe-devel

Reply via email to