PrintStar's Blog
Ramblings of a Fortran Nut
November 29, 2011 by Jeff

Certified Novelist!

Today, just a few minutes ago, I became a certified novelist. I successfully complete the 2011 National Novel Writing Month by writing, from scratch, an original 52,099 word novel.  For the entire month of November, I’ve been toiling over my Tandy Model 102 laptop trying to write a contiguous 50K+ word story.  This evening I was able to write a short Epilogue, completing the story.  I had been using a combination of OpenOffice and a custom BASIC program on the Tandy laptop to count my progress during the month.  Moments ago, I concatenated the twenty chapters and uploaded the new novel Bringing Balance to the NaNoWriMo site for certification.  I was thrilled when the message, “Congratulations, novelist! You’ve won!” appeared in my web browser!

I think my wife deserves some serious thanks for letting me get away with skirting some responsibilities during November in a quest to complete this book.  Everyone should give this contest a try at some point.  The whole process is fun, stressful, exciting, and fulfilling.

  •   •   •   •   •
October 18, 2011 by Jeff

Displaying a Project’s Organization

Simply Fortran has been out for well over a year now, and people generally seem happy with the development environment.  The whole package has grown by leaps and bounds from its initial release.  Of course, there’s plenty of space for improvement.

One user suggested the ability to display the entire project’s structure rather than the structure of a single source file.   Currently an outline for a file currently present in the editor can be viewed and used for simple navigation.  The background parsing engines attempt to determine the location of all Fortran modules, functions, and subroutines within the file, and an outline is built from the parsing results.  Furthermore, other languages, including C, Python, and Makefiles, are also supported.  However, in a project with many source files, there is significant value to building a project-level outline tree.

Displaying the overall project structure is the real dilemma.  Simply Fortran uses a project tree to display all files within a given project, and this tree is not fixed to the file system.  In other words, users can create folders and organize source files without creating a matching, underlying file organization on the disk.

If a project’s entire tree were to be displayed, there are a few options for doing so.  The easiest route would be to expand the single file outline panel to display the overall project outline.  However, should the outline organize by  files, then source components, or should the idea of a “file” be removed from this outline?  The other option might be to enhance the project tree to allow expanding files to examine their source components.  The project tree is already an abstract representation of the project, and the organization reflects the user’s preferences.  Adding source components would be no simple task, though.  And if the file outlines were accessible in the project tree, is there still a need for the single-file outlines?

The simplest solution might be to retain the current outline panel but add new controls to allow showing a global list of available source components rather than only those in the file.  This outline style would probably then ignore the idea of which file owns a given module, function, or subroutine.  Additionally, a search box could be added to sort through components of a large project.  Adding a search box, however, might possibly negate the need for some other Simply Fortran component panels, specifically the module browser and the component search panel.

A whole-project outline is a difficult concept to visualize and implement, but it is assuredly a powerful tool.

  •   •   •   •   •
July 30, 2011 by Jeff

RetroChallenge Finale!

I’m currently typing this from PyOhio about two hours before my talk is scheduled to begin. Today I’ll be presenting the product of this month’s RetroChallenge, a successful port of Python 2.7 to the Atari platform and a partial, but working, module for interfacing with GEM. This presentation will involve a live demo of the gempy module along with some example programs. Good times!

  •   •   •   •   •
July 18, 2011 by Jeff

A Long Time Without Updates

As usual life is getting in the way of RetroChallenge.  I’m just coming off a busy weekend with a visit from my sister and her husband, and I’m ready to get back into the challenge.  Leading up to this past weekend was plenty busy, so I was forced to sacrifice my posting in favor of actual progress towards my goal.

If you look at gempy’s GitHub page, you’ll notice that some significant progress has been achieved.  At this point, I’ve implemented wrappers for all the AES (Application Environment Services) calls that I plan to for this challenge, along with a select grouping of useful extras.  If I am to re-implement GEM Worm under Python, I’ll still need to wrap a selection VDI (Video Device Interface) calls.  However, with some AES functionality present in theory, now is a great time to stop and begin testing.

My first compile attempt since my Pythonic code organization was decided upon was not successful.  Most of the errors, I’m hoping, are simply typos and lazy programming.  I don’t believe I have any showstoppers at this time, but time is not on my side.  I have approximately two weeks remaining, and I still need to author and practice a presentation for PyOhio.  I think everything is still possible, but it’ll be tight.

  •   •   •   •   •
July 10, 2011 by Jeff

Working from Github

To make development of the GEM Python module a bit easier, I’ve created a new repository on Github:

I normally work from a handful of systems, and carting around a USB key with the source code on it gets old after a while.  I think working from a source control system will make development of this module much easier.

I’m currently trying to outline what exactly I’m going to try to implement for this challenge.  I went back and examined the source code for GEM Worm to try to find which GEM calls I really wanted implemented by the end of the month.  However, I hope to complete everything in a sensible manner so I can later go back and implement some unfinished bits.

  •   •   •   •   •
July 9, 2011 by Jeff

Mild Success with Shared Libraries

After my last post outlining an “Abort” issued by Python when attempting to load a shared module, I realized I had made some pretty basic errors in my implementation.  The gist of the issue is that I linked my shared module to the static Python runtime library in order to resolve dependencies.  When I called some Python C API routines, they were not calling the appropriate procedures within the Python process.  The explanation above, however, does require a brief overview of the Atari’s shared library architecture.

A shared library built on the Atari using the LDG method is not strictly a library, but, rather, a highly specialized executable.  If you look at the source code I’ve provided below, you’ll notice that the library code includes a main() function.  When an LDG file is executed, it normally issues a message saying that it is a shared library.

The original LDG design was basically a one-directional shared library.  The process that loads the shared library can call into the shared library, but the reverse was not possible.  This functionality is problematic when using a system as complicated as CPython because many calls will affect global interpreter information, such as the garbage collection system or the namespace.  If my shared library needs to call a Python C API function, it needs to call the appropriate function within the executable that loaded the shared library.  The two processes (client and it’s shared library) are not strictly sharing memory, so the shared library will be performing operations only within its own memory space.  The SIGABRT was most likely issued because I attempted to initialize a Python module within a process address space that had absolutely no initialization of a Python interpreter.

The most recent version of the LDG library provides a workaround for this one-directional shortcoming.  The library implements ldg_callback(), which allows the shared library to call back into the originating process.  The problem is that ldg_callback() must be provided with a function pointer.  To use this callback functionality with the Python C API, the Python process would have to provide a complete list of function addresses to the shared library.

This solution isn’t particularly practical for general implementation.  The Python C API is substantial, so passing all the functions might be a bit troublesome.  While implementing the solution is certainly possible, it might take quite some time.

I did, however, go back to generate at least a skeleton of how things would need to work.  Rather than just leaping into initializing a module in a shared library, the MiNT implementation first loads the library and passes an array of function addresses into the shared library for use.  The shared library, meanwhile, contains re-definitions of necessary functions via preprocessor macros to call ldg_callback() with the proper entry in the array of function pointers.  The whole thing is a bit unwieldy, but…

The shared gem library does, in fact, work.  I was able to call appl_init(), followed by form_alert(), followed finally by appl_exit().  There continue to be some minor issues, namely that the version information that the shared library supplies to Python is clearly incorrect.  Although the shared library implementation is somewhat impractical, I believe I’ll continue to work within a GEM shared library for the remainder of this challenge if not solely to take advantage of the significantly faster turnaround when adding features as compared to rebuilding Python.  Here’s a screenshot for some proof of progress:

If anyone feels like looking, I’ve again included some source code:

  • dynload_mint.c – The most minimal implementation necessary to get my demo code running
  • gem.c – A functioning GEM module with three whole functions!
  •   •   •   •   •
July 7, 2011 by Jeff

Trudging into Shared Libraries

I’ve been struggling since last post with building some shared library functionality into Python for the Atari.  As I stated, Atari’s use Librairies Dynamiques GEM (LDG) for shared library support.  While not exactly as easy as shared libraries on something like, say, GNU/Linux, the system is functional.

I’ve implemented the basics of the routines necessary to bring shared libraries to Python on the Atari in a file called dynload_mint.c, which is equivalent to the files provided in the standard Python distribution for other operating systems.  The contents are available here:

The routine is actually simple, but to get everything compiling, I had to modify the autogenerated Makefile for Python as well as a configuration file (pyconfig.h) to enable dynamic libraries.  I also wrote the simplest of GEM modules for Python providing 3 basic functions:

  1. appl_init() – to notify the Application Environment Service that a GEM program is starting
  2. appl_exit() – to notify the Application Environment Service that a GEM program is closing
  3. form_alert() - display a message box

This extension actually statically compiles and links with the Python executable just fine.  It even works!  It seems like a good candidate for testing shared libraries.

  • gem.c – A minimalist GEM module for Python

The code above contains some of the supporting LDG code as well.  After compiling to a shared library, I was able to try importing the module, and I was greeted with “Abort,” and nothing more.

Obviously something isn’t working quite right.  I’ll need to do some more research into what exactly is occurring.

On a somewhat unrelated note, my home router has been experiencing some serious wireless connection issues.  This blog may go down on occasion due to flaky Netgear engineering.

  •   •   •   •   •
July 4, 2011 by Jeff

Getting Started with Shared Libraries

In preparation for attempting to bring shared libraries to the Atari port of Python, I decided to tackle a simple example.  The development libraries for shared libraries on the Atari, LDG, comes with a rather complex example involving a GEM program (GUI, not just plain text).  To prepare my emulation environment, I downloaded and installed the LDG RPM (FreeMiNT users generally rely on the SpareMiNT distribution these days, which is RPM-based).  GNU/Linux users might already be familiar with RPM’s, but for others, RPM’s are simply easily installable packages with dependency checking.

The LDG development package’s demonstration project also required Windom, an alternative GEM programming API that has enjoyed reasonable popularity among Atari developers.  Luckily, an RPM was also available for Windom.  Once everything was setup, I gave compiling the example application a try.  Of course everything failed.  Looking at the makefiles involved, I was disappointed to see that the makefiles contained a significant number of hard-coded paths from the original developer’s home directory.  After fixing these faux pas, I still received compilation errors.  The errors appeared to be related to the Windom API, a library which I’m not particularly interested in at the moment.  I believe the errors are caused by Windom version differences; the demonstration program relied on 1.x Windom APIs, while my system features 2.x Windom.

I decided to try a simpler example.  Specifically, the demonstration program relied on bindings compiled into the calling client program.  For Python extensions to work, bindings simply can’t be compiled into the main Python executable.  A blind loading attempt was necessary.  I wrote a simple example that loads a sine calculation from a shared library, calls the function, and exits.  I’ve included the two sources below:

The above programs did surprisingly work, which gives me hope for implementing shared libraries for Python on the Atari.  I’ll have some more things to try tomorrow.

  •   •   •   •   •
July 3, 2011 by Jeff

RetroChallenge 2011 Gets Started!

I was a little late registering an entry, but I’m all signed up for this year’s RetroChallenge.  This year I’ll be returning to work on my Ataris in an effort to bring modern Python variants to the 32-bit Atari computers.  Specifically, I’ll be attempting to compile and run Python 2.7 and (possibly) Python 3.2 under the FreeMiNT operating system on both actual Atari hardware and the ARAnyM virtual machine.  Currently Python 2.3 is available for the Atari, but I’d like to see more modern versions available along with their useful language additions.

This challenge is actually coupled to a presentation I’ll be giving on July 30th at the PyOhio conference.  At the presentation, I’ve made the sizable promises of both presenting the work I’ve completed and demonstrating live a module focused on writing GEM programs in Python.  This presentation adds considerable pressure to my challenge this year as I don’t have the soft goals that I’ve been able to exploit in the past.

I plan on attacking two big problems on the Atari.  For the first week or so, I plan to look into implementing shared libraries on the Atari in Python builds. While the Atari platform does rely on GNU C Compiler (amongst other compilers), it does not support shared libraries in the same way that many Linux or *BSD users might be used to.  Instead, the Atari relies on GEM Dynamical Libraries, which are not exactly the same as a Linux-esque shared library.  Python uses native libraries for many modules, both standard library components and countless external extensions.  Without shared libraries in Python, any necessary modules need to be compiled into the main Python executable.

Second, and regardless of the success of my first task, I plan to implement a simple module that can access the many GEM GUI routines.  The GEM API is, however, substantial.  My plan is to implement just enough to get some basic GEM applications running.  I think a reasonable goal is to implement enough of the GEM API to reproduce my previous RetroChallenge entry, GEM Worm, in Python.  This task will require, at the very least, GEM resource file handling, event loops, basic graphical drawing, and some application initialization routines.

I’ve already successfully compiled Python 2.7 with some minor modifications on an emulator. While this achievement is an encouraging start, a long road remains.

  •   •   •   •   •
March 8, 2011 by Jeff

pydare Now Hosted on Google Code

In preparation for PyCon US 2011 and with SciPy’s latest release supporting Python 3, I decided to make some updates to my pydare package.  Specifically, I decided to confirm that pydare could work under Python 3.  The pydare package is entirely pure Python, so I didn’t foresee any real issues.  The transition to work under Python 3 was rather seamless.

However, distributing a Zip file through this blog is far less than ideal.  I decided to move to Google Code for source control and distribution:

In order to take full advantage of pydare, Slycot also needed to be updated for Python 3 compatibility.  Most of the changes necessary in Slycot were minor import path corrections and indentation fixes.  The master branch of Slycot does work flawlessly with Python 3 at this point.

  •   •   •   •   •