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:
Henning Thielemann 2004-03-19 11:45:29 +00:00
commit 483d8b4367
57 changed files with 6645 additions and 380 deletions

View file

@ -0,0 +1,17 @@
runme
*_wrap.c
*_wrap.cxx
*_wrap.xml
*.iltmp
*.cs
*.dll
*.dsw
*.exp
*.lib
*.ncb
*.opt
*.plg
Release
Debug
src
LINUXLIBC6

View file

@ -0,0 +1,25 @@
TOP = ../..
SWIG = $(TOP)/../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

View file

@ -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;
}

View file

@ -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;
};

View file

@ -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"

View file

@ -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