Modula-2 examples ⬆
Directory examples\ contains Modula-2 code examples taken from the XDS Modula-2 distribution.
|
Modula-2 examples presented below share two characteristics :
- they can be built/run with 3 different command line tools.
- their source code can be compiled with 2 Modula-2 compilers.
Build tool | Build script | Build option | Parent file |
---|---|---|---|
cmd.exe |
build.bat |
-adw , -xds |
|
make.exe |
Makefile |
TOOLSET=adw|xds |
Makefile.inc |
sh.exe |
build.sh |
-adw , -xds |
This project has the following directory structure :
> tree /a /f . | findstr /b /v [A-Z] | build.bat | build.sh | Makefile \---src \---main +---mod | Factorial.mod \---mod-adw Factorial.mod
Note: We maintain two source versions of
Factorial.mod
as the import clauses differ between ADW Modula-2 and XDS Modula-2 (options-adw
and-xds
– the default – allow us to switch between both versions).
Batch file build.bat
-verbose clean run
generates and executes the Modula-2 program target\Factorial.exe
:
> build -verbose clean run Delete directory "target" Create XDS project file "target\Factorial.prj" Compile 1 Modula-2 implementation module into directory "target" O2/M2 development system v2.60 TS (c) 1991-2011 Excelsior, LLC. (build 07.06.2012) Make project "J:\examples\Factorial\target\Factorial.prj" XDS Modula-2 v2.40 [x86, v1.50] - build 07.06.2012 Compiling "mod\Factorial.mod" no errors, no warnings, lines 33, time 0.01 New "tmp.lnk" is generated using template "C:/opt/XDS-Modula-2/bin/xc.tem" XDS Link Version 2.13.3 Copyright (c) Excelsior 1995-2009. No errors, no warnings Execute program "target\Factorial.exe" 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320
Note: The other two build scripts
build.sh
andMakefile
work in the same way.
The output directory target\
looks as follows when using build option -xds
(default) :
> tree /a /f target | findstr /v /b [A-Z] | Factorial.exe | Factorial.obj | Factorial.prj | tmp.lnk \---mod Factorial.mod
We first create the project file target\Factorial.prj
and then invoke the XDS compiler with option =p
<project file>
:
> type target\Factorial.prj -cpu = 486 -lookup = *.sym = sym;C:\opt\XDS-Modula-2\sym -lookup = *.dll|*.lib = bin;C:\opt\XDS-Modula-2\bin -m2 % recognize types SHORTINT, LONGINT, SHORTCARD and LONGCARD % -m2addtypes -verbose -werr % disable warning 301 (parameter "xxx" is never used) -woff301+ % disable warning 303 (procedure "xxx" declared but never used) -woff303+ !module mod\Factorial.mod
The output directory target\
looks as follows when using build option -adw
:
> tree /f /a target | findstr /v /b [A-Z] | Factorial.exe | Factorial.map | linker_opts.txt +---mod | Factorial.mod | Factorial.obj | Terminal2.obj \---sym AES.sym [...] Terminal2.sym [...] WINX.sym
We create the response file linker_opts.txt
and give it as parameter to the ADW linker :
> type target\linker_opts.txt -MACHINE:X86_64 -SUBSYSTEM:CONSOLE -MAP:G:\examples\Factorial\target\Factorial -OUT:G:\examples\Factorial\target\Factorial.exe -LARGEADDRESSAWARE target\mod\Factorial.obj target\mod\Terminal2.obj C:\opt\ADW-Modula-2\ASCII\rtl-win-amd64.lib C:\opt\ADW-Modula-2\ASCII\win64api.lib
This project has the following directory structure :
> tree /a /f . | findstr /b /v [A-Z] | build.bat | build.sh | Makefile \---src \---main +---mod | Hello.mod \---mod-adw hello.mod
Command build.bat
-verbose clean run
generates and executes the Modula-2 program target\Hello.exe
:
> build -verbose clean run Delete directory "target" Create XDS project file "target\Hello.prj" Compile Modula-2 implementation module into directory "target" O2/M2 development system v2.60 TS (c) 1991-2011 Excelsior, LLC. (build 07.06.2012) Make project "J:\examples\Hello\target\Hello.prj" XDS Modula-2 v2.40 [x86, v1.50] - build 07.06.2012 Compiling "mod\hello.mod" no errors, no warnings, lines 13, time 0.01 New "tmp.lnk" is generated using template "C:/opt/XDS-Modula-2/bin/xc.tem" XDS Link Version 2.13.3 Copyright (c) Excelsior 1995-2009. No errors, no warnings Execute program "target\Hello.exe" Hello world!
Note: The other two build scripts
build.sh
andMakefile
.work in the same way and the generated files in output directorytarget\
are similar to the ones in exampleFactorial
.
The Liste
example is about creating a Modula-2 library; it contains the 3 source files Liste.def
, Liste.mod
and ListeTest.mod
.
Batch file build.bat
-verbose clean run
generates both the library target\Liste.lib
and the test program target\ListeTest.exe
:
> build -verbose clean run Delete directory "target" Compile Modula-2 definition module "target\def\Liste.def" XDS Modula-2 v2.40 [x86, v1.50] - build 07.06.2012 Compiling "J:\examples\Liste\target\def\Liste.def" no errors, no warnings, lines 10, time 0.00, new symfile Create XDS project file "target\Liste.prj" Compile 1 Modula-2 implementation module into directory "target" O2/M2 development system v2.60 TS (c) 1991-2011 Excelsior, LLC. (build 07.06.2012) Make project "J:\examples\Liste\target\Liste.prj" XDS Modula-2 v2.40 [x86, v1.50] - build 07.06.2012 Compiling "mod\Liste.mod" no errors, no warnings, lines 136, time 0.00 New "tmp.lnk" is generated using template "C:/opt/XDS-Modula-2/bin/xc.tem" XDS Link Version 2.13.3 Copyright (c) Excelsior 1995-2009. No errors, no warnings Create library file into directory "target" Compile 1 Modula-2 test module into directory "target" O2/M2 development system v2.60 TS (c) 1991-2011 Excelsior, LLC. (build 07.06.2012) Make project "J:\examples\Liste\target\ListeTest.prj" XDS Modula-2 v2.40 [x86, v1.50] - build 07.06.2012 Compiling "test\ListeTest.mod" no errors, no warnings, lines 21, time 0.00 New "tmp.lnk" is generated using template "C:/opt/XDS-Modula-2/bin/xc.tem" XDS Link Version 2.13.3 Copyright (c) Excelsior 1995-2009. No errors, no warnings 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 10 11 12 6 7 8 8 9 10 11 12
The output directory target\
looks as follows :
> tree /a /f target | findstr /v /b [A-Z] | Liste.dll | Liste.lib | Liste.obj | Liste.prj | ListeTest.exe | ListeTest.obj | ListeTest.prj | tmp.lnk +---def | Liste.def +---mod | Liste.mod +---sym | Liste.sym \---test ListeTest.mod
The generated project file target\Liste.prj
contains the XDS compiler options and the source files (mod\Liste.mod
in this case) :
> type target\Liste.prj % debug ON -gendebug+ -genhistory+ -lineno+ % write -gendll- to generate an .exe -gendll+ -usedll+ -dllexport+ -implib- -cpu = 486 -lookup = *.sym = sym;C:\opt\XDS-Modula-2\sym -m2 % recognize types SHORTINT, LONGINT, SHORTCARD and LONGCARD % -m2addtypes -verbose -werr % disable warning 301 (parameter "xxx" is never used) -woff301+ % disable warning 303 (procedure "xxx" declared but never used) -woff303+ !module mod\Liste.mod
This project has the following directory structure :
> tree /a /f . | findstr /b /v [A-Z] | build.bat | build.sh | Makefile \---src \---main \---mod PascalTriangle.mod
We generate the application using one of the build scripts build.bat
, build.sh
or Makefile
.
> build -verbose clean run Delete directory "target" Create XDS project file "target\PascalTriangle.prj" Compile Modula-2 implementation module into directory "target" O2/M2 development system v2.60 TS (c) 1991-2011 Excelsior, LLC. (build 07.06.2012) Make project "J:\examples\PascalTriangle\target\PascalTriangle.prj" #file "J:\examples\PascalTriangle\target\PascalTriangle.prj" (line 1): syntax error XDS Modula-2 v2.40 [x86, v1.50] - build 07.06.2012 Compiling "mod\PascalTriangle.mod" no errors, no warnings, lines 42, time 0.01 New "tmp.lnk" is generated using template "C:/opt/XDS-Modula-2/bin/xc.tem" XDS Link Version 2.13.3 Copyright (c) Excelsior 1995-2009. No errors, no warnings Execute program "target\PascalTriangle.exe" Triangle height=3 1 1 1 1 2 1 Triangle height=4 1 1 1 1 2 1 1 3 3 1 Triangle height=5 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 Triangle height=6 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Triangle height=7 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1
Note: The generated files in output directory
target\
are similar to the ones in exampleFactorial
.