Modula-2 examples ⬆
Directory examples\ contains Modula-2 code examples taken from the XDS Modula-2 distribution.
|
The project directory is organized as follows :
> 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).
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\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
The output directory target\
looks as follows :
> tree /a /f target | findstr /v /b [A-Z] | Factorial.exe | Factorial.obj | Factorial.prj | tmp.lnk \---mod Factorial.mod
The generated project file target\Factorial.prj
contains the XDS compiler options and the source files (mod\Factorial.mod
in this case) :
> type target\Factorial.prj -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\Factorial.mod
The project directory is organized as follows :
> tree /a /f . | findstr /b /v [A-Z] | build.bat | build.sh | Makefile | \---src \---main +---mod | Hello.mod | \---mod-adw hello.mod
We generate the application using one of the build scripts such as build.bat
, build.sh
or Makefile
.
> 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 generated files in output directory
target\
are similar to the ones in exampleFactorial
.
The Liste
code example is about creating a Modula-2 library; it contains the 3 source files Liste.def
, Liste.mod
and ListeTest.mod
. We generate the library and the test program using one of the build scripts build.bat
, build.sh
or Makefile
.
> 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
The project directory is organized as follows :
> 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
.