Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

And... for reference. In my Microsoft F80 github string repository:

https://github.com/ratboy666/string

(Microsoft F80 was a FORTRAN 66, slightly subset compiler -- no COMPLEX that Microsoft sold from the late 70s to early 80s).

In there find pop.mac which is a short 4 byte assembly routine to discard a stack level. That can be used as follows:

   ASSIGN 1 TO I        -- STORE ADDRESS OF LABEL 1 TO I
   CALL F(I)            -- PASS I TO SUBROUTINE F
   ...                  -- WE WILL NEVER GET HERE
 1 ... 
 
   SUBROUTINE F(I)
   EXTERNAL $POP 
   INTEGER $POP  
   JUNK = $POP(0)       -- REMOVE RETURN ADDRESS
   GO TO I              -- GO TO ASSIGNED LABEL I 
   END                              
The ASSIGN command puts the address of label 1 into INTEGER I GO TO I then transfers to that location. Note that we can pass I into the SUBROUTINE, use $POP to remove a stack level (the return address), then jump to the variable. Scheme is nicer, which continuations, of course, but that hadn't been considered yet...

The ASSIGN was deleted as a feature in FORTRAN 95 -- obsolescent by FORTRAN 90. I guess "very very old-school".

Now, the FORTRAN 66 standard doesn't mention if something like this is allowed... but, since no stack was involved in early implementations, and recursion was not allowed, I imagine that it would work more widely than might otherwise be expected.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: