25 Years of 386-PROLOG

386-PROLOG - The First Quarter Century

On 2nd November 1989, the very first lines of 386 Assembler code were written by Brian D Steel, on a brand new product that he decided to call, "386-PROLOG". At that time, employed as LPA's senior programmer for MS-DOS products, he had been working on "PROLOG Professional", the final and most advanced version of the iconic "micro-PROLOG", that had seen service on everything from CP/M computers and the Sinclair Spectrum, to the Apple II and BBC Micro.

The Background: From 8 Bits to 16

The original micro-PROLOG was written by Frank McCabe as an 8-bit program for CP/M, with a simple Lisp-style syntax and a bare minimum of "clutter", to help it fit within the confines of the very limited memory of computers of the time. Few people could afford more than 16kb (kilobytes!) of memory, let alone a "full" complement of 64kb.

Employed as a research assistant in the Department of Computing, Imperial College, London, Brian had found a way to add high-resolution graphics to micro-PROLOG, creating a special version for the North Star Advantage. The graphics proved popular with his fellow researchers, and based on this work, he was offered the chance to port micro-PROLOG from the 8-bit Z80 chip, to the 16-bit 8086, which powered the brand new Sirius 1 and IBM PC. While maintaining his position at Imperial, he spent much of his spare time at home, painstakingly translating the source code for micro-PROLOG from its Z80 version, to the new 16-bit machine. Module by module, pieces of code began to run, followed, inevitably, by the dreaded "SYSTEM ABORT" message when some pointer ran out of range, or a routine was called that had not yet been written.

By 1983, a fairly stable version of micro-PROLOG 3.0 was running happily on the Sirius and IBM machines, and further development work on the 16-bit micro-PROLOG resulted in version 3.1 being released in 1984, simultaneously with the final release for Z80 machines. During the following months, a further version was created, with overlapping text windows and a WordStar-style command line editor, but this was never released to the public, instead being used solely by researchers at Imperial.

Pushing 16 Bits to 20 and More

Although it ran on the new 16-bit IBM PC (and many other machines supporting MS-DOS), micro-PROLOG still limited program and execution space to 64kb, and a complete rewrite of the core engine was needed. In 1984, Brian left Imperial to join LPA full time, and together with Frank McCabe, worked to produce what would come to be called, "PROLOG Professional". Using the segmented memory architecture of the 8086, this version could address up to 640kb of memory on the IBM-PC and its increasingly common "clones", and up to 1024kb (1Mb) on other MS-DOS machines such as the Sirius 1 and Apricot.

Larger memory lead to bigger programs, so changes to the micro-PROLOG syntax were introduced to support meaningful variable names, richer floating point maths, and much more. Although the system was still fundamentally based around a Lisp-style notation, support was also added for the increasingly common and de-factor standard, "Edinburgh" syntax. A faster, compiler based version of PROLOG Professional had been created in collaboration with Paul Parker, and eventually this compiler replaced the original interpreter as LPA's flagship product, although the latter was maintained for some further years for hobby purposes, in conjunction with his interest in Hewlett Packard's tiny MS-DOS handheld computers, such as the HP-100C.

While even the first version of PROLOG Professional gave programmers up to ten times the memory space than micro-PROLOG, it was not long before people were clamouring to use "Expanded" memory, or EMS. This somewhat cludgy technology was added to the system, allowing up to 4Mb of additional memory to be swapped in and out of the 8086 20-bit address space, enabling a form of RAM-based virtual memory, which worked with a reasonable degree of efficiency.

Intel 80386

The Intel 80836: 32 Bits

While PROLOG Professional continued to sell well, the arrival on the scene of Intel's 80386 processor was a major game changer. For the first time, it was possible to address a theoretical 4Gb (4096Mb) using a single pointer, rather than the previous 1Mb using a combination of a 16-bit (64kb) pointer and separate segment offset. It was plain that a direct translation of PROLOG Professional and its 16-bit code into 32 bits would not make the most of the new architecture, so it was decided to start over with a completely clean slate.

After much planning and consideration of different memory architectures and compiler models, the first lines of the new, 32-bit version of Prolog were written on 2nd November, 1989. The first version of the new Prolog engine was to run from the MS-DOS command line, using a 32-bit DOS Extender, licensed from Phar Lap, to give it full access to a 32-bit (4Gb) memory address space. The first routines were written: simple output, MS-DOS functions translated into their 32-bit equivalents, assorted declarations, and experimental heap allocation routines. Early days yet, but "386-PROLOG" was born.

For the next twelve months, writing in 386 Assembler language was non-stop, creating a new compiler instruction set, garbage collector, unification routines, essential predicates, input/output routines, error handlers and the entire paraphernalia which embody a Prolog engine. The new system included an extended Lisp syntax, similar to that of micro-PROLOG, but now encompassing four bracketed structure types, mapping to lists and executable tuples, conjunctions and disjunctions.

Early experimental code was written in this extended Lisp syntax, but by June 1990, work was undertaken to add Edinburgh style I/O right into the heart of the new system. It was at this point, that the first fragile, working prototypes of the new, 32-bit compiler could be handed over to others at LPA; Phil Vasey began to work on the "overlay", a Prolog file automatically loaded at system startup, which provides most of the familiar predicates of Edinburgh Prolog.

Version 1.0 of "386-PROLOG" was launched just over a year after those first lines of code had been written, and work continued to develop the system further, and fix the inevitable slew of bugs that were reported by back users of the first systems to be shipped.

Windows and MS-DOS

Simultaneously with the continued development of the new Prolog engine on 32-bit extended MS-DOS, work began on a Windows 3.0 compatible version of the system. The wisdom of choice of development language, namely 386 Assember, really proved itself. The assorted C and Pascal compilers of the day could not host code both on Windows and MS-DOS, nor were the DOS compilers compatible with the Windows ones in terms of syntax and run-time libraries. With Assembler, there were no such concerns: all that was required was to implement a mirror of the MS-DOS function libary, using Windows APIs to do the equivalent job.

In February 1992, version 1.100 of 386-PROLOG was announced simultaneously for MS-DOS and Windows. The name, "386-PROLOG", was retained in documentation to describe the common engine, but the names "DOS-PROLOG" and "WIN-PROLOG" were adopted as shorthand for "386-PROLOG for DOS" and "386-PROLOG for Windows", respectively. WIN-PROLOG was running as a hybrid 16/32 bit system: a 16-bit Windows executable provided the standard input/output features, including a selection of pre-compiled dialogs and alerts, together with user-programmable windows and a console, while all the "work" was being carried out inside the 32-bit 386-PROLOG module, running as a sperate, linked process.

Fast Forward to the Millennium Bug

Countless improvements were made to the 386-PROLOG engine over the next few years, resulting in frequent releases, often with spectacular new performance enhancements as well as with the occasional embarrassing bug being fixed. By July 1996, it was felt that the old WinMem32 hybrid version of WIN-PROLOG had reached the end of its useful life, and while it worked fine with Windows 95, it would not readily support the about-to-be-released, Windows NT. A final release of the hybrid system, version 3.3, had been made in April 1996, and work started on the business of redesigning the low level Windows API interface around the true 32-bit model, and just before Christmas, 1996, released version 3.5 internally at LPA, the first single-process version of WIN-PROLOG, where the 386-PROLOG engine was physically compiled and linked into the main executable file. A stable version 3.6 of the system was publically released in November 1997, ahead of a significant code review and substantial system rewrite.

Much had been made in the computing and public press, about the impending doom-laden evening of 31st January 1999, when, once second after 23:59:59, the lights would go out, aircraft would fall from the sky, and the world's banks, phone exchanges and more would grind to a halt. In ten years' continuous development, some of the clean code in 386-PROLOG had grown over complex, and it was decided to use the Hunt for the Millenium Bug as an excuse to revise much of the code and layout, while ensuring the entire system was immune from the "Y2K" (Year 2000) issue. Three internal release numbers were used up in the ensuing flurry or work, until in April 1999, version 4.0 was released to the public, proven to be safe from all Y2K issues.

Unicode, Syntax Colouring & Common Controls

And so the work went on. Support for highly efficient hashed compilation, supporting large databases like WordNet, and the full adoption of Unicode lead to the 4.2 release in October 2001, allowing programs and data to be written in any world language and character set. Support for Windows 3.1, which could host WIN-PROLOG using Win32s, was finally abandoned with the adoption of Rich Edit to support large program windows (formerly limited to 64kb of text per window), context-sensitive syntax colouring and a new, powerful console user interface complete with command history recall: version 4.3 arrived in June 2002. This version was also released internally, in a new, experimental form, as DLL-PROLOG, a fully-callable and micro-controllable Prolog subprocess that could efficiently be loaded into any running C/C++ application.

Another year, and the 386-PROLOG engine was enjoying the benefits of runtime memory save/restore routines, which both could be used to develop asynchronous server applications, and to support memory space reallocation at runtime without the need to quit Prolog and restart: these features were released with version 4.5 in July 2004; this version also saw the termination of Windows 95 support, following the inclusion of a number of common controls, such as nudge boxes, tabbed windows and tooltips.

MIDI for Music

TCP/IP Sockets, MIDI & Tries

TCP/IP, the primary connection language of the Internet, was built into version 4.6, released in September 2005; MIDI, the lingua franca of Musical Instruments, was included in version 4.7, in July 2007. Version 4.8, released in October 2008, included an advanced parallel text search based on "Tries", which in turn facilitated the creation of library files supporting efficient XML and Jason parsing routines; a final 4.x release, 4.9, was made in April 2011, consolidating the many changes that had taken place in the dozen or so years since the Y2K-safe release in 1999.

Version 5: New Floating Point

It was 2010, and another major code review was undertaken, this time replacing the legacy, third-party mathematics library, which was related to the one formerly incorporated into PROLOG Professional way back in 1986, with a brand new floating point library written from scratch, fully utilising the x87 processor. The change required system-wide modifications, and an extensive programme of complex testing, before finally being released July 2013 as version 5.0.

Happy 25th Birthday, 386-PROLOG

So here were are, 25 years after those first lines of code were written. 386-PROLOG is alive, well and kicking, currently ported to 6 different formats, including the DOS-, WIN- and DLL- varieties mentioned above, but also "BAT-" and "CON-" versions for MS-DOS and Windows command line applications respectively, and "TCP-", which replaces the console input and output streams with a TCP/IP link, allowing Prolog to talk directly to a remote client over a Telnet link.

While the 386-PROLOG engine has, thoughout the past 25 years, been the work of one individual, this is not to underplay the role of everyone else at LPA, who between them have been implementing and maintaining the LPA Toolkit Suite, from the flex Expert System & VisiRule executable business charts, to the ProWeb Server, WebFlex, Intelligence Server and much more. 386-PROLOG is the foundation stone of LPA's entire product range, which in turn comprises the creative output of an amazing team, all working tirelessly, over those same 25 years. Here's looking forward to the next 25 years!

Sixty-Four Bits

Version 7: 64 Bits

While 386-PROLOG lives on in active development, after a flurry of programming commencing on 18th April 2018, Brian created not one, but three brand new versions of his Prolog engine, but this time written in full, native 64-bit code. X64-PROLOG was born, and now exists as WIN-PROLOG, DLL-PROLOG and CON-PROLOG variants.

Welcome to the World, X64-PROLOG

Announced publicly on 2nd November 2018, the occasion of the 29th anniversary of the inception of 386-PROLOG, X64-PROLOG is already well tested and proving to be very reliable. X64-PROLOG is 100% source and object code compatible with 386-PROLOG, and the two systems can coexist and share the same data files. The key difference is that while 386-PROLOG was subject to a theoretical 4Gb limit on memory access (just 2Gb in Windows), X64-PROLOG has no such limits, and program and data heaps and stacks can be as large as required, limited only by the physical hardware upon which the system is running.

Find out about DOS-PROLOG

Find out about WIN-PROLOG

Find out about CON-PROLOG

Find out about DLL-PROLOG