Fortran, AppMaker
Volume Number: | | 7
|
Issue Number: | | 10
|
Column Tag: | | Jörg's Folder
|
Language Systems FORTRAN and AppMaker
Jörg Langowski, MacTutor Editorial Board
Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.
After the comparative review of LS FORTRAN and Absoft MacFORTRAN, I received an invitation from Language Systems to review their interface to AppMaker, which simplifies creating Macintosh applications in Fortran a great deal. So here we go. First, even though AppMaker has been mentioned in our magazine, Id like to remind you briefly what it does.
AppMaker, from Bowers Development, is one of several products that lets you create a user interface graphically, and when you are satisfied with the look and feel of your program, create source code for a variety of programming languages. That source code, compiled and linked, will give a functional Macintosh application that has Apple, File, and Edit menus, together with the menus that you have defined, the windows have the correct basic behavior (e.g. grow, zoom, and resizeable scroll bars), desk accessories are supported and the whole thing is Multifinder compatible, etc. To make the controls and menu selections do something useful, you then have to add your own code that defines the actual functions of the different parts of the user interface.
AppMaker stands out from other programs (such as Prototyper) that do similar things in that it only controls the way certain predefined code segments are plugged together to make the application. These code segments are partially contained in libraries, for the code that is common to all applications, and in string resources in AppMaker itself, for code that changes depending on the user interface. If you are not satisfied with the way AppMaker creates the user interface, you can change any of these resources or libraries, because the source code is provided. And, most important, adding code generation for a new language becomes more or less straightforward (although I think adding a Forth interface to AppMaker would take too much of my spare time ).
Among the Fortrans for the Mac, the great advantage of LS Fortran is that Structure and Pointer definitions are available (even with some amount of type checking), which makes it very easy to create code that uses the Mac Toolbox interface. Thus, with AppMaker being around, Language Systems could easily add their own code generation part. It has been available for a while as Fortran Tools for AppMaker.
Do-Nothing example in LS Fortran/AppMaker
To see what Fortran Tools for AppMaker can do, Ive created the simplest do-nothing example application; it has Apple, File, and Edit menus, one resizeable, zoomable document window, and a couple of standard alerts, such as an About box. It can open and save documents, but does nothing with its contents; saved documents are empty. In order to create an application which does something useful, you have to insert your own code into the AppMaker-generated files in appropriate places. These places are usually well-marked (see listing).
Ive reprinted some of the AppMaker-generated Fortran code in the listing (not all of it, that would be too long). In our example you see the central dispatcher which calls event handlers for the various windows and modeless dialogs that could be present (only one in our case). The actual event handling routines are contained in the file MainWindow.f that is listed after the dispatcher. The logic is quite clear: the dispatcher decides which window the event belongs to, and calls the handler for that window. Who calls the dispatcher? It is called from the main event loop. Because all the behavior particular to the application can be put into the dispatcher and menu handler (not listed), the main event loop never changes, and its code can be contained in a library. When you purchase Fortran Tools, you get its source code, but I cant list it here for copyright reasons.
Thus you see, AppMaker gives you control over all details of the generated code. For instance, it wouldnt be too difficult to change the structure of the main event loop and the dispatcher code pieces to account for high-level events as required by System 7-aware applications. (For those of you who havent read through the System 7 documents: a high-level event can be sent from one application to another and, for instance, cause that application to open a document, or quit. An application can also sent such an event to itself; instead of calling a Quit handler directly when quit is selected from the File menu, the application will send a quit event to itself, and the high-level event handler will do the actual quit actions. More on this in my next column ).
Language Systems include several examples, where the simple do-nothing application has been extended for displaying graphics, handling text edit fields, etc., by adding only very few lines of Fortran code. Whatever your opinion (or religion) about Fortran as a programming language is, with LS Fortran and AppMaker you can certainly create application as easily and as well-documented as in Pascal or C. With the amount of scientific applications written in Fortran, the LS Fortran / AppMaker team is a very important tool that I recommend to anyone who considers transporting Fortran programs to the Mac.
In the near future you can expect more developments in LS Fortran, as I was told in a recent letter from Language Systems:
The integration of AppleEvents and Publish & Subscribe into FORTRAN programs was certainly the most popular part of our preview [at MacWorld Expo - JL].
one of our demos launches Excel via AppleEvents and directs it to open two documents. These documents subscribe to a data file published by the FORTRAN program. By selecting a menu item from our output window the user causes the published data file to be updated with random data. In the background Excel can be seen to update its worksheet and chart to reflect the new values. Finally, when the user quits the output window, Excel is also forced to quit via AppleEvents.
[Im really sorry I cant disclose the source code of that example here. It is amazing how elegant the interface to the Edition Manager works - JL]
We have also been hard at work on new optimizations, including some technology specific to the mc68040. We have improved our compatibility with Pascal and C and also with other FORTRANs such as Cray and Data General. Debugging features have been enhanced and the output window made more configurable.
The projected release date is early November, and we will send free upgrades to registered owners who purchased after June 1st.
Regards,
Guy McCarthy
Vice President
Research & Development
AppleLink: D1810 or LANGSYS
Forth mail
A couple of letters came in dealing with different Forths for the Macintosh (I should write an all-Forth column soon again, I think ). Bob Loewenstein gives an update on the latest version of his Neon-successor, Yerk:
Version 3.5 of Yerk, once known as Neon, is now available from anonymous ftp at oddjob.uchicago.edu in ~ftp/pub/Yerk. There are 5 files:
0. ReadMe.txt description
1. manual1.sit.hqx no change from Yerk version 3.2
2. manual2.sit.hqx no change from Yerk version 3.2
3. yerk.3.5.sit.hqx all source files and executables
4. supp.sit.hqx supplemental files; no change from Yerk version 3.2
If you are picking Yerk off for the first time, you will want these files.
Even though not all of the source files have changed from version 3.3.2, I recommend grabbing the yerk.3.5.sit.hqx file and archiving all of Yerk 3.3.2. Further upgrades from 3.5 will be posted with an file consisting of only those files that have been modified.
Version 3.5 is 32 bit clean and runs under system 7, but does not respond to AppleEvents. You may now create a stand-alone application, though, and hooks are in to help you make your program respond to High Level Events. See the ReadMe file and source Events.
Yerk is an object oriented language based on a Forth Kernel with some major modifications. It was originally known as Neon, developed and sold as a product by Kriya Systems from 1985 to 1989. Several of us at The University of Chicago have maintained Yerk since its demise as a product. Because of the possible trademark conflict that Kriya mentions, we picked the name Yerk, which is at least not an acronym for anything, but rather stands for Yerkes Observatory, part of the Department of Astronomy and Astrophysics at U of C.
Some features of the language are:
- defaulted early binding, with ability to late bind in almost any circumstance
- inheritance (not multiple)
- floating point (SANE)
- many system classes and objects for mac interfacing: windows, controls, events, files, arrays, ordered-columns, menus, hierarchical and popup menus, handles, strings, mouse, quickdraw, modal dialogs, offscreen bitmaps, vbl, time manager, etc.
- module (overlay) creation that are loaded only when necessary and may be purged from application heap memory.
Some forth extensions are:
- local input parameters
- named input variables
- multiple cfa words (including vectors and values)
- CASE
- SELECT
- 68000 assembler
Yerk runs on all macs from mac+ on up, and under all systems > 5.x. If anyone has any questions, feel free to contact me:
Bob Loewenstein
Dept. of Astronomy and Astrophysics
University of Chicago
Yerkes Observatory
Williams Bay, Wisconsin 53191
414-245-5555
rfl@oddjob.uchicago.edu
Mach2, too, still has its active users; after mentioning the Mach2 compatibility problems with System 7, I received this letter:
Jörg,
I was very relieved when I saw your article in the July MacTutor. I was afraid that you left the magazine since I had not seen your column in June. Reading your column is the only reason that I subscribe to the magazine since I am an avid Forth fan. [I see the hint - look for a new Forth column soon / JL]I am a scientist at the University of Utah and ignore the snobbery of most Mac programmers with respect to Forth. I am only interested in performance and Forth is by far the most productive programming environment for someone like me who can only hack in his spare time. Nevertheless, I have managed to create a sophisticated scientific program in MACH 2 Forth that has been commercially available for the last year.
The particular subject that prompted this note was your comment on the incompatibility between System 7 and MACH2. This is only partially correct. In the spirit of all true Forth hackers, I spent an afternoon modifying the system and it is now completely compatible (at least I have compiled dozens of programs with it on a Mac IIfx with System 7 without any problems at all). The modifications are really quite minor. You must install a modified event loop to become fully multifinder compatible (the one posted on the Genie bulletin board is *not* correct). Next you use ResEdit to set the size resource to reflect the changes and install the screen font (monaco 9pt I think) into MACH2 itself. Apparently MACH2 doesnt believe in TrueType fonts. Anyway, if your are interested in a fixed copy of MACH2 or a more detailed listing of the changes necessary to patch MACH2, just let me know and I will be glad to send them to you. [Definitely! E-mail is on its way / JL]I still do all my System 7 programming in MACH2. By using the trap compiler that was posted on the Genie bulletin board, I have implemented all of the new trap routines and have written programs that use color, offscreen devices, palette animation and so forth. Since I can modify my system (as you showed us how to do), I am always the first programmer I know who can use new enhancements on the Mac...
H. Steven Wiley (MacScientist)
Wiley@bioscience.utah.edu
[You might want to consider porting your code to MacFORTH since it is actively supported.-ed]
The author of Pocket Forth, Chris Heilman, has some good news for us, too:
Jörg,
I just got Augusts MacTutor, opened it to page 58, just to see whats up in the world of Forth, and low and behold, there is my name right in the middle of the page! Im a star! Thank you for the mention ( Starting with !!!). [Youre welcome. Your Forth is definitely one of the best ways for beginning and advanced hackers to get into the guts of the machine / JL]
Last May, I (and a lot of others) upgraded our systems to 7.0. Of course the compatibility checker had never heard of Pocket Forth (since I had never told Apple anything about it.) So, cautiously, I began to check it out.
The DA dragged out of the suitcase and ran just fine, although I found the generic icon to be kind of, well, generic. I put it through all the paces and tested the various addressing modes. The DA passed. Then on to the application (which in systems 6 and lower, I considered a poor cousin). First off neither it nor anything else would run in the background; then I tried 32 bit addressing mode. /\/Crash-ola\/\ It was not a pretty sight. I knew it would happen, but it was unpleasant to see it just the same. By the time I had rebooted, release 5 was being hatched.
Pocket Forth release 5 has now been completed. Release date: 11 July 1991, the date of the solar eclipse. Actually only a group of testers got it then, I put it on CompuServe and America Online a couple of weeks ago. Since then a few hundred people have received Pocket Forth, so it looks as if PASCs statement that there is no market for Forth is wrong (as long as the price is right). Pocket Forth is still priced within the reach of every programmer (free), and support is more available than ever before. I give out three addresses including CI$, Bitnet and mail. Anyone who gets it from America Online can also contact me there.
The new release consists of a self extracting archive that contains the application (now the star of the show), the DA, rewritten manual, updated glossary, the ReadMe application, a WhatIsNew text file for previous users, about a dozen examples, and every line of assembly source code (with instructions). Concurrent with the release, a new Rhine program (runs in color or black and white) was also released with an ad for Pocket Forth in its about box.
Pocket Forths new features: Fully compatible with System 7. High level events, balloon help, color icons (check out the girl in the DA), better menus, bugs fixed and numerous other enhancements have been added. Compatibility with release 4 and with all types of Macintosh (1984-1991) has been maintained.
Forth on the Mac scene, does indeed seem to be thinning out but with the work of us few, it is available, and being kept up to date. Recent coverage by the popular press suggests that efficient languages are no longer needed for general use, now that average memory sizes are measured in megabytes, and at 25 MHz even HyperCard is a speed daemon. Forth, however, is the language of choice for embedded systems.
[Of course the popular press is wrong, like so often. Even with fast machines, Hypercard is still slow if you do anything more advanced than opening a card by pressing a button. Mac users are used to immediate response (a point that is hard to get through to mainframe users), and even a 1/4 second delay between a user action and the program reaction can seem very slow. / JL]
While languages like C and Pascal are politically correct (and they carry their banners to battle), Forth is losing its religious zealots. No longer are there claims that Forth programs are half the size of assembly and run twice as fast. And improperly commented code is impossible to read, even if written in Forth. Other languages now base their popularity on the language itself, while Forth has become judged by its applications. I heard from somewhere that most of the experiments carried out on a recent space shuttle mission were written in Forth and that the software fix for the Hubble is also Forth.
It looks like Forth is very much alive, just used in different ways than it has been in the past. Keep up the good work and Im looking forward to an all Forth article soon.
PS If you dont have PF5 yet, let me know, Ill get to you.
Chris Heilman, Phoenix College, Chemistry:
Author of Pocket Forth
BITNET: heilman@pc (work) :
CompuServe: [70566,1474] (personal)
US Mail 85066-8345 (personal)
Listing: LS Fortran example code created by AppMaker
! Dispatcher.f -- dispatcher for windows and for modeless dialogs
! Created 8/27/91 9:37 by AppMaker
!!MP inlines.f
!!G JLtest.finc.f
!----------
!!D+
!!R+
!!OV+
!!S Dispatcher
!----------
Subroutine OpenWindows (fName, vRefNum, fRefNum)
String*255 fName
Integer*2 vRefNum, fRefNum
Call OpenMainWindow (fName, vRefNum, fRefNum)
End !OpenWindows
!----------
Subroutine CloseCurWindow
include Globals.inc
if(cur^.windowKind = WMainWindow) Call CloseMainWindow
End !CloseCurWindow
!----------
Subroutine MouseInContent (where, modifiers)
include Globals.inc
record /point/ where
integer*2 modifiers
if(cur^.windowKind = WMainWindow) Call MouseInMainWindow (where, modifiers)
End !MouseInContent
!----------
Subroutine TypeInWindow (ch)
include Globals.inc
character*1 ch
if(cur^.windowKind = WMainWindow) Call TypeInMainWindow (ch)
End !TypeInWindow
!----------
Subroutine UpdateContent
include Globals.inc
if(cur^.windowKind = WMainWindow) Call UpdateMainWindow
End !UpdateContent
!----------
Subroutine ActivateContent (activate)
include Globals.inc
logical activate
if(cur^.windowKind = WMainWindow) Call ActivateMainWindow (activate)
End !ActivateContent
!----------
Subroutine ResizeContent
include Globals.inc
if(cur^.windowKind = WMainWindow) Call ResizeMainWindow
End !ResizeContent
!----------
Subroutine ScrollWindow (newValue, oldValue)
include Globals.inc
integer*2 newValue, oldValue
if(cur^.windowKind = WMainWindow) Call ScrollMainWindow (newValue, oldValue)
End !ScrollWindow
!----------
Subroutine DoControl (whichControl, whichPart, where)
include Globals.inc
record /ControlHandle/ whichControl
integer*2 whichPart
record /point/ where
if(cur^.windowKind = WMainWindow) Call ControlMainWindow (whichControl,
whichPart, where)
End !DoControl
!----------
Subroutine InitModelessDialogs
End !InitModelessDialogs
!----------
Subroutine CloseModelessDialog (whichDialog)
pointer /dialogrecord/ whichDialog
End !CloseModelessDialog
!----------
Logical*2 Function FilterModeless (whichDialog, event, itemHit)
pointer /dialogrecord/ whichDialog
record /EventRecord/ event
integer*2 itemHit
End !FilterModeless
!----------
Subroutine DoModelessItem (whichDialog, itemNr)
pointer /Dialogrecord/ whichDialog
integer*2 itemNr
End !DoModelessItem
! MainWindow.f
! Created 8/27/91 9:37 by AppMaker
!!MP inlines.f
!!G JLtest.finc.f
!!D+
!!R+
!!OV+
!!S MainWindow
!----------
Subroutine OpenMainWindow (fName, vRefNum, fRefNum)
include Globals.inc
String*255 fName
integer*2 vRefNum, fRefNum
pointer /grafport/ newWindow
record /rect/ bounds
newWindow = GetNewWindow (MainWindowID, nil, INT4(-1))
Call SetWTitle (newWindow, %ref(fName))
Call SetPort (newWindow)
Call SetNewInfo (newWindow)
cur^.vScroll.Ctlh = nil
cur^.hScroll.Ctlh = nil
cur^.fileNum = fRefNum
cur^.volNum= vRefNum
cur^.dirty = .false.
cur^.filename.shdl = NewString (%ref(fName))
cur^.windowKind = WMainWindow
cur^.text.TEH = nil
!add code here: MainWindow open
Call ShowWindow (newWindow)
End !OpenMainWindow
!----------
Subroutine CloseMainWindow
include Globals.inc
Call DisposHandle (cur^.filename)
Call DiscardInfo (curWindow)
!add code here: MainWindow close
End !CloseMainWindow
!----------
Subroutine MouseInMainWindow (where, modifiers)
include Globals.inc
record /point/ where
integer*2 modifiers
record /rect/ bounds
!add code here: MainWindow mousedown
End !MouseInMainWindow
!----------
Subroutine TypeInMainWindow(ch)
include Globals.inc
Character*1 ch
if (cur^.text.TEH = nil) then
Call SysBeep (INT2(1))
else
Call TEKey (ch, cur^.text)
end if
!add code here: MainWindow keypress
End !TypeInMainWindow
!----------
Subroutine UpdateMainWindow
include Globals.inc
record /rect/ bounds
Call DrawClippedGrow (Int2(-15), Int2(-15))
!add code here: MainWindow update
End !UpdateMainWindow
!----------
Subroutine ActivateMainWindow (activate)
include globals.inc
logical activate
Call DrawClippedGrow (Int2(-15), Int2(-15))
!add code here: MainWindow activate
End !ActivateMainWindow
!----------
Subroutine ResizeMainWindow
include globals.inc
!add code here: MainWindow items resize
End !ResizeMainWindow
!----------
Subroutine ScrollMainWindow (newValue, oldValue)
include globals.inc
integer*2 newValue, oldValue
!add code here: MainWindow scroll
End !ScrollMainWindow
!----------
Subroutine ControlMainWindow (whichControl, whichPart, where)
include globals.inc
record /ControlHandle/ whichControl
Logical*2 TrackButton
External TrackButton
integer*2 whichPart
record /point/ where
record /rect/ bounds
End !ControlMainWindow