Tuesday, April 13, 2010

Irie Pascal 3.0. Adding support for multi-module programs.

I'm currently working on adding support for writing multi-module programs. I've decided to support the Object Pascal syntax for this. If you're not familiar with this syntax (with UNITs and USES clauses) then please see chapter 3: Programs and Units in the Object Pascal Language Guide for a look at this syntax.

NOTE: Irie Pascal will NOT be able to use most units written for other compilers, and I am NOT planning to create units for Irie Pascal that are similiar to units available for other compilers.

I am planning to make sure that the units supplied with Irie Pascal don't have the same names as units available for other compilers (maybe I'll prefix the Irie Pascal unit names with "Irie"). So I'm leaving the door open for someone else to write units for Irie Pascal that are similiar to units available for other compilers. I'm not going out of my way to make Irie Pascal incompatible with other compilers (I don't like it when vendors do that), but I'm not making any heroic efforts to make it compatible either.

I'm adding a linker.
Right now, Irie Pascal doesn't use a linker, instead the compiler just generates executables directly from the source files. This is not difficult, because Irie Pascal builds each program from a single module, but building programs from multiple modules is much more complicated so I've decided to build programs in two phases.
  1. A compile phase. In this phase the compiler generates intermediate object files from the source files.
  2. A link phase. In this phase the linker generates an executable object file from all of the intermediate object files in the project. 
Adding support for multi-module programs

Already done
  1. Design a new object file format. All of these changes to Irie Pascal mean that a new object file format is necessary.
 To be done
  1. Switch over to the new object file format. Which means updating Irie Pascal to compile existing (single-module) programs in two phases and generate files in the new format).
  2. Test the updated Irie Pascal.
  3. Add syntax-only support for multi-module programs (i.e. update Irie Pascal to recognize the new multi-module syntax but don't generate any code for it yet).
  4. Gradually add full support for multi-module programs (i.e. gradually start generating code for each piece of the new multi-module syntax).
  5. Add new programs to the Irie Pascal test suite (to test the new syntax).
  6. Done.

2 comments:

  1. Irie Pascal has the ability to easily connect to an SQL database (that alone is awesome - very well done).

    When used on a server it can also generate an HTML page using just the writeln command (as included within the samples).

    What I would love to know is how to generate a similar HTML page from my desktop
    i.e. I run my EXE program on my desktop and it opens up my browser and displays an HTML page.

    It probably can be done already and I just haven't worked out how to do it.

    Anyway, Irie Pascal is a really great application. My congratulations to the brains behind the functionality.

    ReplyDelete
  2. There is a Windows function called, ShellExecute, that allows you to open a document (using the program associated with the document type). So, you can generate an HTML document (using rewrite, and writeln), and then call ShellExecute.

    You can get detailed information on Shellexecute at the URL below:

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

    You can also try searching the web for "ShellExecute".

    I wrote a small program that calls ShellExecute (so you can experiment a little bit)

    The program is below (followed by an explanation).

    program ShellExecute(f, oper);
    (*$I winuser.inc *)
    (*$I shellapi.inc *)
    var
    h : HINSTANCE;
    oper : cstring;
    f : cstring;

    procedure DisplaySyntax;
    begin
    //Add code here to show the proper syntax for this program.
    end;

    begin
    writeln('f = "', f, '"');
    writeln('oper = "', oper, '"');

    if f = '' then
    begin
    DisplaySyntax;
    halt
    end;
    if oper = '' then
    oper := "open";
    h := ShellExecute(0, addr(oper), addr(f), 0, 0, SW_SHOWNORMAL);
    end.

    The core of the program is just the last line (i.e. the call to the ShellExecute function). The rest of the program is just to get the values to pass to the function.

    This program takes two arguments:
    1. The name of the file you want to perform an operation on.
    2. The operation you want to perform on the file. The default is "open".

    ShellExecute is not built into Irie Pascal (it is a part of Windows), so the program needs a declaration for Shellexecute. To make this kind of thing a little easier, Irie Pascal comes with some built in include files with some declarations for Windows programming.

    If you look at the beginning of the program, you will see the following two lines:

    (*$I winuser.inc *)
    (*$I shellapi.inc *)

    These lines include the declarations for the Windows declarations that the program needs.

    After that, the program declares three variables

    h : HINSTANCE;
    oper : cstring;
    f : cstring;

    "h" is used to store the handle to the program that operated on the file.
    "oper" is used to specify the operation you want to perform on the file (e.g. "open").
    "f" is used to specify the name of the file.

    Notice that the type of "oper" and "f" is "cstring". This type stores strings in the format used by the C programming language (and by Windows).

    If you look at the call to Shellexecute, you will notice that the "f", and "oper" parameters are not passed directly. These paramters are passed through the built in function, addr (which gets the actual Windows address of the parameter).

    I realize that this is a vert brief introduction to calling Windows API functions. The Programmers Reference Guide has a secion on that, here:

    http://irietools.com/iriepascal/progref305.html

    If you have any questions, just let me know.

    Stuart

    ReplyDelete