Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: ANS TC Magnet for Control, ABORT,QUIT.. Message-ID: <2241.UUL1.3#5129@willett.pgh.pa.us> Date: 17 Jan 91 12:30:45 GMT Organization: (n.) to be organized. But that's not important right now. Lines: 95 Category 10, Topic 27 Message 34 Tue Jan 15, 1991 W.BADEN1 [Wil] at 20:17 PST Discussion: The lack of a way to accomplish what the non-portable, inadequate, and unusable Forth-83 BRANCH-MARK-RESOLVE words attempted to do is felt by some to be a serious omission. In brief, the Forth-83 words are unacceptable because they assume a particular object form, require the data stack for information during compilation, and yet do not give any way to access the stack information. They are incapable of defining ELSE and WHILE...REPEAT independently of implementation. The paper "Flowgraph Basis" gives a set of seven operations that can describe the topology of any flowgraph. Algorithms to describe any flowgraph with these seven operations are given in the paper. Five of these operations have a direct correspondence with Forth words: IF, UNTIL, AGAIN, THEN, BEGIN. These specify forward and backward conditional branches, unconditional backward branch, and the destination of forward and backward branches. All that is necessary to give Forth the ability to make a portable definition of any control structure is to adopt the two additional operations described in "Flowgraph Basis". One operation, ALTHOUGH, is the mirror of AGAIN, and specifies an unconditional forward branch. Adoption of this alone still would not make ELSE and WHILE...REPEAT definable. The operations produce and consume values on a stack whose implementation is hidden. We call that stack the control flow stack. The operation [ n ] SO provides the basic operation to manipulate the control flow stack. [ n ] SO Take the nth element from the top of the control flow stack and move it to the top of the control flow stack. Each of the seven operations has a graphical correspondence as well as a control-flow correspondence. These correspondences are shown in "Flowgraph Basis". E.g., the argument n of SO is related to the number of lines crossed by a line in a planar representation of a flowgraph. A paleolithic 1970's style Forth implementation of the seven operations is given below. The values of the constants whose names begin with ' is of course implementation dependent. : IF '?>Branch , HERE 0 , ; IMMEDIATE : UNTIL '?Branch , HERE 0 , ; IMMEDIATE : SO ROLL ; IMMEDIATE ALTHOUGH is the essentil ingredient of ELSE. It could also be used in customized control structures. First we make an implementation independent definition of a useful auxiliary word (still in 1970's style). : BUT 1 [COMPILE] SO ; IMMEDIATE BUT Interchange the top two elements of the control flow stack. Now we can define in any implementation. : ELSE [COMPILE] ALTHOUGH [COMPILE] BUT [COMPILE] THEN ; IMMEDIATE : WHILE [COMPILE] IF [COMPILE] BUT ; IMMEDIATE : REPEAT [COMPILE] AGAIN [COMPILE] THEN ; IMMEDIATE An example of ALTHOUGH is a customized optimization of BEGIN...WHILE...REPEAT. : MEANWHILE [COMPILE] ALTHOUGH [COMPILE] BEGIN [COMPILE] BUT ; IMMEDIATE MEANWHILE mumble THEN grumble UNTIL optimizes BEGIN grumble 0= WHILE mumble REPEAT Proposal: Add ALTHOUGH, BUT, and SO to the implementor's toolkit. ALTHOUGH (The definition of ALTHOUGH should be cannibalized from the current definition of IF by replacing references to conditional branching with unconditional branching.) ----- This message came from GEnie via willett. You cannot Reply to the author using email. Please post a follow-up article, or use any instructions the author may have included (USMail addresses, telephone #, whatever). Report problems to: dwp@willett.pgh.pa.us or uunet!willett!dwp