summaryrefslogtreecommitdiff
path: root/Examples/modula3
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2009-08-18 20:56:02 +0000
committerLorry <lorry@roadtrain.codethink.co.uk>2012-09-25 16:59:08 +0000
commit9f8a09ed743cedd9547bf0661d518647966ab114 (patch)
tree9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/modula3
downloadswig-tarball-9f8a09ed743cedd9547bf0661d518647966ab114.tar.gz
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/modula3')
-rw-r--r--Examples/modula3/check.list7
-rw-r--r--Examples/modula3/class/Makefile25
-rw-r--r--Examples/modula3/class/example.cxx28
-rw-r--r--Examples/modula3/class/example.h44
-rw-r--r--Examples/modula3/class/example.i32
-rw-r--r--Examples/modula3/class/swig.tmpl11
-rw-r--r--Examples/modula3/enum/Makefile26
-rw-r--r--Examples/modula3/enum/example.cxx32
-rw-r--r--Examples/modula3/enum/example.h83
-rw-r--r--Examples/modula3/enum/example.i72
-rw-r--r--Examples/modula3/exception/Makefile23
-rw-r--r--Examples/modula3/exception/example.h18
-rw-r--r--Examples/modula3/exception/example.i43
-rw-r--r--Examples/modula3/reference/Makefile21
-rw-r--r--Examples/modula3/reference/example.cxx46
-rw-r--r--Examples/modula3/reference/example.h22
-rw-r--r--Examples/modula3/reference/example.i32
-rw-r--r--Examples/modula3/simple/Makefile21
-rw-r--r--Examples/modula3/simple/example.c18
-rw-r--r--Examples/modula3/simple/example.i7
-rw-r--r--Examples/modula3/typemap/Makefile21
-rw-r--r--Examples/modula3/typemap/example.i90
22 files changed, 722 insertions, 0 deletions
diff --git a/Examples/modula3/check.list b/Examples/modula3/check.list
new file mode 100644
index 0000000..37ac8c1
--- /dev/null
+++ b/Examples/modula3/check.list
@@ -0,0 +1,7 @@
+# see top-level Makefile.in
+class
+enum
+exception
+reference
+simple
+typemap
diff --git a/Examples/modula3/class/Makefile b/Examples/modula3/class/Makefile
new file mode 100644
index 0000000..bf929a0
--- /dev/null
+++ b/Examples/modula3/class/Makefile
@@ -0,0 +1,25 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+TARGET = example
+PLATFORM = LINUXLIBC6
+INTERFACE = example.i
+SWIGOPT = -c++
+MODULA3SRCS = *.[im]3
+
+all:: modula3
+
+modula3::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
+ m3ppinplace $(MODULA3SRCS)
+# compilation of example_wrap.cxx is started by cm3
+# $(CXX) -c $(TARGET)_wrap.cxx
+ mv example_wrap.cxx m3makefile $(MODULA3SRCS) src/
+ ln -sf ../example.h src/example.h
+ cm3
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile modula3_clean
+
+check: all
diff --git a/Examples/modula3/class/example.cxx b/Examples/modula3/class/example.cxx
new file mode 100644
index 0000000..1e8e203
--- /dev/null
+++ b/Examples/modula3/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Examples/modula3/class/example.h b/Examples/modula3/class/example.h
new file mode 100644
index 0000000..9c1f479
--- /dev/null
+++ b/Examples/modula3/class/example.h
@@ -0,0 +1,44 @@
+/* File : example.h */
+
+class Shape
+{
+public:
+ Shape ()
+ {
+ nshapes++;
+ }
+ virtual ~ Shape ()
+ {
+ nshapes--;
+ };
+ double x, y;
+ void move (double dx, double dy);
+ virtual double area (void) const = 0;
+ virtual double perimeter (void) const = 0;
+protected:
+ static int nshapes;
+};
+
+class Circle:public Shape
+{
+private:
+ double radius;
+public:
+ Circle (double r):radius (r)
+ {
+ };
+ virtual double area (void) const;
+ virtual double perimeter (void) const;
+};
+
+class Square:public Shape
+{
+private:
+ double width;
+public:
+ Square (double w):width (w)
+ {
+ };
+ virtual double area (void) const;
+ virtual double perimeter (void) const;
+};
diff --git a/Examples/modula3/class/example.i b/Examples/modula3/class/example.i
new file mode 100644
index 0000000..2fafadb
--- /dev/null
+++ b/Examples/modula3/class/example.i
@@ -0,0 +1,32 @@
+/* File : example.i */
+%module Example
+
+%{
+#include "example.h"
+%}
+
+%insert(m3makefile) %{template("../swig")
+cxx_source("example_wrap")%}
+
+%typemap(m3rawinmode) Shape *, Circle *, Square * ""
+%typemap(m3rawrettype) Shape *, Circle *, Square * "$1_basetype"
+
+%typemap(m3wrapinmode) Shape *, Circle *, Square * ""
+%typemap(m3wrapargraw) Shape *, Circle *, Square * "self.cxxObj"
+
+%typemap(m3wrapretvar) Circle *, Square * "cxxObj : ExampleRaw.$1_basetype;"
+%typemap(m3wrapretraw) Circle *, Square * "cxxObj"
+%typemap(m3wrapretconv) Circle *, Square * "NEW($1_basetype,cxxObj:=cxxObj)"
+%typemap(m3wraprettype) Circle *, Square * "$1_basetype"
+
+/* Should work with and without renaming
+%rename(M3Shape) Shape;
+%rename(M3Circle) Circle;
+%rename(M3Square) Square;
+%typemap(m3wrapintype) Shape *, Circle *, Square * "M3$1_basetype"
+%typemap(m3wraprettype) Shape *, Circle *, Square * "M3$1_basetype"
+%typemap(m3wrapretconv) Circle *, Square * "NEW(M3$1_basetype,cxxObj:=cxxObj)"
+*/
+
+/* Let's just grab the original header file here */
+%include "example.h"
diff --git a/Examples/modula3/class/swig.tmpl b/Examples/modula3/class/swig.tmpl
new file mode 100644
index 0000000..e3e9bf1
--- /dev/null
+++ b/Examples/modula3/class/swig.tmpl
@@ -0,0 +1,11 @@
+
+readonly proc cxx_source (X) is
+ local cxxfile = X&".cxx"
+ local objfile = X&".o"
+ %exec("echo $PWD")
+ if stale(objfile,cxxfile)
+ exec("cd",path(),"; g++ -I.. -c -o",objfile,cxxfile)
+ end
+ import_obj(X)
+ %unlink_file(path()&SL&objfile)
+end
diff --git a/Examples/modula3/enum/Makefile b/Examples/modula3/enum/Makefile
new file mode 100644
index 0000000..b5bf8f6
--- /dev/null
+++ b/Examples/modula3/enum/Makefile
@@ -0,0 +1,26 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+TARGET = example
+INTERFACE = example.i
+CONSTNUMERIC = example_const
+SWIGOPT = -c++
+MODULA3SRCS = *.[im]3
+
+all:: modula3
+
+modula3::
+ $(SWIG) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h
+ $(CXX) -Wall $(CONSTNUMERIC).c -o $(CONSTNUMERIC)
+ $(CONSTNUMERIC) >$(CONSTNUMERIC).i
+
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
+ m3ppinplace $(MODULA3SRCS)
+ mv m3makefile $(MODULA3SRCS) src/
+ cm3
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile modula3_clean
+
+check: all
diff --git a/Examples/modula3/enum/example.cxx b/Examples/modula3/enum/example.cxx
new file mode 100644
index 0000000..bd808ff
--- /dev/null
+++ b/Examples/modula3/enum/example.cxx
@@ -0,0 +1,32 @@
+/* File : example.cxx */
+
+#include "example.h"
+#include <stdio.h>
+
+void Foo::enum_test(speed s) {
+ if (s == IMPULSE) {
+ printf("IMPULSE speed\n");
+ } else if (s == WARP) {
+ printf("WARP speed\n");
+ } else if (s == LUDICROUS) {
+ printf("LUDICROUS speed\n");
+ } else if (s == HYPER) {
+ printf("HYPER speed\n");
+ } else {
+ printf("Unknown speed\n");
+ }
+}
+
+void enum_test(color c, Foo::speed s) {
+ if (c == RED) {
+ printf("color = RED, ");
+ } else if (c == BLUE) {
+ printf("color = BLUE, ");
+ } else if (c == GREEN) {
+ printf("color = GREEN, ");
+ } else {
+ printf("color = Unknown color!, ");
+ }
+ Foo obj;
+ obj.enum_test(s);
+}
diff --git a/Examples/modula3/enum/example.h b/Examples/modula3/enum/example.h
new file mode 100644
index 0000000..2f44a6c
--- /dev/null
+++ b/Examples/modula3/enum/example.h
@@ -0,0 +1,83 @@
+/* File : example.h */
+
+#define PI 3.141
+
+#define DAY_MONDAY 0
+#define DAY_TUESDAY 1
+#define DAY_WEDNESDAY 2
+#define DAY_THURSDAY 3
+#define DAY_FRIDAY 4
+#define DAY_SATURDAY 5
+#define DAY_SUNDAY 6
+
+enum color { BLUE, RED, GREEN };
+
+#define CLB_BLACK 0
+#define CLB_BLUE 1
+#define CLB_RED 2
+#define CLB_MAGENTA 3
+#define CLB_GREEN 4
+#define CLB_CYAN 5
+#define CLB_YELLOW 6
+#define CLB_WHITE 7
+
+/* Using this would be good style
+ which cannot be expected for general C header files.
+ Instead I want to demonstrate how to live without it.
+enum month {
+ MTHF_JANUARY,
+ MTHF_FEBRUARY,
+ MTHF_MARCH,
+ MTHF_APRIL,
+ MTHF_MAY,
+ MTHF_JUNE,
+ MTHF_JULY,
+ MTHF_AUGUST,
+ MTHF_SEPTEMBER,
+ MTHF_OCTOBER,
+ MTHF_NOVEMBER,
+ MTHF_DECEMBER,
+}
+*/
+
+/* Since there are no compile time constants in C / C++
+ it is a common abuse
+ to declare bit set (flag) constants
+ as enumerations. */
+enum calendar {
+ MTHB_JANUARY = 1 << 0, /* 1 << MTHF_JANUARY, */
+ MTHB_FEBRUARY = 1 << 1, /* 1 << MTHF_FEBRUARY, */
+ MTHB_MARCH = 1 << 2, /* 1 << MTHF_MARCH, */
+ MTHB_APRIL = 1 << 3, /* 1 << MTHF_APRIL, */
+ MTHB_MAY = 1 << 4, /* 1 << MTHF_MAY, */
+ MTHB_JUNE = 1 << 5, /* 1 << MTHF_JUNE, */
+ MTHB_JULY = 1 << 6, /* 1 << MTHF_JULY, */
+ MTHB_AUGUST = 1 << 7, /* 1 << MTHF_AUGUST, */
+ MTHB_SEPTEMBER = 1 << 8, /* 1 << MTHF_SEPTEMBER, */
+ MTHB_OCTOBER = 1 << 9, /* 1 << MTHF_OCTOBER, */
+ MTHB_NOVEMBER = 1 << 10, /* 1 << MTHF_NOVEMBER, */
+ MTHB_DECEMBER = 1 << 11, /* 1 << MTHF_DECEMBER, */
+
+ MTHB_SPRING = MTHB_MARCH | MTHB_APRIL | MTHB_MAY,
+ MTHB_SUMMER = MTHB_JUNE | MTHB_JULY | MTHB_AUGUST,
+ MTHB_AUTUMN = MTHB_SEPTEMBER | MTHB_OCTOBER | MTHB_NOVEMBER,
+ MTHB_WINTER = MTHB_DECEMBER | MTHB_JANUARY | MTHB_FEBRUARY,
+};
+
+
+namespace Answer {
+ enum {
+ UNIVERSE_AND_EVERYTHING = 42,
+ SEVENTEEN_AND_FOUR = 21,
+ TWOHUNDRED_PERCENT_OF_NOTHING = 0,
+ };
+
+ class Foo {
+ public:
+ Foo() { }
+ enum speed { IMPULSE = -2, WARP = 0, HYPER, LUDICROUS = 3};
+ void enum_test(speed s);
+ };
+};
+
+void enum_test(color c, Answer::Foo::speed s);
diff --git a/Examples/modula3/enum/example.i b/Examples/modula3/enum/example.i
new file mode 100644
index 0000000..f5947b3
--- /dev/null
+++ b/Examples/modula3/enum/example.i
@@ -0,0 +1,72 @@
+/* File : example.i */
+%module Example
+
+%{
+#include "example.h"
+%}
+
+%include "example_const.i"
+
+// such features are generated by the following pragmas
+#if 0
+%feature("modula3:enumitem:enum","Days") DAY_MONDAY;
+%feature("modula3:enumitem:name","monday") DAY_MONDAY;
+%feature("modula3:enumitem:conv","int:int") DAY_MONDAY;
+
+%feature("modula3:enumitem:enum","Month") MTHB_JANUARY;
+%feature("modula3:enumitem:name","january") MTHB_JANUARY;
+%feature("modula3:enumitem:conv","set:int") MTHB_JANUARY;
+//%feature("modula3:constset:type","MonthSet") MTHB_JANUARY; /*type in the constant definition*/
+%feature("modula3:constset:set", "MonthSet") MTHB_JANUARY; /*remarks that the 'type' is a set type*/
+%feature("modula3:constset:base","Month") MTHB_JANUARY;
+%feature("modula3:constset:name","monthsJanuary") MTHB_JANUARY;
+%feature("modula3:constset:conv","set:set") MTHB_JANUARY; /*conversion of the bit pattern: no change*/
+
+%feature("modula3:enumitem:enum","Color") BLUE;
+%feature("modula3:enumitem:name","blue") BLUE;
+%feature("modula3:enumitem:conv","int:int") BLUE;
+
+%feature("modula3:constint:type","INTEGER") Foo::IMPULSE;
+%feature("modula3:constint:name","impulse") Foo::IMPULSE;
+%feature("modula3:constint:conv","int:int") Foo::IMPULSE;
+#endif
+
+%rename(pi) PI;
+
+%pragma(modula3) enumitem="prefix=DAY_;int;srcstyle=underscore;Day";
+
+%pragma(modula3) enumitem="enum=color;int;srcstyle=underscore;Color";
+%pragma(modula3) makesetofenum="Color";
+%pragma(modula3) constset="prefix=CLB_;set;srcstyle=underscore,prefix=clb;ColorSet,Color";
+
+%pragma(modula3) enumitem="prefix=MTHB_,enum=calendar;set;srcstyle=underscore;Month";
+%pragma(modula3) makesetofenum="Month";
+%pragma(modula3) constset="prefix=MTHB_,enum=calendar;set;srcstyle=underscore,prefix=monthset;MonthSet,Month";
+
+%pragma(modula3) constint="prefix=Answer::Foo::,enum=Answer::Foo::speed;int;srcstyle=underscore,prefix=speed;INTEGER";
+
+%pragma(modula3) constint="prefix=Answer::,enum=Answer::;int;srcstyle=underscore,prefix=answer;CARDINAL";
+
+%rename(AnswerFoo) Answer::Foo;
+%typemap("m3rawrettype") Answer::Foo * %{AnswerFoo%}
+%typemap("m3rawintype") Answer::Foo * %{AnswerFoo%}
+%typemap("m3rawinmode") Answer::Foo * %{%}
+%typemap("m3wraprettype") Answer::Foo * %{AnswerFoo%}
+%typemap("m3wrapintype") Answer::Foo * %{AnswerFoo%}
+%typemap("m3wrapinmode") Answer::Foo * %{%}
+%typemap("m3wrapargraw") Answer::Foo * %{self.cxxObj%}
+
+%typemap("m3wrapretvar") Answer::Foo * %{cxxObj : ExampleRaw.AnswerFoo;%}
+%typemap("m3wrapretraw") Answer::Foo * %{cxxObj%}
+%typemap("m3wrapretconv") Answer::Foo * %{NEW(AnswerFoo,cxxObj:=cxxObj)%}
+
+
+%typemap("m3rawintype") Answer::Foo::speed %{C.int%};
+%typemap("m3rawintype:import") Answer::Foo::speed %{Ctypes AS C%};
+%typemap("m3wrapintype") Answer::Foo::speed %{[-2..3]%};
+
+%typemap("m3wrapintype") color %{Color%};
+%typemap("m3wrapargraw") color %{ORD($1_name)%};
+
+/* Let's just grab the original header file here */
+%include "example.h"
diff --git a/Examples/modula3/exception/Makefile b/Examples/modula3/exception/Makefile
new file mode 100644
index 0000000..2518a22
--- /dev/null
+++ b/Examples/modula3/exception/Makefile
@@ -0,0 +1,23 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+SWIGOPT =
+MODULA3SRCS = *.[im]3
+MODULA3FLAGS= -o runme
+
+all:: modula3
+
+modula3::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3_cpp
+# $(MAKE) -f $(TOP)/Makefile MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile
+ m3ppinplace $(MODULA3SRCS)
+ mv m3makefile $(MODULA3SRCS) src/
+ cm3
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile modula3_clean
+
+check: all
diff --git a/Examples/modula3/exception/example.h b/Examples/modula3/exception/example.h
new file mode 100644
index 0000000..0e9e0e8
--- /dev/null
+++ b/Examples/modula3/exception/example.h
@@ -0,0 +1,18 @@
+/* File : example.h */
+
+enum error {OK, OVERFLOW, DIVISION_BY_ZERO, NEGATIVE_RADICAND, NEGATIVE_BASE};
+typedef error errorstate; /* just to separate the typemaps */
+
+error acc_add (double &x, double y);
+error acc_sub (double &x, double y);
+error acc_mul (double &x, double y);
+error acc_div (double &x, double y);
+
+double op_add (double x, double y, errorstate &err);
+double op_sub (double x, double y, errorstate &err);
+double op_mul (double x, double y, errorstate &err);
+double op_div (double x, double y, errorstate &err);
+double op_sqrt (double x, errorstate &err);
+double op_pow (double x, double y, errorstate &err);
+
+double op_noexc (double x, double y);
diff --git a/Examples/modula3/exception/example.i b/Examples/modula3/exception/example.i
new file mode 100644
index 0000000..92a716f
--- /dev/null
+++ b/Examples/modula3/exception/example.i
@@ -0,0 +1,43 @@
+/* File : example.i */
+%module Example
+
+%{
+#include "example.h"
+%}
+
+%insert(m3wrapintf) %{
+EXCEPTION E(Error);
+%}
+%insert(m3wrapimpl) %{
+IMPORT Ctypes AS C;
+%}
+
+%pragma(modula3) enumitem="enum=error;int;srcstyle=underscore;Error";
+
+%typemap("m3rawintype") double & %{C.double%};
+%typemap("m3wrapintype") double & %{LONGREAL%};
+
+%typemap("m3wraprettype") error ""
+%typemap("m3wrapretvar") error "rawerr: C.int;"
+%typemap("m3wrapretraw") error "rawerr"
+%typemap("m3wrapretcheck:throws") error "E"
+%typemap("m3wrapretcheck") error
+%{VAR err := VAL(rawerr, Error);
+BEGIN
+IF err # Error.ok THEN
+RAISE E(err);
+END;
+END;%}
+
+%typemap("m3rawintype") errorstate & %{C.int%};
+%typemap("m3wrapintype",numinputs=0) errorstate & %{%};
+%typemap("m3wrapargvar") errorstate & %{err:C.int:=ORD(Error.ok);%};
+%typemap("m3wrapoutcheck:throws") errorstate & "E";
+%typemap("m3wrapoutcheck") errorstate &
+%{IF VAL(err,Error) # Error.ok THEN
+RAISE E(VAL(err,Error));
+END;%}
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
diff --git a/Examples/modula3/reference/Makefile b/Examples/modula3/reference/Makefile
new file mode 100644
index 0000000..b31577a
--- /dev/null
+++ b/Examples/modula3/reference/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+TARGET = example
+INTERFACE = example.i
+SWIGOPT = -c++
+MODULA3SRCS = *.[im]3
+
+all:: modula3
+
+modula3::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
+ m3ppinplace $(MODULA3SRCS)
+ mv m3makefile $(MODULA3SRCS) src/
+ cm3
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile modula3_clean
+
+check: all
diff --git a/Examples/modula3/reference/example.cxx b/Examples/modula3/reference/example.cxx
new file mode 100644
index 0000000..649b016
--- /dev/null
+++ b/Examples/modula3/reference/example.cxx
@@ -0,0 +1,46 @@
+/* File : example.cxx */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include "example.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+Vector operator+(const Vector &a, const Vector &b) {
+ Vector r;
+ r.x = a.x + b.x;
+ r.y = a.y + b.y;
+ r.z = a.z + b.z;
+ return r;
+}
+
+char *Vector::print() {
+ static char temp[512];
+ sprintf(temp,"Vector %x (%g,%g,%g)", (int)this, x,y,z);
+ return temp;
+}
+
+VectorArray::VectorArray(int size) {
+ items = new Vector[size];
+ maxsize = size;
+}
+
+VectorArray::~VectorArray() {
+ delete [] items;
+}
+
+Vector &VectorArray::operator[](int index) {
+ if ((index < 0) || (index >= maxsize)) {
+ printf("Panic! Array index out of bounds.\n");
+ exit(1);
+ }
+ return items[index];
+}
+
+int VectorArray::size() {
+ return maxsize;
+}
+
diff --git a/Examples/modula3/reference/example.h b/Examples/modula3/reference/example.h
new file mode 100644
index 0000000..0a9cd44
--- /dev/null
+++ b/Examples/modula3/reference/example.h
@@ -0,0 +1,22 @@
+/* File : example.h */
+
+struct Vector {
+private:
+ double x,y,z;
+public:
+ Vector() : x(0), y(0), z(0) { };
+ Vector(double x, double y, double z) : x(x), y(y), z(z) { };
+ Vector operator+(const Vector &b) const;
+ char *print();
+};
+
+struct VectorArray {
+private:
+ Vector *items;
+ int maxsize;
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ Vector &operator[](int);
+ int size();
+};
diff --git a/Examples/modula3/reference/example.i b/Examples/modula3/reference/example.i
new file mode 100644
index 0000000..0020909
--- /dev/null
+++ b/Examples/modula3/reference/example.i
@@ -0,0 +1,32 @@
+/* File : example.i */
+
+/* This file has a few "typical" uses of C++ references. */
+
+%module Example
+
+%{
+#include "example.h"
+%}
+
+%pragma(modula3) unsafe="1";
+
+%insert(m3wrapintf) %{FROM ExampleRaw IMPORT Vector, VectorArray;%}
+%insert(m3wrapimpl) %{FROM ExampleRaw IMPORT Vector, VectorArray;%}
+
+%typemap(m3wrapretvar) Vector %{vec: UNTRACED REF Vector;%}
+%typemap(m3wrapretraw) Vector %{vec%}
+%typemap(m3wrapretconv) Vector %{vec^%}
+
+
+/* This helper function calls an overloaded operator */
+%inline %{
+Vector addv(const Vector &a, const Vector &b) {
+ return a+b;
+}
+%}
+
+%rename(Vector_Clear) Vector::Vector();
+%rename(Add) Vector::operator+;
+%rename(GetItem) VectorArray::operator[];
+
+%include "example.h"
diff --git a/Examples/modula3/simple/Makefile b/Examples/modula3/simple/Makefile
new file mode 100644
index 0000000..834521f
--- /dev/null
+++ b/Examples/modula3/simple/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+TARGET = example
+INTERFACE = example.i
+SWIGOPT =
+MODULA3SRCS = *.[im]3
+
+all:: modula3
+
+modula3::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
+ m3ppinplace $(MODULA3SRCS)
+ mv m3makefile $(MODULA3SRCS) src/
+ cm3
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile modula3_clean
+
+check: all
diff --git a/Examples/modula3/simple/example.c b/Examples/modula3/simple/example.c
new file mode 100644
index 0000000..1c2af78
--- /dev/null
+++ b/Examples/modula3/simple/example.c
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/modula3/simple/example.i b/Examples/modula3/simple/example.i
new file mode 100644
index 0000000..1694e6d
--- /dev/null
+++ b/Examples/modula3/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module Example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
diff --git a/Examples/modula3/typemap/Makefile b/Examples/modula3/typemap/Makefile
new file mode 100644
index 0000000..834521f
--- /dev/null
+++ b/Examples/modula3/typemap/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+TARGET = example
+INTERFACE = example.i
+SWIGOPT =
+MODULA3SRCS = *.[im]3
+
+all:: modula3
+
+modula3::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
+ m3ppinplace $(MODULA3SRCS)
+ mv m3makefile $(MODULA3SRCS) src/
+ cm3
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile modula3_clean
+
+check: all
diff --git a/Examples/modula3/typemap/example.i b/Examples/modula3/typemap/example.i
new file mode 100644
index 0000000..2f454ef
--- /dev/null
+++ b/Examples/modula3/typemap/example.i
@@ -0,0 +1,90 @@
+/* File : example.i */
+%module Example
+
+%pragma(modula3) unsafe="true";
+
+%insert(m3wrapintf) %{FROM ExampleRaw IMPORT Window, Point;
+%}
+%insert(m3wrapimpl) %{FROM ExampleRaw IMPORT Window, Point;
+IMPORT M3toC;
+IMPORT Ctypes AS C;
+%}
+
+/* Typemap applied to patterns of multiple arguments */
+
+%typemap(m3rawinmode) (char *outstr) %{VAR%}
+%typemap(m3rawintype) (char *outstr) %{CHAR%}
+%typemap(m3wrapinmode) (char *outstr, int size) %{VAR%}
+%typemap(m3wrapintype) (char *outstr, int size) %{ARRAY OF CHAR%}
+%typemap(m3wrapargraw) (char *outstr, int size) %{$1_name[0], NUMBER($1_name)%}
+
+
+%typemap(m3rawinmode) (const struct Window *) %{READONLY%}
+%typemap(m3wrapinmode) (const struct Window *) %{READONLY%}
+%typemap(m3rawintype) ( struct Window *) %{Window%}
+%typemap(m3wrapintype) ( struct Window *) %{Window%}
+
+%typemap(m3rawinmode) (const char *str []) %{READONLY%}
+%typemap(m3wrapinmode) (const char *str []) %{READONLY%}
+%typemap(m3rawintype) (const char *str []) %{(*ARRAY OF*) C.char_star%}
+%typemap(m3wrapintype) (const char *str []) %{ARRAY OF TEXT%}
+%typemap(m3wrapargvar) (const char *str []) %{$1: REF ARRAY OF C.char_star;%}
+%typemap(m3wrapargraw) (const char *str []) %{$1[0]%}
+%typemap(m3wrapinconv) (const char *str []) %{$1:= NEW(REF ARRAY OF C.char_star,NUMBER($1_name));
+FOR i:=FIRST($1_name) TO LAST($1_name) DO
+$1[i]:=M3toC.SharedTtoS($1_name[i]);
+END;%}
+%typemap(m3wrapfreearg) (const char *str [])
+%{FOR i:=FIRST($1_name) TO LAST($1_name) DO
+M3toC.FreeSharedS($1_name[i],$1[i]);
+END;%}
+
+%typemap(m3wraprettype) char * %{TEXT%}
+%typemap(m3wrapretvar) char * %{result_string: C.char_star;%}
+%typemap(m3wrapretraw) char * %{result_string%}
+%typemap(m3wrapretconv) char * %{M3toC.CopyStoT(result_string)%}
+
+struct Window {
+ char *label;
+ int left,top,width,height;
+};
+
+
+%typemap(m3wrapinname) (int x, int y) %{p%}
+%typemap(m3wrapinmode) (int x, int y) %{READONLY%}
+%typemap(m3wrapintype) (int x, int y) %{Point%}
+%typemap(m3wrapargraw) (int x, int y) %{p.$1_name, p.$2_name%}
+
+%typemap(m3wrapargraw) (int &x, int &y) %{p.$1_name, p.$2_name%}
+%typemap(m3wrapintype) (int &x, int &y) %{Point%}
+%typemap(m3wrapoutname) (int &x, int &y) %{p%}
+%typemap(m3wrapouttype) (int &x, int &y) %{Point%}
+%typemap(m3wrapargdir) (int &x, int &y) "out"
+
+
+%typemap(m3wrapargvar) int &left, int &top, int &width, int &height "$1:C.int;"
+%typemap(m3wrapargraw) int &left, int &top, int &width, int &height "$1"
+%typemap(m3wrapoutconv) int &left, int &top, int &width, int &height "$1"
+
+%typemap(m3wrapargdir) int &left, int &top "out"
+
+%typemap(m3wrapouttype) int &width, int &height "CARDINAL"
+%typemap(m3wrapargdir) int &width, int &height "out"
+
+struct Point {
+ int x,y;
+};
+
+%m3multiretval get_box;
+
+void set_label ( struct Window *win, const char *str, bool activate);
+void set_multi_label ( struct Window *win, const char *str []);
+void write_label (const struct Window *win, char *outstr, int size);
+int get_label (const struct Window *win, char *outstr, int size);
+char *get_label_ptr (const struct Window *win);
+void move(struct Window *win, int x, int y);
+int get_area(const struct Window *win);
+void get_box(const struct Window *win, int &left, int &top, int &width, int &height);
+void get_left(const struct Window *win, int &left);
+void get_mouse(const struct Window *win, int &x, int &y);
+int get_attached_data(const struct Window *win, const char *id);