         Edinburgh IMP77 Compiler - Version 8.4

    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  
    5    %routine unlink(%string(*)%name s)
    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        
   10        { i2c } %systemroutinespec unlink (%string(*)%name fname)
   11        !imp77! %externalroutinespec unlink %alias "unlink" (%string(*)%name fname)
   12        %string(255) fname = s.TO STRING(0) { Add terminating \0 that C strings need. }
   13        unlink(STRING(ADDR(fname)+1))
   14      %end
   15    %end
   16  
   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:
   20    %integerfn getchar
   21      %integer sym
   22      readsymbol(sym)
   23      printstring("Call returned "); printsymbol(sym); newline
   24      %result = sym
   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)
   29    open output(2, fname)
   30    select output(2)
   31    printstring("BUG")
   32    newline
   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    
   41    { i2c } select output(1)
   42    !imp77! select output(0)
   43  
   44    open input(3, fname)
   45    select input(3)
   46  
   47    %if 'A' <= getchar <= 'C' %start
   48      printstring("Test successful."); newline
   49    %else
   50      printstring("Test failed - getchar was called twice."); newline
   51    %finish
   52  
   53    close input; select input(0)
   54    unlink(fname)
   55  
   56  %endofprogram

   36 Statements compiled
