TweetFollow Us on Twitter

LS FORTRAN 2.1, Forth
Volume Number:6
Issue Number:10
Column Tag:Jörg's Folder

LS FORTRAN 2.1; Forth News

By Jörg Langowski, MacTutor Editorial Board

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

After our excursions into the world of MacApp and C++ (which will be continued), this month will get us back to FORTRAN and Forth - somewhat closer to the ground, some may say. Language Systems just sent me their latest update of FORTRAN for MPW, and I’d like to show you some of its new features.

FORTRAN background processing

One of the main improvements is automatic background execution. Assume you are porting a program from a mainframe to the Macintosh. FORTRAN programs on big machines are often written to compute some output, given some input, in a rather ‘linear’ style, that is, user interaction occurs only at some predefined points in the program. As an avid reader of this magazine you will know by now that Macintosh programming (and, for that matter, programming of other graphical user interfaces such as XWindows or MS Windows) is done differently; the program should only do small pieces of its operation at a time, and check for user events (mouse down, key down, etc.) as often as possible. This is done by making the program cycle through a main ‘event loop’, and do time-intensive tasks only at times when there are no such events to be handled.

The average data treatment, curve fitting, numerical simulation, etc. program that has been running on a VAX or some other machine will not be structured with a graphical user interface in mind. It will also be several thousand lines long, have gone through the hands of three generations of programmers, and, politely speaking, not adequately documented. However, it works, so how can we port it to the Macintosh with the least hassle, but please make it run in the background so that the work gets done while one is preparing the paper which was due three days ago (as I’m doing right now with this column, while a Fortran program is actually running in the background)?

One must find a mechanism by which the computation is broken up into little pieces, after which the program can return control to the operating system. As some of you might recall, a while ago I presented such a mechanism: at each point where you want the program to return control, insert a call to WaitNextEvent with an event mask that checks only for update and suspend/resume events. As long as WaitNextEvent receives only null events at those control points, the program will continue to do its work, advancing from WaitNextEvent to WaitNextEvent, whether it is in the foreground or in the background. When the mouse is clicked, the usual task switching will occur.

Of course, one must be careful about placing the WaitNextEvent calls; spaced too far apart, foreground execution of other applications will be ‘chunky’ when the program is turning in the background, and too many calls can slow down the Fortran program considerably.

Language Systems, in its Fortran 2.1, has integrated a ‘be-nice’ routine, F_DoBackground, into their libraries. A call to this routine causes events to be checked, and if necessary, control will be transferred to another process.

It would still be a lot of work to include calls to this routine into an existing Fortran program; therefore the 2.1 compiler adds a new option, -bkg=n, to its command line switches. If you use this switch with n greater than 0, you tell the compiler to add calls to F_DoBackground to your code automatically. The value of n controls the frequency at which calls to the backgrounding routine are made:

n=0: the default (and the way the old compiler worked): background processing is possible only during input/output to the console window.

n=1: F_DoBackground is called during file operations or console I/O.

n=2: F_DoBackground is called at each entry to a subroutine or function.

n=3: F_DoBackground is called before each labeled statement.

n=4: F_DoBackground is called inside each DO loop.

There are more possibilities to influence the frequency of F_DoBackground calls. Another library routine, F_SetBackInterval(ticks) will tell the system not to do a background call unless the specified number of ticks have elapsed, if otherwise your program would slow down unnecessarily. If you have some critical code that has to run uninterrupted, you can also insert a compiler switch into your source code that turns off the automatic insertion of background calls, and later turn it back on again.

Some Benchmarks

I have checked the backgrounding capabilities of Fortran 2.1, running a rather extensive curve fitting program that consists of several tens of modules that call each other, together with some subroutines for matrix operations. The program consists of two parts, an initialization part which is one rather lengthy calculation, and the curve fitting itself which runs iteratively, writing intermediate results to disk on each loop.

All results have been obtained on a MacIIx at Fortran optimization level 3. Using the old Fortran 2.0, the program used 43 s for the first part and 715 s for 65 iterations of the second part. The new Fortran 2.1 cut the execution time down to 38 s for the first part and 595 s for the second part, using backgrounding levels of 0 or 2 and running the program in the foreground.

If the backgrounding level is set to its maximum of 4 (that is, background calls on every labeled statement and in every DO loop) for all parts of the program except the low-level matrix algebra routines, the program executes quite nicely in the background and one can do some other work in a reasonable way. Typing text into WriteNow while the program was running, its execution time was slowed down to 40 s for the first and 690 s for the second part; still faster than for the previous Fortran version.

As you see from these numbers, code generation was also improved compared with Fortran 2.0. Not all benchmarks run faster, though; the single precision Whetstone program still ran at 1050 whetstones/s, which is close to the old value.

Incidentally, I have not received a copy of the new Absoft MacFortran II for testing yet; I would certainly like to compare that compiler to LS Fortran. In their latest ad - here in MacTutor - they claim their code is more than twice as fast than Language Systems’ (for the Whetstone benchmark). I would like to verify this and tell you about it in a later column. Absoft, are you listening?

Object-oriented Forth: Mops, a NEON clone

Some months ago (V6#5) I told you about a NEON clone that had been created by Michael Hore in Australia. He baptized his product Mops, for Michael’s Object Programming System. I would like to describe Mops in more detail now, and give you some programming examples.

First, for those of you who have never heard about NEON, I’d like to recall quickly the most basic facts about this object-oriented programming environment. Several years ago, Charles Duff created NEON which was then marketed by Kriya Systems. It was a language based on Forth, but let users write object-oriented code in a very non-Forth like manner. For instance, if you had defined a class of drawable objects, shape, you could declare

shape a
shape b
and then write 
draw: a
draw: b

which would display those objects according to a draw method defined in the class declaration. That method, in turn, would be written in a mixture of Forth and method calls like the ones you’ve just seen. A class declaration in NEON looked like

:class circle <super shape
\ instance variables
 point center
 int radius
\method declarations
 :m draw: 
\ code for draw: follows here
 ;m

 :m init:
\ initialization code follows here
 ;m
\ etc. etc.

;class \ end of circle declaration

Unfortunately, Kriya stopped updating - and selling - NEON a while ago, and the problem whether its source code is ever being made public domain is unsolved as yet. And might remain unsolved for a long time

Thus, and I wrote some notes about that in May, several people set out to iron out bugs in NEON, make it work with new Macintosh system releases, or even re-implement it from scratch. Mops is such a NEON reimplementation that is public domain. After (hopefully) watering your mouth for that system, I’d like to give you some details this time and encourage you to write to Michael at the address given at the end of this column. If you send him two disks he’ll copy Mops to it and send it to you. Now, some extracts from the Mops documentation:

“In Mops, we had the problem that native 68000 code only allows a 16-bit displacement for addressing [note that Mops uses subroutine-threaded code, just like Mach2 - JL] , every part of the dictionary must be within 32K of where an A register is pointing. The 68020/030 chips have a 32-bit displacement mode, but the 68000 doesn’t. The eventual solution was to dedicate three A registers for addressing. Mops uses A3 and A4 to address the main dictionary - these registers are set up with A4 pointing 64K higher than A3, and these two registers never change during execution. This way we can address a dictionary up to 128K in size. We call A3 “lobase” and A4 “hibase”. This scheme doesn’t really limit the total size of an application, however, since any number of modules can be used. These are addressed using A5 (“modbase”). Since Neon never allows a module to be accessed from outside except through an exported word, we maintain this rule in Mops, and thus we can ensure that A5 is always valid when a module is in execution.

We use A6 as the data stack pointer, and A7 as the return stack pointer. a Mops word can be called with a simple BSR instruction, and nothing further needs to be done with the return address, since it is already on the top of the return stack. All the words which call the system (such as TRAP) exchange A6 and A7 before the system trap, and then exchange them back on return.

In Mops we have been able to eliminate the methods stack. we use A2 for the base address of the current object in methods, and save nested object addresses on the return stack. We use D3-D7 for named parameters and local variables, and save as many as necessary on the return stack during nested definitions. Although this restricts us to 5 of named parms/locals instead of 6, I judged the gain in performance and the ability to eliminate the methods stack was worth it. Actually, in definitions with DO loops we can only have 4 parms/locals, since we use D3 for the loop variable I. I haven’t found this a very serious restriction in practice.

So to summarize the register usage:

D0-2  scratch
D3 I
D3-7  named parms/locals 
 (D3 available when not in a DO loop)
A0-1  scratch
A3 lobase
A4 hibase
A5 modbase
A6 data stack pointer
A7 return stack pointer

For speed, we normally hold all addresses in absolute form. We don’t therefore need the words +base and -base, and when doing @ etc. we don’t need an indexing step. This does mean, however, that we have to do some juggling to handle addresses that are stored in the dictionary and then saved in a dictionary image which is reloaded later at a different place in memory. For this kind of operation we have defined a relocatable address format, and the words reloc! and >abs to do the conversion The most common need for a relocatable address is for vectors.”

This was just to give you a look at some of Mops’ internals. Mops code looks very much like the old NEON code, with some cosmetic differences that come from the fact that Michael wanted to make the Forth syntax closer to the Forth-83 standard, and some syntax changes especially for late binding and heap object creation.

Differences to NEON

In NEON, when you wanted to send a message to an object whose address was on the stack but whose class was determined only at run time, you wrote:

message: [ object_address ]

Since Michael Hore wanted to use the square brackets for its original purpose, namely to turn compilation off and on, he changed that syntax to:

object_address message: **

When you wanted to create objects dynamically on the heap at run time in NEON, you wrote heap> classname which created an object of the appropriate class on the heap and left its address on the stack. In Mops, heap objects are handles, which themselves are objects to which messages can be passed. So in order to create a new object dynamically, now you first have to define a handle:

handle h1

and then use newObj: to create a heap object that this handle refers to:

‘ classname newObj: h1

You can lock the handle and get a pointer to the object by writing obj: h1. If you store that object pointer elsewhere (e.g. in an array as we do it in our example), you can re-use the handle and assign a new heap object to it. This is the way an array of towers and a list of disks on those towers is created in the Hanoi towers example in the listing.

Multiple inheritance

Mops also changes the syntax of superclass references in a class definition to implement multiple inheritance. Instead of writing, as in NEON

:class a <super b

you now write

:class a super( b c d )

where b c d are the classes from which a is derived.

There are more new features in Mops, such as optimization of the subroutine-threaded code, inline definitions and an assembly level debugger/decompiler. If you are interested, you should write to Michael and send two blank disks to get the whole system. Even though the version that I have still crashes sometimes, and the Install facility doesn’t work for me yet, it is a very interesting product and promises a great future.

I include the example code, the Mops kernel, the basic dictionary and some auxiliary files on the source code disk. To run the code, double-click the dictionary icon and select Load from the file menu when Mops has started up. Then load the demo code; ignore a warning message that comes up and simply type <return>. Start the demo by typing doit <return>.

The address of Michael Hore again, with some last comments of his own:

“I think I probably have a copyright on the Mops nucleus, which is pretty well completely original. This may well apply to a lot of the high-level stuff as well. Anyway, to the extent to which this is so, I’m releasing it into the public domain. Please address all comments, queries and (gasp!) bug reports to:

Michael Hore

Numbulwar,

via Katherine NT 0852,

AUSTRALIA.

I’ll do my best to respond to comments, etc. Even the bug reports.”

Thank you, Michael. Those of you who have access to Internet/Bitnet can as usual send mail to me at langowski@frembl51.bitnet. I’ll do my best to respond, too; in case you have trouble reaching Michael, I can also send a Stuffit file with the complete Mops system.

Happy threading.

Listing 1: Hanoi towers example in Mops

( Towers of hanoi in Mops )
( Aug. 90 jl )
( adapted from the NEON example in V2#1 )

: hanoi-towers ; \ for easy forgetting

:class tower super( ordered-col )
 rect base
 rect column
 int xcenter
 int ycenter

 :M classinit: ( xcenter ycenter -- ) 
 put: ycenter put: xcenter 
 get: xcenter 70 - get: ycenter 16 - 
 get: xcenter 70 + get: ycenter  put: base
 get: xcenter 4 -get: ycenter 
 limit: self 10 * 50 +  -
 get: xcenter 4 +get: ycenter 16 - put: column 
 ;M

 :M draw: 0 syspat dup fill: base fill: column ;M
 :M getX: get: xcenter ;M
 :M getY: get: ycenter ;M

;class

:class disk super( object )
 int size
 var which
 rect image
 int xc int yc

 :M classinit: ( which size -- ) 
 put: sizeput: which 
 addr: self get: which add: ** ;M

 :M draw: 
 get: which getX: ** put: xc 
 get: which getY: ** 12 - 
 get: which size: ** 10 * - put: yc
 get: xc get: size - get: yc 4-  
 get: xc get: size + get: yc 4+  put: image
 3 syspat fill: imagedraw: image 
 ;M

 :M undraw: 19 syspat fill: image
 get: xc 4- get: yc 4- 
 get: xc 4+ get: yc 4+  put: image
 0 syspat fill: image
 ;M

 :M move: { dest -- }
 undraw: self
 addr: self dest add: **
 get: which size: ** 1- get: which remove: **
 dest put: which
 draw: self
 ;M
 
;class

3 array towers

handle tw
 
: make.towers { ndisks -- }
 3 0 do i 150 * 100 +280 ndisks [‘] tower newObj: tw
 obj: twi to: towers loop ;

: draw.towers
 3 0 do i at: towers draw: ** loop ;

: dispose.towers 3 0 do i at: towers dispose: ** loop ;

: hanoi { n start inter finish -- }
 n if n 1-start finish inter hanoi
 finish at: towers start at: towerslast: ** move: **
 n 1- inter start finish hanoi
 then
;

: main  { ndisks -- }
 ndisks make.towerscls draw.towers
 ndisks 0 do 
 0 at: towers 6 ndisks i - 4* + 
 [‘] disk newObj: tw drop 
 0 at: towers  last: ** draw: ** 
 loop
;

: doit
 show: fwindselect: fwind 
 10 main
 10 0 1 2 hanoi
;

: demo doit bye ;

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Chromium 119.0.6044.0 - Fast and stable...
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. List of changes available here. Version for Apple... Read more
Spotify 1.2.21.1104 - Stream music, crea...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue puts... Read more
Tor Browser 12.5.5 - Anonymize Web brows...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Malwarebytes 4.21.9.5141 - Adware remova...
Malwarebytes (was AdwareMedic) helps you get your Mac experience back. Malwarebytes scans for and removes code that degrades system performance or attacks your system. Making your Mac once again your... Read more
TinkerTool 9.5 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Paragon NTFS 15.11.839 - Provides full r...
Paragon NTFS breaks down the barriers between Windows and macOS. Paragon NTFS effectively solves the communication problems between the Mac system and NTFS. Write, edit, copy, move, delete files on... Read more
Apple Safari 17 - Apple's Web brows...
Apple Safari is Apple's web browser that comes bundled with the most recent macOS. Safari is faster and more energy efficient than other browsers, so sites are more responsive and your notebook... Read more
Firefox 118.0 - Fast, safe Web browser.
Firefox offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals and casual... Read more
ClamXAV 3.6.1 - Virus checker based on C...
ClamXAV is a popular virus checker for OS X. Time to take control ClamXAV keeps threats at bay and puts you firmly in charge of your Mac’s security. Scan a specific file or your entire hard drive.... Read more
SuperDuper! 3.8 - Advanced disk cloning/...
SuperDuper! is an advanced, yet easy to use disk copying program. It can, of course, make a straight copy, or "clone" - useful when you want to move all your data from one machine to another, or do a... Read more

Latest Forum Discussions

See All

‘Monster Hunter Now’ October Events Incl...
Niantic and Capcom have just announced this month’s plans for the real world hunting action RPG Monster Hunter Now (Free) for iOS and Android. If you’ve not played it yet, read my launch week review of it here. | Read more »
Listener Emails and the iPhone 15! – The...
In this week’s episode of The TouchArcade Show we finally get to a backlog of emails that have been hanging out in our inbox for, oh, about a month or so. We love getting emails as they always lead to interesting discussion about a variety of topics... | Read more »
TouchArcade Game of the Week: ‘Cypher 00...
This doesn’t happen too often, but occasionally there will be an Apple Arcade game that I adore so much I just have to pick it as the Game of the Week. Well, here we are, and Cypher 007 is one of those games. The big key point here is that Cypher... | Read more »
SwitchArcade Round-Up: ‘EA Sports FC 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 29th, 2023. In today’s article, we’ve got a ton of news to go over. Just a lot going on today, I suppose. After that, there are quite a few new releases to look at... | Read more »
‘Storyteller’ Mobile Review – Perfect fo...
I first played Daniel Benmergui’s Storyteller (Free) through its Nintendo Switch and Steam releases. Read my original review of it here. Since then, a lot of friends who played the game enjoyed it, but thought it was overpriced given the short... | Read more »
An Interview with the Legendary Yu Suzuk...
One of the cool things about my job is that every once in a while, I get to talk to the people behind the games. It’s always a pleasure. Well, today we have a really special one for you, dear friends. Mr. Yu Suzuki of Ys Net, the force behind such... | Read more »
New ‘Marvel Snap’ Update Has Balance Adj...
As we wait for the information on the new season to drop, we shall have to content ourselves with looking at the latest update to Marvel Snap (Free). It’s just a balance update, but it makes some very big changes that combined with the arrival of... | Read more »
‘Honkai Star Rail’ Version 1.4 Update Re...
At Sony’s recently-aired presentation, HoYoverse announced the Honkai Star Rail (Free) PS5 release date. Most people speculated that the next major update would arrive alongside the PS5 release. | Read more »
‘Omniheroes’ Major Update “Tide’s Cadenc...
What secrets do the depths of the sea hold? Omniheroes is revealing the mysteries of the deep with its latest “Tide’s Cadence" update, where you can look forward to scoring a free Valkyrie and limited skin among other login rewards like the 2nd... | Read more »
Recruit yourself some run-and-gun royalt...
It is always nice to see the return of a series that has lost a bit of its global staying power, and thanks to Lilith Games' latest collaboration, Warpath will be playing host the the run-and-gun legend that is Metal Slug 3. [Read more] | Read more »

Price Scanner via MacPrices.net

Clearance M1 Max Mac Studio available today a...
Apple has clearance M1 Max Mac Studios available in their Certified Refurbished store for $270 off original MSRP. Each Mac Studio comes with Apple’s one-year warranty, and shipping is free: – Mac... Read more
Apple continues to offer 24-inch iMacs for up...
Apple has a full range of 24-inch M1 iMacs available today in their Certified Refurbished store. Models are available starting at only $1099 and range up to $260 off original MSRP. Each iMac is in... Read more
Final weekend for Apple’s 2023 Back to School...
This is the final weekend for Apple’s Back to School Promotion 2023. It remains active until Monday, October 2nd. Education customers receive a free $150 Apple Gift Card with the purchase of a new... Read more
Apple drops prices on refurbished 13-inch M2...
Apple has dropped prices on standard-configuration 13″ M2 MacBook Pros, Certified Refurbished, to as low as $1099 and ranging up to $230 off MSRP. These are the cheapest 13″ M2 MacBook Pros for sale... Read more
14-inch M2 Max MacBook Pro on sale for $300 o...
B&H Photo has the Space Gray 14″ 30-Core GPU M2 Max MacBook Pro in stock and on sale today for $2799 including free 1-2 day shipping. Their price is $300 off Apple’s MSRP, and it’s the lowest... Read more
Apple is now selling Certified Refurbished M2...
Apple has added a full line of standard-configuration M2 Max and M2 Ultra Mac Studios available in their Certified Refurbished section starting at only $1699 and ranging up to $600 off MSRP. Each Mac... Read more
New sale: 13-inch M2 MacBook Airs starting at...
B&H Photo has 13″ MacBook Airs with M2 CPUs in stock today and on sale for $200 off Apple’s MSRP with prices available starting at only $899. Free 1-2 day delivery is available to most US... Read more
Apple has all 15-inch M2 MacBook Airs in stoc...
Apple has Certified Refurbished 15″ M2 MacBook Airs in stock today starting at only $1099 and ranging up to $230 off MSRP. These are the cheapest M2-powered 15″ MacBook Airs for sale today at Apple.... Read more
In stock: Clearance M1 Ultra Mac Studios for...
Apple has clearance M1 Ultra Mac Studios available in their Certified Refurbished store for $540 off original MSRP. Each Mac Studio comes with Apple’s one-year warranty, and shipping is free: – Mac... Read more
Back on sale: Apple’s M2 Mac minis for $100 o...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $100 –... Read more

Jobs Board

Licensed Dental Hygienist - *Apple* River -...
Park Dental Apple River in Somerset, WI is seeking a compassionate, professional Dental Hygienist to join our team-oriented practice. COMPETITIVE PAY AND SIGN-ON Read more
Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Sep 30, 2023 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
*Apple* / Mac Administrator - JAMF - Amentum...
Amentum is seeking an ** Apple / Mac Administrator - JAMF** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Child Care Teacher - Glenda Drive/ *Apple* V...
Child Care Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.