SPLat Logo

Builder: Conditional segments ;<=IF

NOTICE: SPLat Controls has moved. We are now at 1/85 Brunel Rd, Seaford, 3198. map

Builder: Conditional segments ;<=IF

Another way of including/excluding segments from the build is called Conditional segments. Here's how it works:

Suppose in the SPLat source file you have this:

;<=IF DEBUG>	SetMem	StateNumber,6

The Builder tag is ;<=IF DEBUG> (including the semicolon!)

One of two things can happen:

  1. If the .b1d file lists DEBUG in the segment names, the final .spt file will contain
		SetMem	StateNumber,6 

2.  If the .b1d file does not list DEBUG in the segment names, the final .spt file will NOT contain the above SetMem instruction.

In this case the generated code line (SetMem) is not repositioned. Also, the <=IF DEBUG> tag only affects the line it appears on. Rephrasing that: A normal Builder tags acts as a switch the applies until the next Builder tag. <=IF tags only affect the current source line and do not result in the line being moved. Think of them as block tags versus line tags.

Example:

Consider the following source file, called test.spt:


;<MEQUSEG>
HourMeter mEQU 6 ;In permanent memory
;<=IF DEBUG>StateNumber mEQU 0 ;For easy readout using SPLatLink feature in SPLat/PC

;<CODESEG>
Start:
GoSub Initialise
;<=IF DEBUG> SetMem StateNumber,0
;<=IF DEBUG> GoSub TraceState


;<DEBUG>
;---- Some debug-only code ----
TraceState:
...
...
Return

Consider now the following .b1d file


;Build it with debug code
MEQUSEG
CODESEG
DEBUG
#---
test.spt

This will emit:

HourMeter	mEQU	6	;In permanent memory
StateNumber mEQU 0 ;For easy readout using SPLatLink feature in SPLat/PC
Start:
GoSub Initialise
SetMem StateNumber,0
GoSub TraceState

;---- Some debug-only code ----
TraceState:
...
...
Return

If on the other hand I add DISCARD after the segment name DEBUG in the bld file, I will get:


HourMeter mEQU 6 ;In permanent memory
Start:
GoSub Initialise

In other words, all the debug code will be stripped out automatically.

Notice that the lines that are tagged with ;<=IF DEBUG> are not moved to the debug segment, they are merely switched on (but get emitted in their original positions) by the presence of DEBUG without DISCARD.

Similarly, if the segment in which a conditional segment is embedded is set to DISCARD, the conditional line(s) will also be discarded. That's what happened in the last example above.

Note that the tag ;<=IF DEBUG> will work fine if there is no mention of DEBUG in the .b1d file. The scope of this tag (range of lines it affects) is only the line it is on. The other form, ;<DEBUG> will produce an error if DEBUG is not listed in the b1d file. The scope of that form is all following lines up until the next Builder tag (or the end of the file). This is why I use DISCARD to turn the DEBUG tag on and off.

Tip: You can turn the DISCARD qualifier off by using a semicolon - it becomes a comment and is ignored, e.g.:

DEBUG ; DISCARD

That is safer than

; DEBUG