
     1  ! for i2c: m-0mm(v/! i2c !/s/{ i2c }/, v/{imp77}/s/!imp77!/, r, m)0
     2  ! for imp2026: m-0mm(v/{ i2c }/s/! i2c !/, v/!imp77!/s/{imp77}/, r, m)0
     3  %begin
     4  
503 @ 4405:         LINE   3 "regression-run-tmp/dscond.imp"
504 @ 4438:         BEGIN  _lev0id0 {lev=0 --> 1}

     5    %routine unlink(%string(*)%name s)
505 @ 4439:            LINE   5 "regression-run-tmp/dscond.imp"
506 @ 4472:            DEF    UNLINK (_lev0id0_UNLINK) p1=V_0081 a/tf=7 b/format=0 c/ostate=0  type=0 (<type:0>) form=7 (routine) special=0 (<special:0>) linkage=0 (auto) spec=0 indirect=0 unass=0
507 @ 4490:               START  ( FORMAL PARAMETERS  {lev=2 --> 3, nested=0 --> 1}
508 @ 4491:                  DEF    S p1=V_0082 a/tf=32 b/format=0 c/ostate=0  type=3 (string) form=2 (name) special=0 (<special:0>) linkage=0 (auto) spec=0 indirect=0 unass=0
509 @ 4504:               FINISH ) {lev=2}

     6      %begin
     7        ! i2c uses %systemroutine to access linux externals with the normal name and parameter order.
     8        ! imp2026 needs to use %alias to get the linux linkage name and reverses the order of all params.
     9        
510 @ 4505:               LINE   6 "regression-run-tmp/dscond.imp"
511 @ 4538:               BEGIN  _lev0id0_UNLINK_lev2id1 {lev=2 --> 3}

    10        { i2c } %systemroutinespec unlink (%string(*)%name fname)
    11        !imp77! %externalroutinespec unlink %alias "unlink" (%string(*)%name fname)
512 @ 4539:                  LINE   10 "regression-run-tmp/dscond.imp"
513 @ 4572:                  DEF    UNLINK (_lev0id0_UNLINK_lev2id1_UNLINK) p1=V_0083 a/tf=7 b/format=0 c/ostate=2c  type=0 (<type:0>) form=7 (routine) special=0 (<special:0>) linkage=4 (system) spec=1 indirect=0 unass=1
514 @ 4590:                  START  ( FORMAL PARAMETERS  {lev=3 --> 4, nested=0 --> 1}
515 @ 4591:                     DEF    FNAME p1=V_0084 a/tf=32 b/format=0 c/ostate=0  type=3 (string) form=2 (name) special=0 (<special:0>) linkage=0 (auto) spec=0 indirect=0 unass=0
516 @ 4608:                  FINISH ) {lev=3}

    12        %string(255) fname = s.TO STRING(0) { Add terminating \0 that C strings need. }
517 @ 4609:                  LINE   12 "regression-run-tmp/dscond.imp"
518 @ 4642:                  DEF    FNAME p1=V_0084 a/tf=31 b/format=ff c/ostate=0  type=3 (string) form=1 (simple) special=0 (<special:0>) linkage=0 (auto) spec=0 indirect=0 unass=0
519 @ 4659:                  PUSH   FNAME
520 @ 4662:                  PUSH   S
521 @ 4665:                  PUSH   TOSTRING
522 @ 4668:                  PUSHI  #0x00000000
523 @ 4673:                  ASSPAR
524 @ 4674:                  CALL  
525 @ 4675:                  CONCAT
526 @ 4676:                  ASSVAL

    13        unlink(STRING(ADDR(fname)+1))
527 @ 4677:                  LINE   13 "regression-run-tmp/dscond.imp"
528 @ 4710:                  PUSH   UNLINK
529 @ 4713:                  PUSH   STRING
530 @ 4716:                  PUSH   ADDR
531 @ 4719:                  PUSH   FNAME
532 @ 4722:                  ASSPAR
533 @ 4723:                  CALL  
534 @ 4724:                  PUSHI  #0x00000001
535 @ 4729:                  ADD   
536 @ 4730:                  ASSPAR
537 @ 4731:                  CALL  
538 @ 4732:                  ASSPAR
539 @ 4733:                  CALL  

    14      %end
540 @ 4734:                  LINE   14 "regression-run-tmp/dscond.imp"
541 @ 4767:               END    _lev0id0_UNLINK_lev2id1 {lev=3 --> 2}

    15    %end
    16  
542 @ 4768:               LINE   15 "regression-run-tmp/dscond.imp"
543 @ 4801:            END    _lev0id0_UNLINK {lev=2 --> 1}

    17    %ownstring(255) fname = "/tmp/dscond-test.txt"
    18    
    19    ! A function with side-effects that can be used in the middle of a double-sided conditional test:
544 @ 4802:            LINE   17 "regression-run-tmp/dscond.imp"
545 @ 4835:            PUSHS  "/tmp/dscond-test.txt"
546 @ 4857:            DEF    FNAME p1=V_0082 a/tf=31 b/format=ff c/ostate=21  type=3 (string) form=1 (simple) special=0 (<special:0>) linkage=1 (own) spec=0 indirect=0 unass=1
547 @ 4874:            INIT   1

    20    %integerfn getchar
548 @ 4877:            LINE   20 "regression-run-tmp/dscond.imp"
549 @ 4910:            DEF    GETCHAR (_lev0id0_GETCHAR) p1=V_0083 a/tf=18 b/format=1 c/ostate=10  type=1 (integer) form=8 (function) special=0 (<special:0>) linkage=0 (auto) spec=0 indirect=1 unass=0
550 @ 4929:               START  ( FORMAL PARAMETERS  {lev=2 --> 3, nested=0 --> 1}
551 @ 4930:               FINISH ) {lev=2}

    21      %integer sym
552 @ 4931:               LINE   21 "regression-run-tmp/dscond.imp"
553 @ 4964:               DEF    SYM p1=V_0084 a/tf=11 b/format=1 c/ostate=0  type=1 (integer) form=1 (simple) special=0 (<special:0>) linkage=0 (auto) spec=0 indirect=0 unass=0

    22      readsymbol(sym)
554 @ 4979:               LINE   22 "regression-run-tmp/dscond.imp"
555 @ 5012:               PUSH   READSYMBOL
556 @ 5015:               PUSH   SYM
557 @ 5018:               ASSPAR
558 @ 5019:               CALL  

    23      printstring("Call returned "); printsymbol(sym); newline
559 @ 5020:               LINE   23 "regression-run-tmp/dscond.imp"
560 @ 5053:               PUSH   PRINTSTRING
561 @ 5056:               PUSHS  "Call returned "
562 @ 5072:               ASSPAR
563 @ 5073:               CALL  
564 @ 5074:               LINE   23 "regression-run-tmp/dscond.imp"
565 @ 5107:               PUSH   PRINTSYMBOL
566 @ 5110:               PUSH   SYM
567 @ 5113:               ASSPAR
568 @ 5114:               CALL  
569 @ 5115:               LINE   23 "regression-run-tmp/dscond.imp"
570 @ 5148:               PUSH   NEWLINE
571 @ 5151:               CALL  

    24      %result = sym
572 @ 5152:               LINE   24 "regression-run-tmp/dscond.imp"
573 @ 5185:               PUSH   SYM
574 @ 5188:               RESULT

    25    %end
    26  
    27    ! using streams 2 and 3 in case imp2026 has opened stream 1 for default input/output.
    28    ! (I'm not really very clear on what it is doing with the streams)
575 @ 5189:               LINE   25 "regression-run-tmp/dscond.imp"
576 @ 5222:            END    _lev0id0_GETCHAR {lev=2 --> 1}

    29    open output(2, fname)
577 @ 5223:            LINE   29 "regression-run-tmp/dscond.imp"
578 @ 5256:            PUSH   OPENOUTPUT
579 @ 5259:            PUSHI  #0x00000002
580 @ 5264:            ASSPAR
581 @ 5265:            PUSH   FNAME
582 @ 5268:            ASSPAR
583 @ 5269:            CALL  

    30    select output(2)
584 @ 5270:            LINE   30 "regression-run-tmp/dscond.imp"
585 @ 5303:            PUSH   SELECTOUTPUT
586 @ 5306:            PUSHI  #0x00000002
587 @ 5311:            ASSPAR
588 @ 5312:            CALL  

    31    printstring("BUG")
589 @ 5313:            LINE   31 "regression-run-tmp/dscond.imp"
590 @ 5346:            PUSH   PRINTSTRING
591 @ 5349:            PUSHS  "BUG"
592 @ 5354:            ASSPAR
593 @ 5355:            CALL  

    32    newline
594 @ 5356:            LINE   32 "regression-run-tmp/dscond.imp"
595 @ 5389:            PUSH   NEWLINE
596 @ 5392:            CALL  

    33    close output
    34  
    35    ! restore stdout.
    36  
    37    ! under i2c, stream 0 is /dev/tty, stream 1 is /dev/stdout.  We want stdout so that
    38    ! the result can be written to a file in order for the regression tests to check it.
    39    ! under imp2026, selecting stream 1 causes a runtime failure but stream 0 is OK.
    40    
597 @ 5393:            LINE   33 "regression-run-tmp/dscond.imp"
598 @ 5426:            PUSH   CLOSEOUTPUT
599 @ 5429:            CALL  

    41    { i2c } select output(1)
    42    !imp77! select output(0)
    43  
600 @ 5430:            LINE   41 "regression-run-tmp/dscond.imp"
601 @ 5463:            PUSH   SELECTOUTPUT
602 @ 5466:            PUSHI  #0x00000001
603 @ 5471:            ASSPAR
604 @ 5472:            CALL  

    44    open input(3, fname)
605 @ 5473:            LINE   44 "regression-run-tmp/dscond.imp"
606 @ 5506:            PUSH   OPENINPUT
607 @ 5509:            PUSHI  #0x00000003
608 @ 5514:            ASSPAR
609 @ 5515:            PUSH   FNAME
610 @ 5518:            ASSPAR
611 @ 5519:            CALL  

    45    select input(3)
    46  
612 @ 5520:            LINE   45 "regression-run-tmp/dscond.imp"
613 @ 5553:            PUSH   SELECTINPUT
614 @ 5556:            PUSHI  #0x00000003
615 @ 5561:            ASSPAR
616 @ 5562:            CALL  

    47    %if 'A' <= getchar <= 'C' %start
617 @ 5563:            LINE   47 "regression-run-tmp/dscond.imp"
618 @ 5596:            PUSHI  #0x00000041
619 @ 5601:            PUSH   GETCHAR
620 @ 5604:            CALL  
621 @ 5605:            JUMPIFD > L_0004
622 @ 5609:            PUSHI  #0x00000043
623 @ 5614:            JUMPIF > L_0004

    48      printstring("Test successful."); newline
624 @ 5618:            LINE   48 "regression-run-tmp/dscond.imp"
625 @ 5651:            PUSH   PRINTSTRING
626 @ 5654:            PUSHS  "Test successful."
627 @ 5672:            ASSPAR
628 @ 5673:            CALL  
629 @ 5674:            LINE   48 "regression-run-tmp/dscond.imp"
630 @ 5707:            PUSH   NEWLINE
631 @ 5710:            CALL  

    49    %else
632 @ 5711:            LINE   49 "regression-run-tmp/dscond.imp"
633 @ 5744:            GOTO   L_0003
634 @ 5747:            LOCATE L_0004

    50      printstring("Test failed - getchar was called twice."); newline
635 @ 5750:            LINE   50 "regression-run-tmp/dscond.imp"
636 @ 5783:            PUSH   PRINTSTRING
637 @ 5786:            PUSHS  "Test failed - getchar was called twice."
638 @ 5827:            ASSPAR
639 @ 5828:            CALL  
640 @ 5829:            LINE   50 "regression-run-tmp/dscond.imp"
641 @ 5862:            PUSH   NEWLINE
642 @ 5865:            CALL  

    51    %finish
    52  
643 @ 5866:            LINE   51 "regression-run-tmp/dscond.imp"
644 @ 5899:            LOCATE L_0003

    53    close input; select input(0)
645 @ 5902:            LINE   53 "regression-run-tmp/dscond.imp"
646 @ 5935:            PUSH   CLOSEINPUT
647 @ 5938:            CALL  
648 @ 5939:            LINE   53 "regression-run-tmp/dscond.imp"
649 @ 5972:            PUSH   SELECTINPUT
650 @ 5975:            PUSHI  #0x00000000
651 @ 5980:            ASSPAR
652 @ 5981:            CALL  

    54    unlink(fname)
    55  
653 @ 5982:            LINE   54 "regression-run-tmp/dscond.imp"
654 @ 6015:            PUSH   UNLINK
655 @ 6018:            PUSH   FNAME
656 @ 6021:            ASSPAR
657 @ 6022:            CALL  

    56  %endofprogram
658 @ 6023:            LINE   56 "regression-run-tmp/dscond.imp"
659 @ 6056:         END    _lev0id0 {lev=1 --> 0}
660 @ 6057:         END     {lev=0 --> -1}
661 @ 6058: 

