added basic Modula-3 support
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5776 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ad57fc3545
commit
483d8b4367
57 changed files with 6645 additions and 380 deletions
15
SWIG/Examples/modula3/reference/.cvsignore
Normal file
15
SWIG/Examples/modula3/reference/.cvsignore
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.*
|
||||
*.i3
|
||||
*.m3
|
||||
*.dll
|
||||
*.dsw
|
||||
*.exp
|
||||
*.lib
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
src
|
||||
Release
|
||||
Debug
|
||||
21
SWIG/Examples/modula3/reference/Makefile
Normal file
21
SWIG/Examples/modula3/reference/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../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
|
||||
41
SWIG/Examples/modula3/reference/example.cxx
Normal file
41
SWIG/Examples/modula3/reference/example.cxx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* File : example.cxx */
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
22
SWIG/Examples/modula3/reference/example.h
Normal file
22
SWIG/Examples/modula3/reference/example.h
Normal file
|
|
@ -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();
|
||||
};
|
||||
32
SWIG/Examples/modula3/reference/example.i
Normal file
32
SWIG/Examples/modula3/reference/example.i
Normal file
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue