| | 5330 | |
| | 5331 | % conditional compilation directives |
| | 5332 | |
| | 5333 | '$lgt_tr_directive'(if(Goal), _, _, _) :- |
| | 5334 | var(Goal), |
| | 5335 | throw(error(instantiantion_error, directive(if(Goal)))). |
| | 5336 | |
| | 5337 | '$lgt_tr_directive'(if(Goal), _, _, _) :- |
| | 5338 | \+ callable(Goal), |
| | 5339 | throw(error(type_error(callable, Goal), directive(if(Goal)))). |
| | 5340 | |
| | 5341 | '$lgt_tr_directive'(if(Goal), _, Input, _) :- |
| | 5342 | '$lgt_pp_cc_mode_'(Value), % not top-level if |
| | 5343 | !, |
| | 5344 | assertz('$lgt_pp_cc_if_found_'), |
| | 5345 | ( Value == seek -> % we're looking for an else |
| | 5346 | asserta('$lgt_pp_cc_mode_'(ignore)) % so ignore this if ... endif |
| | 5347 | ; % Value == skip -> |
| | 5348 | ( catch(Goal, Error, '$lgt_report_compiler_error'(Input, Error)) -> |
| | 5349 | asserta('$lgt_pp_cc_mode_'(skip)) |
| | 5350 | ; asserta('$lgt_pp_cc_mode_'(seek)), |
| | 5351 | retractall('$lgt_pp_cc_skipping_'), |
| | 5352 | assertz('$lgt_pp_cc_skipping_') |
| | 5353 | ) |
| | 5354 | ). |
| | 5355 | |
| | 5356 | '$lgt_tr_directive'(if(Goal), _, _, _) :- |
| | 5357 | !, |
| | 5358 | assertz('$lgt_pp_cc_if_found_'), |
| | 5359 | ( call(Goal) -> |
| | 5360 | asserta('$lgt_pp_cc_mode_'(skip)) |
| | 5361 | ; asserta('$lgt_pp_cc_mode_'(seek)), |
| | 5362 | retractall('$lgt_pp_cc_skipping_'), |
| | 5363 | assertz('$lgt_pp_cc_skipping_') |
| | 5364 | ). |
| | 5365 | |
| | 5366 | '$lgt_tr_directive'(elif(Goal), _, _, _) :- |
| | 5367 | var(Goal), |
| | 5368 | throw(error(instantiantion_error, directive(elif(Goal)))). |
| | 5369 | |
| | 5370 | '$lgt_tr_directive'(elif(Goal), _, _, _) :- |
| | 5371 | \+ callable(Goal), |
| | 5372 | throw(error(type_error(callable, Goal), directive(elif(Goal)))). |
| | 5373 | |
| | 5374 | '$lgt_tr_directive'(elif(Goal), _, _, _) :- |
| | 5375 | \+ '$lgt_pp_cc_if_found_', |
| | 5376 | throw(error(unmatched_directive, directive(elif(Goal)))). |
| | 5377 | |
| | 5378 | '$lgt_tr_directive'(elif(Goal), _, Input, _) :- |
| | 5379 | retract('$lgt_pp_cc_mode_'(Value)), |
| | 5380 | ( Value == ignore -> % we're inside an if ... endif |
| | 5381 | true % that we're ignoring; do nothing (continue skipping) |
| | 5382 | ; Value == skip -> % the corresponding if is true |
| | 5383 | retractall('$lgt_pp_cc_skipping_'), % so we must skip this elif |
| | 5384 | assertz('$lgt_pp_cc_skipping_'), |
| | 5385 | asserta('$lgt_pp_cc_mode_'(skip)) |
| | 5386 | ; % Value == seek -> % the corresponding if is false |
| | 5387 | ( catch(Goal, Error, '$lgt_compiler_error_handler'(Input, Error)) -> |
| | 5388 | retract('$lgt_pp_cc_skipping_'), |
| | 5389 | asserta('$lgt_pp_cc_mode_'(skip)) |
| | 5390 | ; asserta('$lgt_pp_cc_mode_'(seek)) |
| | 5391 | ) |
| | 5392 | ), |
| | 5393 | !. |
| | 5394 | |
| | 5395 | '$lgt_tr_directive'(else, _, _, _) :- |
| | 5396 | \+ '$lgt_pp_cc_if_found_', |
| | 5397 | throw(error(unmatched_directive, directive(else))). |
| | 5398 | |
| | 5399 | '$lgt_tr_directive'(else, _, _, _) :- |
| | 5400 | retract('$lgt_pp_cc_mode_'(Value)), |
| | 5401 | ( Value == ignore -> % we're inside an if ... endif |
| | 5402 | true % that we're ignoring |
| | 5403 | ; Value == skip -> % the corresponding if is true |
| | 5404 | retractall('$lgt_pp_cc_skipping_'), % so we must skip this else |
| | 5405 | assertz('$lgt_pp_cc_skipping_'), |
| | 5406 | asserta('$lgt_pp_cc_mode_'(skip)) |
| | 5407 | ; % Value == seek -> % the corresponding if is false |
| | 5408 | retract('$lgt_pp_cc_skipping_'), |
| | 5409 | asserta('$lgt_pp_cc_mode_'(skip)) |
| | 5410 | ), |
| | 5411 | !. |
| | 5412 | |
| | 5413 | '$lgt_tr_directive'(endif, _, _, _) :- |
| | 5414 | \+ '$lgt_pp_cc_if_found_', |
| | 5415 | throw(error(unmatched_directive, directive(endif))). |
| | 5416 | |
| | 5417 | '$lgt_tr_directive'(endif, _, _, _) :- |
| | 5418 | retract('$lgt_pp_cc_if_found_'), |
| | 5419 | retract('$lgt_pp_cc_mode_'(Value)), |
| | 5420 | ( Value == ignore -> |
| | 5421 | true |
| | 5422 | ; retractall('$lgt_pp_cc_skipping_') |
| | 5423 | ), |
| | 5424 | !. |
| | 5425 | |
| | 5426 | |
| | 5427 | % remaining directives |
| | 5428 | |