Discussion:
XDS M2 ISO vs TopSpeed
(too old to reply)
Martin Brown
2013-02-18 09:30:04 UTC
Permalink
I have a fair amount of legacy code in Topspeed/JPI dialect of Modula 2
that is sometimes useful. I now use XDS M2 and its Topspeed libraries.
The good news is that with the right minor adjustments the code ports,
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.

In particular directory functions and iterating across files in a
directory fails miserably if there is no match on a wildcard search.

Here is a canonical example stripped to minimal code. XDS + Topspeed.

MODULE Dir;

<* +M2EXTENSIONS *>
<* +M2ADDTYPES *>

FROM FIO IMPORT DirEntry, FileAttr, ReadFirstEntry, ReadNextEntry;
FROM IO IMPORT WrLn, WrLngCard, WrStr;
FROM M2EXCEPTION IMPORT IsM2Exception, M2Exception;

VAR filename : ARRAY [0..255] OF CHAR;
fatt : FileAttr;
Entry: DirEntry;
OK : BOOLEAN;

BEGIN
filename := "*.*"; (* this works NB must be a variable *)
fatt := FileAttr({});

OK := ReadFirstEntry( filename, fatt, Entry); (* works *)
WHILE OK DO
WrStr(Entry.name) ; WrLn;
OK := ReadNextEntry(Entry);
END;

WrLn; WrStr("And now for a fatal crash :("); WrLn;
filename := "ZQJ*.LQW";
OK := ReadFirstEntry( filename, fatt, Entry); (* fails GPF *)
EXCEPT
IF IsM2Exception() THEN
WrLngCard(ORD(M2Exception()),6);
ELSE
WrStr("Boggle");
END;

WHILE OK DO
WrStr(Entry.name); WrLn;
OK := ReadNextEntry(Entry)
END;

END Dir.


The first search on "*.*" lists all files in the home directory and
works without any problems at all. The second crashes spectacularly
either with "Unhandled exception" or "GPF" depending on choice of code.
It is possible that doing IO from the handler is unwise. Comment out
"EXCEPT clause or "WrStr("Boggle") to get Unhandled exception.

The inability to list a directory where the template wildcard pattern
results in no matches is rather annoying. I can't spot anything useful
for doing this in the ISO libraries or other provided libraries.

What am I missing?

An alternative fix for me would be if I could figure out how to use the
allegedly inline assembler that XDS is supposed to contain. I have full
library sources of Topspeed so I could roll my own crucial FIO routines
if I could make the requisite DOSCALL. At the moment I am seriously
tempted to run the lot through MOD2C and give up on M2 entirely!

Thanks for any enlightenment.
--
Regards,
Martin Brown
Marco van de Voort
2013-02-18 11:57:56 UTC
Permalink
Post by Martin Brown
I have a fair amount of legacy code in Topspeed/JPI dialect of Modula 2
that is sometimes useful. I now use XDS M2 and its Topspeed libraries.
The good news is that with the right minor adjustments the code ports,
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.
I switched from M2 to Pascal/Delphi 15 years ago, but isn't it simply
that you must call some function to shutdown a directory search?

Dos typically had a first/next file searching scheme, but other OSes (*nix,
windows) and even win9x based dos (LFN) and later apis had
first->(next)->close search scheme.
Martin Brown
2013-02-18 13:17:28 UTC
Permalink
Post by Marco van de Voort
Post by Martin Brown
I have a fair amount of legacy code in Topspeed/JPI dialect of Modula 2
that is sometimes useful. I now use XDS M2 and its Topspeed libraries.
The good news is that with the right minor adjustments the code ports,
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.
I switched from M2 to Pascal/Delphi 15 years ago, but isn't it simply
that you must call some function to shutdown a directory search?
The problem I have run into is that in the XDS implementation a
directory search that finds no files at all dies horribly right at the
outset. Attempts to guard it with an EXCEPTION clause adds a hard GPF.

It all works properly provided that the directory search returns at
least one valid result. It is also a bit odd that despite being declared
as ARRAY OF CHAR their code also crashes spectacularly if a constant
string is used. (This is a separate implementation bug)

I deliberately declared variables for every parameter to ensure that the
objects passed into the function call were all the right length.
Post by Marco van de Voort
Dos typically had a first/next file searching scheme, but other OSes (*nix,
windows) and even win9x based dos (LFN) and later apis had
first->(next)->close search scheme.
It is "first" that fails horribly with an unknown exception :(

I can't find anything in the ISO libraries that caters for directory
operations and iterating on them. I feel I must be missing something.

I have figured out that the inline assembler can be persuaded to work
but syntax highlighting doesn't recognise ASM as legit. I will create my
own copy of the relevant low level calls that work as intended.
--
Regards,
Martin Brown
Marco van de Voort
2013-02-19 09:58:30 UTC
Permalink
Post by Martin Brown
Post by Marco van de Voort
Post by Martin Brown
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.
I switched from M2 to Pascal/Delphi 15 years ago, but isn't it simply
that you must call some function to shutdown a directory search?
The problem I have run into is that in the XDS implementation a
directory search that finds no files at all dies horribly right at the
outset. Attempts to guard it with an EXCEPTION clause adds a hard GPF.
(I suspected that, but I noticed that in the example the second case went
wrong. Reuse of a not properly closed handle might do funny things, so I
though I'd better mention it)

As to the rest, I don't know XDS, but can't you flip some switch to use debug
versions of the libs and simply step through the RTL and see what happens?

I don't think I ever want to use a development system were that is not
possible again.

P.s. it is good to see so many of the old names still here.
Martin Brown
2013-03-05 09:50:31 UTC
Permalink
Post by Marco van de Voort
Post by Martin Brown
Post by Marco van de Voort
Post by Martin Brown
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.
I switched from M2 to Pascal/Delphi 15 years ago, but isn't it simply
that you must call some function to shutdown a directory search?
The problem I have run into is that in the XDS implementation a
directory search that finds no files at all dies horribly right at the
outset. Attempts to guard it with an EXCEPTION clause adds a hard GPF.
(I suspected that, but I noticed that in the example the second case went
wrong. Reuse of a not properly closed handle might do funny things, so I
though I'd better mention it)
As to the rest, I don't know XDS, but can't you flip some switch to use debug
versions of the libs and simply step through the RTL and see what happens?
No debug versions of the TS library just compiled binary code. If
someone would let me have the source I would happily fix it.

However, hints provided here have allowed me to find undocumented Posix
style functionality for directories in XDS\FileSys.def which works OK
and does not crash at all even when I try to provoke crashes. It isn't
in the help system or manuals but it is there!

I suspect some other undocumented gems lie hidden in there too.

The new syntax to iterate over files in a directory is:

OpenDir(d, "*.jkh", e);
WHILE e.done DO
GetName(d, fname);
WrStr(fname); WrLn; (* do whatever here *)
END;
CloseDir(d);

It all works and is impossible to crash even if GetName is used on a dud
directory with e.done = FALSE. The fault is very specific to the TS
compatibility code and a wildcard match failure/invalid filename error.
Post by Marco van de Voort
I don't think I ever want to use a development system were that is not
possible again.
P.s. it is good to see so many of the old names still here.
BTW I have hit another couple of snags using the XDS compiler on Win7.

It doesn't seem to get on with source directories with spaces in and
more critical still after working around that it fails at linking with
"fatal error cannot open xc.tem". It claims to work on Win7...

Any suggestions for a fix for this apart from running the thing in an XP
box (which is my solution for now).

Regards,
Martin Brown
r***@gmail.com
2013-03-08 13:44:55 UTC
Permalink
Hi,
Post by Martin Brown
However, hints provided here have allowed me to find undocumented
Posix style functionality for directories in XDS\FileSys.def which
works OK and does not crash at all even when I try to provoke
crashes. It isn't in the help system or manuals but it is there!
Glad you got it working.
Post by Martin Brown
BTW I have hit another couple of snags using the XDS compiler
on Win7.
It doesn't seem to get on with source directories with spaces
in and more critical still after working around that it fails
at linking with fatal error cannot open xc.tem". It claims to
work on Win7...
Any suggestions for a fix for this apart from running the thing
in an XP box (which is my solution for now).
It works fine for me on Win7 64-bit (not that I like the OS, but
anyways ...). The xc.tem bit is probably a permissions thing.
Try reinstalling (and yes, many tools choke on spaces in paths,
so always avoid that).

c***@gmail.com
2013-02-18 12:31:23 UTC
Permalink
Post by Martin Brown
The inability to list a directory where the template wildcard pattern
results in no matches is rather annoying. I can't spot anything useful
for doing this in the ISO libraries or other provided libraries.
What am I missing?
AFAICS your code should work. Try setting FIO.IOcheck to FALSE. If that prevents the crash you can then check the return value of FIO.IOresult() to determine the error code.
Post by Martin Brown
At the moment I am seriously tempted to run the lot through MOD2C and give up > on M2 entirely!
'Seriously'? Surely not!

That has to be an 'out of the frying pan into the fire' idea if ever I've heard one ...

Regards,
Chris

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/modula2
r***@gmail.com
2013-02-19 16:34:46 UTC
Permalink
Hi,
Post by Martin Brown
I have a fair amount of legacy code in Topspeed/JPI dialect of
Modula 2 that is sometimes useful. I now use XDS M2 and its
Topspeed libraries.
The good news is that with the right minor adjustments the code
ports, compiles and works OK most of the time (and runs natively
on Win 7 64bit). The bad news is that it is not all entirely well
behaved.
I'm not familiar with TopSpeed/JPI, what did it (you) target, DOS?
Just for completeness, you can run DOS stuff via various emulators
or virtualization (VT-X), though I admit it's not really convenient.
Post by Martin Brown
In particular directory functions and iterating across files in a
directory fails miserably if there is no match on a wildcard
search.
You could maybe report a bug on the XDS forum, but don't get your
hopes up, I think development has mostly ceased.
Post by Martin Brown
Here is a canonical example stripped to minimal code. XDS +
Topspeed.
(snip)
The first search on "*.*" lists all files in the home directory
and works without any problems at all. The second crashes
spectacularly either with "Unhandled exception" or "GPF"
depending on choice of code. It is possible that doing IO from
the handler is unwise. Comment out EXCEPT clause or
"WrStr("Boggle") to get Unhandled exception.
Probably just a bug, who knows.
Post by Martin Brown
The inability to list a directory where the template wildcard
pattern results in no matches is rather annoying. I can't spot
anything useful for doing this in the ISO libraries or other
provided libraries.
I've never tried, but I'm not entirely sure you can use such
functionality portably except via something like POSIX. (Some
systems don't have subdirs!) For that, you may be better off
using GM2, and Cygwin binaries for that do exist, if you're
interested.

http://freepages.modula2.org/

Or maybe ADW Modula-2 (Windows) supports similar, dunno.
Post by Martin Brown
What am I missing?
Don't know, sorry, just offering a few general tips here.
Post by Martin Brown
An alternative fix for me would be if I could figure out how to
use the allegedly inline assembler that XDS is supposed to
contain.
IIRC, you have to enable extensions for ASM .. END ASM; to work.
Post by Martin Brown
I have full library sources of Topspeed so I could roll my own
crucial FIO routines if I could make the requisite DOSCALL.
Are you targeting DOS? (serious) I mean, it's a Win32 [sic]
compiler, and even though DOS nerds like me know you can run it
under HX (not counting using XDS-C with OpenWatcom), it's not
exactly meant to be DOS-friendly. Heck, I know nothing about
OS/2, but even I thought "DOSCALL" [sic] was some OS/2 API (shrug).

In other words, I'm not sure inline assembly is directly useful
for Windows development (they don't use DOS int 21h calls).
Though plenty of Win32 API assembly gurus hang out on FASM's
forum, if you need help in that minefield.

http://board.flatassembler.net

You might have to write your own routine in some third-party tool
(language, C?) and link that to the main program. (Or some horrible
kludge like shelling out to use "DIR /S".)
Post by Martin Brown
At the moment I am seriously tempted to run the lot through MOD2C
and give up on M2 entirely!
If you get too frustrated, try GM2. Or at least try another similar
Wirth-y language, not C. I would suggest Gardens Point Component
Pascal or FreePascal or GNAT Ada or even CM3 Modula-3. C isn't that
bad (if you understand the quirks), but it's surely less similar to
your existing syntax than those.
Marco van de Voort
2013-02-19 19:39:36 UTC
Permalink
Post by r***@gmail.com
I'm not familiar with TopSpeed/JPI,
Basically something Turbo Pascal equivalent on the Modula2 side. Somewhat
more advanced in some, since they continued with dos a bit longer.

But 16-bit.
Post by r***@gmail.com
what did it (you) target, DOS?
(or like TP, I think win16 was also supported)
Post by r***@gmail.com
or FreePascal
Of course :-)
Martin Brown
2013-02-20 21:24:59 UTC
Permalink
Post by r***@gmail.com
Hi,
Post by Martin Brown
I have a fair amount of legacy code in Topspeed/JPI dialect of
Modula 2 that is sometimes useful. I now use XDS M2 and its
Topspeed libraries.
The good news is that with the right minor adjustments the code
ports, compiles and works OK most of the time (and runs natively
on Win 7 64bit). The bad news is that it is not all entirely well
behaved.
I'm not familiar with TopSpeed/JPI, what did it (you) target, DOS?
DOS and OS/2. In its day which was very long ago now it was a pretty
good compiler although they ran into trouble trying to do a C as well.
Post by r***@gmail.com
Just for completeness, you can run DOS stuff via various emulators
or virtualization (VT-X), though I admit it's not really convenient.
The problem isn't so much running old DOS command line programs written
in this dialect of M2 so much as updating and recompiling some of the
more useful ones with extra features so that they can be used on Win7
and Win8 platforms (post 16bit support). I could make it only work on a
single file at a time and insist users wrap it in a FOR %1 batch file.
Post by r***@gmail.com
Post by Martin Brown
In particular directory functions and iterating across files in a
directory fails miserably if there is no match on a wildcard
search.
You could maybe report a bug on the XDS forum, but don't get your
hopes up, I think development has mostly ceased.
Yes. Sadly missed and it is quite a clever compiler too. Its static
dataflow analysis is good enough to identify latent faults in production
code that have never occurred in use (often down fault handling paths
for faults that thankfully have never occurred). Set to aggressive mode
it actually compiles a runtime trap - I use pragmas to make it warn at
compile time which I think is far more reasonable!

Does anyone know what happened to the original research papers that
underpinned their static code analysis at compile time?
Post by r***@gmail.com
Post by Martin Brown
Here is a canonical example stripped to minimal code. XDS +
Topspeed.
(snip)
The first search on "*.*" lists all files in the home directory
and works without any problems at all. The second crashes
spectacularly either with "Unhandled exception" or "GPF"
depending on choice of code. It is possible that doing IO from
the handler is unwise. Comment out EXCEPT clause or
"WrStr("Boggle") to get Unhandled exception.
Probably just a bug, who knows.
Seems to be passing a null filename to a routine that expects to get a
valid filename or at least not a zero length string.
Post by r***@gmail.com
Post by Martin Brown
The inability to list a directory where the template wildcard
pattern results in no matches is rather annoying. I can't spot
anything useful for doing this in the ISO libraries or other
provided libraries.
I've never tried, but I'm not entirely sure you can use such
functionality portably except via something like POSIX. (Some
systems don't have subdirs!) For that, you may be better off
using GM2, and Cygwin binaries for that do exist, if you're
interested.
http://freepages.modula2.org/
Or maybe ADW Modula-2 (Windows) supports similar, dunno.
Post by Martin Brown
What am I missing?
Don't know, sorry, just offering a few general tips here.
Post by Martin Brown
An alternative fix for me would be if I could figure out how to
use the allegedly inline assembler that XDS is supposed to
contain.
IIRC, you have to enable extensions for ASM .. END ASM; to work.
I was misled by the fact that syntax highlighting does not recognise the
ASM keyword. It does work and inline code assmebles once you have
guessed and added the correct slightly idiosyncratic syntaxic sugar.
Post by r***@gmail.com
Post by Martin Brown
I have full library sources of Topspeed so I could roll my own
crucial FIO routines if I could make the requisite DOSCALL.
Are you targeting DOS? (serious) I mean, it's a Win32 [sic]
compiler, and even though DOS nerds like me know you can run it
under HX (not counting using XDS-C with OpenWatcom), it's not
exactly meant to be DOS-friendly. Heck, I know nothing about
OS/2, but even I thought "DOSCALL" [sic] was some OS/2 API (shrug).
These are command line utilities and no prospect of ever going to a
windows environment. They do their work and the output is piped to a
file. They have a DOS and OS/2 shared command line heritage.
Post by r***@gmail.com
In other words, I'm not sure inline assembly is directly useful
for Windows development (they don't use DOS int 21h calls).
Though plenty of Win32 API assembly gurus hang out on FASM's
forum, if you need help in that minefield.
I am using the XDS compiler only to create old style DOS command line
interface programs at the moment. Most things behave OK this one came
out of the blue but it is an annoying show stopper for the moment since
almost all the tools I have ever written use the same method to iterate
over a directory. It works OK at present provided you never feed it a
wildcard pattern that matches no files. In other words it is usable but
looks very unprofessional in an obvious error situation.
Post by r***@gmail.com
Post by Martin Brown
At the moment I am seriously tempted to run the lot through MOD2C
and give up on M2 entirely!
If you get too frustrated, try GM2. Or at least try another similar
Wirth-y language, not C. I would suggest Gardens Point Component
Pascal or FreePascal or GNAT Ada or even CM3 Modula-3. C isn't that
bad (if you understand the quirks), but it's surely less similar to
your existing syntax than those.
I still use M2 from time to time as a scratchpad tool since translating
it into C makes for less error prone C. Most clients have insisted on C
or C++ development (actually often a tiny subset of C++) for ages now.

Not intending to start a language war here - just reflecting on the
lamentable commercial realities today.

Regards,
Martin
Marco van de Voort
2013-02-21 08:39:49 UTC
Permalink
Post by Martin Brown
Post by r***@gmail.com
Are you targeting DOS? (serious) I mean, it's a Win32 [sic]
compiler, and even though DOS nerds like me know you can run it
under HX (not counting using XDS-C with OpenWatcom), it's not
exactly meant to be DOS-friendly. Heck, I know nothing about
OS/2, but even I thought "DOSCALL" [sic] was some OS/2 API (shrug).
These are command line utilities and no prospect of ever going to a
windows environment. They do their work and the output is piped to a
file. They have a DOS and OS/2 shared command line heritage.
I think Rugxulo tries to warn you that even for win32/64 commandline utils,
you still need to use the win32 api, and INT calls go as much the way of the
dodo as 16-bit assembler.
r***@gmail.com
2013-02-22 00:42:33 UTC
Permalink
Hi,
Post by Martin Brown
Post by r***@gmail.com
Post by Martin Brown
I have a fair amount of legacy code in Topspeed/JPI dialect of
Modula 2 that is sometimes useful. I now use XDS M2 and its
Topspeed libraries.
The good news is that with the right minor adjustments the code
ports, compiles and works OK most of the time (and runs natively
on Win 7 64bit). The bad news is that it is not all entirely
well behaved.
I'm not familiar with TopSpeed/JPI, what did it (you) target, DOS?
DOS and OS/2. In its day which was very long ago now it was a
pretty good compiler although they ran into trouble trying to do a
C as well.
OS/2 is still kicking with eCS 2.1 (or such), though I don't use it.
I guess your target audience these days only uses Windows?
Post by Martin Brown
Post by r***@gmail.com
Just for completeness, you can run DOS stuff via various
emulators or virtualization (VT-X), though I admit it's not
really convenient.
The problem isn't so much running old DOS command line programs
written in this dialect of M2 so much as updating and recompiling
some of the more useful ones with extra features so that they can
be used on Win7 and Win8 platforms (post 16bit support).
I assume 32-bit Windows still supports "some" DOS support. At least
it did when I used Vista. But yeah, 64-bit drops that (though with
VirtualBox it can still "mostly" work, even better with VT-X, and
Linux users can use DOSEMU).
Post by Martin Brown
I could make it only work on a single file at a time and insist
users wrap it in a FOR %1 batch file.
Maybe a good idea, if nothing else turns up.
Post by Martin Brown
Post by r***@gmail.com
Post by Martin Brown
In particular directory functions and iterating across files in
a directory fails miserably if there is no match on a wildcard
search.
Probably just a bug, who knows.
Seems to be passing a null filename to a routine that expects to
get a valid filename or at least not a zero length string.
Post by r***@gmail.com
Post by Martin Brown
The inability to list a directory where the template wildcard
pattern results in no matches is rather annoying. I can't spot
anything useful for doing this in the ISO libraries or other
provided libraries.
I've never tried, but I'm not entirely sure you can use such
functionality portably except via something like POSIX. (Some
systems don't have subdirs!) For that, you may be better off
using GM2 / Cygwin binaries
Post by Martin Brown
I have full library sources of Topspeed so I could roll my own
crucial FIO routines if I could make the requisite DOSCALL.
Are you targeting DOS? (serious) I mean, it's a Win32 [sic]
compiler
These are command line utilities and no prospect of ever going to
a windows environment. They do their work and the output is piped
to a file. They have a DOS and OS/2 shared command line heritage.
Okay, so [Win32] "console" stuff.
Post by Martin Brown
Post by r***@gmail.com
In other words, I'm not sure inline assembly is directly useful
for Windows development (they don't use DOS int 21h calls).
Though plenty of Win32 API assembly gurus hang out on FASM's
forum, if you need help in that minefield.
I am using the XDS compiler only to create old style DOS command
line interface programs at the moment.
Okay, but just to be totally clear:

1). These are native PE (Win32) console binaries, not MZ (DOS)
nor OS/2 (NE, LX) ones.
2). They don't run in the DOS subsystem (NTVDM) either.
3). They won't run in native DOS without third-party add-ons.

I know most people know this already, including you, most likely,
just saying ....

(And yes, "everybody" uses Windows, but DOS used to be the console
in ye olde days. DOS used to run everywhere, almost like a universal
binary, but "nobody" cares anymore. Sigh.)
Post by Martin Brown
Most things behave OK this one came out of the blue but it is an
annoying show stopper for the moment since almost all the tools I
have ever written use the same method to iterate over a directory.
It works OK at present provided you never feed it a wildcard
pattern that matches no files. In other words it is usable but
looks very unprofessional in an obvious error situation.
Win32's CMD has some fancy features, e.g. "FOR /R" or "FOR /F". That
may help you (see "for /?").
Post by Martin Brown
Post by r***@gmail.com
Post by Martin Brown
At the moment I am seriously tempted to run the lot through
MOD2c and give up on M2 entirely!
If you get too frustrated, try GM2. Or at least try another
similar Wirth-y language, not C. I would suggest Gardens Point
Component Pascal [Oberon] or FreePascal or GNAT Ada or even CM3
Modula-3. C isn't that bad (if you understand the quirks), but
it's surely less similar to your existing syntax than those.
I still use M2 from time to time as a scratchpad tool since
translating it into C makes for less error prone C. Most clients
have insisted on C or C++ development (actually often a tiny subset
of C++) for ages now.
Not intending to start a language war here - just reflecting on
the lamentable commercial realities today.
I know. Just trying to be fair, it's used a lot and gets some stuff
done, even if some of us still prefer others. ;-)
Loading...