COMEFROM

COMEFROM

In computer programming, COMEFROM (or COME FROM) is an obscure control flow structure used in some programming languages, originally as a joke.

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal.

A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.

Contents

History

COMEFROM was initially seen in lists of joke assembly language instructions (as 'CMFRM'). It was elaborated upon in a Datamation article by R. Lawrence Clark in 1973,[1] written in response to Edsger Dijkstra's letter Go To Statement Considered Harmful. COMEFROM was eventually implemented in the C-INTERCAL variant of the esoteric programming language INTERCAL along with the even more obscure 'computed COMEFROM'. There were also Fortran proposals for 'assigned COME FROM' and a 'DONT' keyword (to complement the existing 'DO' loop).

On 1 April 2004, Richie Hindle published an implementation of both GOTO and COMEFROM for the Python programming language.[2] Despite being released on April Fools' Day and not being intended for serious use, the syntax is valid and the implementation fully works.

Practical uses

Although COMEFROM is syntactically and semantically valid, and capable of replacing GOTO in some programs, it is considerably more difficult to visualise in program design and actually implement in a programming language. The most well known use of a COMEFROM-like construct is setting a breakpoint during debugging. One implementation of FORTRAN included it, under the name "AT", as a debugging aid, with dire warnings against using it in production code. In addition, many modern CPUs have hardware support for breakpoints.

Some elements of aspect-oriented programming have been compared to the COMEFROM statement.[3]

In compilers using SSA, a phi node is essentially similar to a come from statement. It lists which basic blocks the current basic block could have been reached from and the associated value to use if it did.

In some reversible computing assembly languages, the target of a GOTO is always a COMEFROM targeting the GOTO.

Examples

The following is an example of a program in a hypothetical BASIC dialect with "COMEFROM" instead of "GOTO". An actual example in INTERCAL would be too difficult to read[citation needed].

10 COMEFROM 40
20 INPUT "WHAT IS YOUR NAME? "; A$
30 PRINT "HELLO, "; A$
40 REM

The program (hypothetically) works by asking the user for their name, then greeting them with the same name, and continuing all over again. The instruction "REM" on line 40 is simply a NOP — the "COMEFROM" statement on line 10 causes a branch back to that line when execution reaches line 40, regardless of its contents.


A fully runnable example in Python with the joke goto module installed (which uses debugger hooks to control program execution) looks like this:

from goto import comefrom, label
 
comefrom .repeat
name = raw_input('what is your name? ')
if name:
    print "Hello",name
    label .repeat
print "Goodbye!"


This is an implementation in Ruby of the Intercal COME FROM statement.

$come_from_labels = {}
 
def label(l)
    if $come_from_labels[l]
        $come_from_labels[l].call
    end
end
 
def come_from(l)
    callcc do |block|
        $come_from_labels[l] = block
    end
end


Some examples of the debug packet feature of the OS/360 Fortran G compiler:[4]

Example 1:
 
      INTEGER SOLON, GFAR, EWELL
         .
         .
         .
10    SOLON = GFAR * SQRT(FLOAT(EWELL))
11    IF (SOLON) 40, 50, 60
         .
         .
         .
      DEBUG UNIT(3)
      AT 11
      DISPLAY GFAR, SOLON, EWELL
      END
 
Example 2:
 
      DIMENSION STOCK(1000),OUT(1000)
         .
         .
         .
      DO 30 I=1, 1000
25    STOCK(I)=STOCK(I) - OUT(I)
30    CONTINUE
35    A = B + C
         .
         .
         .
      DEBUG UNIT(3)
      AT 35
      DISPLAY STOCK
      END
 
Example 3:
 
10    A = 1.5
12    L = 1
15    B = A + 1.5
20    DO 22 I = 1,5
         .
         .
         .
22    CONTINUE
25    C = B + 3.16
30    D = C/2
      STOP
         .
         .
         .
      DEBUG UNIT(3), TRACE
C     DEBUG PACKET NUMBER 1
      AT 10
      TRACE ON
C     DEBUG PACKET NUMBER 2
      AT 20
      TRACE OFF
      DO 35 I = 1,3
         .
         .
         .
35    CONTINUE
      TRACE ON
C     DEBUG PACKET NUMBER 3
      AT 30
      TRACE OFF
      END

In example 1, the values of SOLON, GFAR, and EWELL are examined as they were at the completion of statement 10. The AT statement indicates statement 11.

In example 2, all the values of STOCK are displayed when statement 35 is encountered.

In example 3, tracing begins at statement 10, at statement 20, tracing stops while the loop is executed, and resumes after the loop. Tracing stops just before statement 30 is executed.

Hardware implementation

The SHARC DSP supports a DO..UNTIL instruction, intended for do..while loops, that is essentially a COMEFROM. Example:

    LCNTR=42;
    DO x UNTIL LCE;  /* COMEFROM x, unless the loop counter is zero */
    F12=F0*F4, F8=F8+F12, F0=dm(I0,M3), F4=pm(I8,M9);
    IF NZ dm(I2,M2) = F12;
    IF ZF dm(I2,M2) = F1;
x:  R2 = R3 + 76;   /* the label "x" does not exist in the machine code */

Note that the loop termination condition, here specified as LCE (loop counter expired), can be set to other values including always-true and always-false. With an always-true condition, we have a genuine COMEFROM. The hardware supports up to six simultaneously active COMEFROMs.

A similar feature exists in Microchip dsPIC's for (unnested) loops provided by the 'DO' assembly instruction. Its interruptible and trivial nesting goes up to one level with an additional 5 levels in software.

See also

Serious programming contrivances involving ideas resembling COMEFROM:

References

  1. ^ Clarke, Lawrence, Datamation (article), Fortran, http://www.fortran.com/fortran/come_from.html .
  2. ^ Hindle, Richie (1 April 2004), "goto for Python", Entrian, http://entrian.com/goto/ .
  3. ^ C2:ComeFrom
  4. ^ IBM System/360 and System/370 Fortran IV Language, GC28-6515-10, May 1974
  5. ^ F. X. Reid, On the Formal Semantics of the COMEFROM Statement. FACS FACTS, Issue 2006-1, pages 18–20, March 2006.

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • COMEFROM — halbmythisches Sprachkonstrukt entgegengesetzt zu goto : ) http://www.ccil.org/jargon/jargon.html …   Acronyms

  • COMEFROM — halbmythisches Sprachkonstrukt entgegengesetzt zu goto : ) (http://www.ccil.org/jargon/jargon.html) …   Acronyms von A bis Z

  • Lega Nord — Federal Secretary Umberto Bossi Federal President Angelo Alessandri …   Wikipedia

  • Andre Derain — André Derain (* 10. Juni 1880 in Chatou bei Paris; † 8. September 1954 in Garches bei Paris) war ein französischer Künstler. Er schuf unter anderem Gemälde, Grafiken, Skulpturen, Bühnenbilder und –kostüme, überdauert hat jedoch vor allem seine… …   Deutsch Wikipedia

  • Derain — André Derain (* 10. Juni 1880 in Chatou bei Paris; † 8. September 1954 in Garches bei Paris) war ein französischer Künstler. Er schuf unter anderem Gemälde, Grafiken, Skulpturen, Bühnenbilder und –kostüme, überdauert hat jedoch vor allem seine… …   Deutsch Wikipedia

  • Tenerani — Pietro Tenerani (* 11. November 1789 in Torano bei Carrara; † 14. Dezember 1869 in Rom) war ein italienischer Bildhauer, Tenerani war in Rom Schüler der Bildhauer Antonio Canova und Bertel Thorvaldsen. Als Meisterschüler des letzteren war… …   Deutsch Wikipedia

  • Falconet — Der eherne Reiter in Sankt Petersburg Etienne Maurice Falconet (* 1. Dezember 1716 zu Vevey in der Schweiz; † 4. Januar 1791 in Paris) war ein französischer Bildhauer. Leben …   Deutsch Wikipedia

  • Intercal — ist eine esoterische Programmiersprache, die am 26. Mai 1972 von Donald R. Woods und James M. Lyon entwickelt wurde. Erst 1990 wurde eine erste UNIX Implementierung von Eric S. Raymond programmiert, heute ist INTERCAL auch auf DOS verfügbar.… …   Deutsch Wikipedia

  • Пазырык — Фрагмент пазырыкского ковра из Эрмитажа (V в. до н. э.) Пазырыкская культура скифская археологическая культура железного века (VI III вв. до н. э.), основные находки предметов которой были сделаны в Горном Алтае. Носители этой культуры обитали на …   Википедия

  • Nicholas Burgess Farrell — (October 2, 1958) is an English journalist and the author of Mussolini: A New Life, accused by some of playing down the crimes of Benito Mussolini, a former Italian dictator. Farrel s most famous article is an interview with Silvio Berlusconi for …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”