summaryrefslogtreecommitdiff
path: root/Examples/modula3/reference
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/reference
downloadswig-tarball-master.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/reference')
-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
4 files changed, 121 insertions, 0 deletions
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"