Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 209 additions & 0 deletions README-new.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
= The language

Modula-3 is an optionally safe systems programming language.
It has garbage collection (for the optionally safe part).
Extent implementations are compiled statically to native code.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word Extent is hard to read. Existing?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the word you want there is "Extant", but the whole thing could possibly be reworded as

Existing implementation compile ahead-of-time to native code.

(Because apparently what compilers have done for decades is now a special thing with its own lingo.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. "ahead of time" ugh. It is called "compiling". I won't say much right about this termonology I am tired and grumpy. :)
  2. I don't like the current README. You can see mine is based on it, but I don't like that it points people to the.sh files and I like that I at least tried to explain various ways to run them (.py and .sh do about the same). Maybe allude to the .sh files for the unusual systems without .py.

Aside not for docs:
I have py2 on OSF1.
I have py3 but not current on OSF1.
Porting to py3 is challenging.
I would like to try bringup on DOS maybe.
Point is though. py2 and perhaps py3 are pretty darn portable, the space that needs .sh is pretty small imho.
We could offer py -fake that writes out the commands, perhaps.

Or has been said many times, rewrite the scripts in quake or mod3, but I don't know, I am torn.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scripts have definitely been a point of confusion for me. I recognize that the python scripts are there for portability, but I'm so used to shell that they're a bit foreign.

I like the idea of rewriting them in quake, but I don't know enough yet to know how practical that is. Of course there would still have to be some sort of bootstrap process.

I saw somewhere quake being compared to scons. I don't know scons, but the scripts always remind me of cmake, which gives me the idea of organizing/modularizing them in the same style. But I'm getting in way over my head.

But yes it's a mess, there will always be tension between "it works for me" and "it needs to be portable", and some sort of native/built-in solution may be the best way to resolve that.

For now just cataloguing what's there is a help.

And I get the grumpy. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We "have py2 on" on DOS , but we do not have py3 ( I found working py2, but do not found py3)


= The implementation

Critical Mass is a complete mature implementation of Modula-3.

Being an optionally safe "systems" programming language, the
vast bulk of the system is implemented in Modula-3,
including the garbage collector, and parts of the compiler.

C is used mainly as a thin portable wrapper to interoperate with C libraries
without encoding underlying ABI details, like the precise layout
of struct stat, or if some functions are really macros, etc.

= The backends

The system contains three backends presently.

- A gcc-based backend for many platforms.
This is a gcc "frontend" that reads Modula-3 IR (intermediate representation)
and then runs the gcc backend.
This produces textual assembly source that is then assembled.

This works for example on Macos/amd64 ("Darwin"), Linux/amd64, Linux/x86,
as well other architectures and other Unix systems: SPARC, Alpha, FreeBSD, NetBSD, OpenBSD, Solaris, Cygwin etc.

m3-sys/m3cc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should highlight the m3cg directory and parse.c


- An "integrated" backend, written in Modula-3.
It is "integrated" in that one executable cm3 contains the frontend and complete backend.
This presently targets only the Windows/x86 system.
Also known as NT386 or I386_NT.
It writes object files directly.
m3-sys/m3back/src/*x86*.m3

- A C backend that writes out textual C that can then be
compiled with a variety of C compilers including gcc, clang,
Visual C++, Sun CC, and more. This has been tested
on many systems, including the ones targetted by the other backends.
The code that writes the C is itself written in Modula-3.
The C is not meant to be read or maintained by humans, as it is a representation
of a low level IR (intermediate representation).
m3-sys/m3back/src/M3C.m3

- A working LLVM backend?

With some exception, the backends should generate code compatible with each other.
But there is at least one exception so this is best avoided.
Specifically related to nested functions or at least pointers to them.

= The libraries

The system includes a variety of libraries including but not limited to:
- threading and locking
- formated textual io (similar to printf)
- networking (sockets)
- custom GUI library ("Trestle")

The system also includes "bindings" so you can directly call Win32, OpenGL, X Windows, ODBC, etc.
That is, C headers rewritten in Modula-3. Very much like P/Invoke in C#.

As well some sample applications such as a web browser, forms editor, and some games.

= Build system

The compiler is also integrated into its own build system.

The build system is mostly declarative, embedded in a somewhat general "scripting" language,
known as "quake" (quick make?)

Architecturally it resembles scons, though the again the build system and compiler are linked.

The build system contains per-platform "configuration" files, written in the underlying quake
scripting language, providing functions like "compile a .c file", "link an executable"
and "link a shared library". In this respect the build system largely subsumes libtool.
See m3-sys/cminstall/src/config-no-install

= Building

Because the system is written in Modula-3 building it from source can be challenging.

Several distribution formats are provided.

- "boot" is generated C that produces the compiler, integrated and C backends, and build sytem.
These live in one executable -- "cm3".
"boot" also produces mklib which is used on Windows platforms only.
The C code is almost portable to all systems, however for now it is platform-specific.
Specifically it encodes sizeof(void*), endian, and Windows vs. Unix.
In time this matrix should be reduced.

- "min" is a minimal binary distribution containing little more than "boot" -- cm3 and mklib --
but also two libraries, m3core and libm3.
See m3-libs/m3core and m3-libs/libm3.
m3core is the lowest level library containing threading, garbage collector, unistd/win32 bindings.
The compiler and m3core are somewhat tightly coupled. The compiler outputs calls into m3core,
such as for garbage collection barriers.
libm3 is a higher level utility library containing things like growable vectors, linked lists, etc.

- "all" is everything. Sometimes some things are omitted, such as if a system lacked X Windows installed.

The use-cases are fairly obvious.
"min" is small and binary. You can write small Modula-3 programs right away.
"all" is larger and provides a larger assortment of libraries.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe throw in vernacular like "kitchen sink" or "batteries included", "other systems call it that".

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • "all" is everything, batteries included

to be followed by a list. I can try to put together that list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the list is important, but to allude to it already being mentioned, "gui library", "browsers (not very good ones, but demos", "games (tetris)", Obliq, Mentor...maybe with links to papers .... presenting hierarhical information is always an exercise in how deep to go though... links certainly helps, I would not detail obliq and mentor but maybe link. They are kinda cool.

It is tough, you know, the system, the "installers", and the documentation, tries to be all things to all people, just what one wants. Providing sockets+stdio does satisfy a large group, but not everyone. You need gui to capture some people. etc. The group satisifed with sockets+stdio might complain about the large size of all.. no great answer, but I sorta tried, or rather I mostly copied what Olaf did, possibly misunderstanding it, and doing less (I am not sure he had overlap, and he had other groups like std, I tried to reduce things for a simpler story, but ultimately if you take a Debian-like perspective, what I did is quite bad..there should be no overlap....)


To use "min" or "all", extract them such as with tar xf and add <root>/bin to the PATH environment variable.

<insert link to HelloWorld and Larger tutorials>

"boot" is if you "like" or "need" to build from source as much as possible.
Note again that this is not human readable/writable source, but it is at least C.

The usage is roughly:
tar xf cm3-boot.tgz
cd cm3-boot
make
# If there any errors here, start by looking at the top of Makefile.
mkdir -p /cm3/bin
mv {cm3,mklib} /cm3/bin
export PATH=/cm3/bin:$PATH
cd ...
git clone ... cm3
cd cm3/scripts/python
sudo apt-get install python2
./boot2.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List boot2-full.py or such here? I forget, need to check.


At which point you have the equivalent of "all", but have built mostly from source.

= Packages and scripts

The Critical Mass system is split up informally into groups of packages.
Such as core, games, demo.
These are declared in scripts/pkginfo.txt.
Package names are on the left. The rest of each line is the groups the packages are in.
Packages are discovered throughout the source tree, identified roughly as directories
containing "m3makefile".
I believe the order in pkginfo.txt is the flattened dependency graph?

You can build packages like:
cd m3-libs/m3core
cm3
cm3 -ship

"ship" is analogous to "make install".

todo: Building from not-near-leaf directories is not useful:
cd m3-libs
cm3
# Ideally would build m3core, libm3, etc. in dependency order, perhaps even
# concurrently, but presently fails.

Or you can do:
cd scripts/python
./do-pkg.py m3core buildship

The advantage of the scripts is that you can specify multiple packages, and/or groups, and
the scripts loop over them, in dependency order.

So you can say:
./do-pkg.py m3core libm3 sysutils m3middle m3back cm3 buildship

You can intermix groups with packages:
./do-pkg.py front tetris buildship

Note that the dependency graph is not walked "down".
Only the packages requested are built.
If their dependencies have never been build, you will get an error about a missing .m3exports file.
If their dependencies are out of data, errors can occur.
But they are built in dependency order.

Something needs to be said about "overrides", and this part of the system revamped.
cm3 -x builds against in-tree package store, w/o -x builds against
shipped packages.

= Super scripts

There are also scripts like:

./upgrade.py
Rebuilds the compiler, given an already working compiler and already
working m3core and libm3 and updates it in place -- be careful.
Sometimes this must be preceded by ./do-pkg.py m3core libm3 buildship

./make-dist.py

Produces the various binary .tgz/.msi files.
In particular though, it builds a new compiler from a present working system,
then builds the compiler with itself, and then rebuilds the entire system
with that compiler. This should be the basis of future automation.

./boot1.py c <target>

Produces the boot C archives.
todo: Ability to provide multiple targets.

= Windows

On Windows users should run the "shortcut" on the start menu that produces
a working C++ comman line build environment.
That is, cl.exe should be in path, and %INCLUD% and %LIB% should be reasonably populated.

= Caveats

This documentation needs work.
One thing it glosses over is chosing a backend and specifying it to the scripts.
In particular, it is often a good idea to say "skipgcc" and/or "c" to use the C backend.