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
7
SWIG/Examples/modula3/check.list
Normal file
7
SWIG/Examples/modula3/check.list
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
enum
|
||||
exception
|
||||
reference
|
||||
simple
|
||||
typemap
|
||||
17
SWIG/Examples/modula3/class/.cvsignore
Normal file
17
SWIG/Examples/modula3/class/.cvsignore
Normal 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
|
||||
25
SWIG/Examples/modula3/class/Makefile
Normal file
25
SWIG/Examples/modula3/class/Makefile
Normal 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
|
||||
28
SWIG/Examples/modula3/class/example.cxx
Normal file
28
SWIG/Examples/modula3/class/example.cxx
Normal 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;
|
||||
}
|
||||
44
SWIG/Examples/modula3/class/example.h
Normal file
44
SWIG/Examples/modula3/class/example.h
Normal 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;
|
||||
};
|
||||
32
SWIG/Examples/modula3/class/example.i
Normal file
32
SWIG/Examples/modula3/class/example.i
Normal 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"
|
||||
11
SWIG/Examples/modula3/class/swig.tmpl
Normal file
11
SWIG/Examples/modula3/class/swig.tmpl
Normal 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
|
||||
18
SWIG/Examples/modula3/enum/.cvsignore
Normal file
18
SWIG/Examples/modula3/enum/.cvsignore
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.*
|
||||
*_const*
|
||||
*.i3
|
||||
*.m3
|
||||
m3makefile
|
||||
src
|
||||
LINUXLIBC6
|
||||
*.dll
|
||||
*.dsw
|
||||
*.exp
|
||||
*.lib
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
26
SWIG/Examples/modula3/enum/Makefile
Normal file
26
SWIG/Examples/modula3/enum/Makefile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../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
|
||||
32
SWIG/Examples/modula3/enum/example.cxx
Normal file
32
SWIG/Examples/modula3/enum/example.cxx
Normal file
|
|
@ -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);
|
||||
}
|
||||
83
SWIG/Examples/modula3/enum/example.h
Normal file
83
SWIG/Examples/modula3/enum/example.h
Normal file
|
|
@ -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);
|
||||
72
SWIG/Examples/modula3/enum/example.i
Normal file
72
SWIG/Examples/modula3/enum/example.i
Normal file
|
|
@ -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"
|
||||
17
SWIG/Examples/modula3/exception/.cvsignore
Normal file
17
SWIG/Examples/modula3/exception/.cvsignore
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.*
|
||||
*.i3
|
||||
*.m3
|
||||
m3makefile
|
||||
src
|
||||
LINUXLIBC6
|
||||
*.dll
|
||||
*.dsw
|
||||
*.exp
|
||||
*.lib
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
23
SWIG/Examples/modula3/exception/Makefile
Normal file
23
SWIG/Examples/modula3/exception/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../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
|
||||
18
SWIG/Examples/modula3/exception/example.h
Normal file
18
SWIG/Examples/modula3/exception/example.h
Normal file
|
|
@ -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);
|
||||
43
SWIG/Examples/modula3/exception/example.i
Normal file
43
SWIG/Examples/modula3/exception/example.i
Normal file
|
|
@ -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"
|
||||
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"
|
||||
8
SWIG/Examples/modula3/simple/.cvsignore
Normal file
8
SWIG/Examples/modula3/simple/.cvsignore
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
*_wrap.c
|
||||
*_wrap.xml
|
||||
*.i3
|
||||
*.m3
|
||||
m3makefile
|
||||
src
|
||||
Release
|
||||
Debug
|
||||
21
SWIG/Examples/modula3/simple/Makefile
Normal file
21
SWIG/Examples/modula3/simple/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../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
|
||||
18
SWIG/Examples/modula3/simple/example.c
Normal file
18
SWIG/Examples/modula3/simple/example.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
5
SWIG/Examples/modula3/simple/example.i
Normal file
5
SWIG/Examples/modula3/simple/example.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module Example
|
||||
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
17
SWIG/Examples/modula3/typemap/.cvsignore
Normal file
17
SWIG/Examples/modula3/typemap/.cvsignore
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.*
|
||||
*.i3
|
||||
*.m3
|
||||
m3makefile
|
||||
src
|
||||
LINUXLIBC6
|
||||
*.dll
|
||||
*.dsw
|
||||
*.exp
|
||||
*.lib
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
21
SWIG/Examples/modula3/typemap/Makefile
Normal file
21
SWIG/Examples/modula3/typemap/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../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
|
||||
90
SWIG/Examples/modula3/typemap/example.i
Normal file
90
SWIG/Examples/modula3/typemap/example.i
Normal file
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue