Added support for the D programming languge.

It is still a bit rough around some edges, particularly with regard to multi-threading and operator overloading, and there are some documentation bits missing, but it should be fine for basic use.

The test-suite should build and run fine with the current versions of DMD, LDC and Tango (at least) on Linux x86_64 and Mac OS X 10.6.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12299 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
David Nadlinger 2010-11-18 00:24:02 +00:00
commit 03aefbc6e9
176 changed files with 16449 additions and 29 deletions

View file

@ -0,0 +1,28 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ example_wrap.c
EXTRA_LDFLAGS = example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
all:: d
d::
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
$(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean::
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_clean
check: all

View file

@ -0,0 +1,28 @@
module runme;
import tango.io.Stdout;
static import example;
void main() {
Stdout.formatln("ICONST = {} (should be 42)", example.ICONST);
Stdout.formatln("FCONST = {} (should be 2.18)", example.FCONST);
Stdout.formatln("CCONST = {} (should be 'x')", example.CCONST);
Stdout.formatln("CCONST2 = {} (this should be on a new line)", example.CCONST2);
Stdout.formatln("SCONST = {} (should be 'Hello World')", example.SCONST);
Stdout.formatln("SCONST2 = {} (should be '\"Hello World\"')", example.SCONST2);
Stdout.formatln("EXPR = {} (should be 48.55)", example.EXPR);
Stdout.formatln("iconst = {} (should be 37)", example.iconst);
Stdout.formatln("fconst = {} (should be 3.14)", example.fconst);
static if (is(typeof(example.EXTERN))) {
Stdout.formatln("EXTERN should not be defined, but is: {}.", example.EXTERN );
} else {
Stdout.formatln("EXTERN isn't defined (good)");
}
static if (is(typeof(example.FOO))) {
Stdout.formatln("FOO should not be defined, but is: {}.", example.FOO);
} else {
Stdout.formatln("FOO isn't defined (good)");
}
}

View file

@ -0,0 +1,28 @@
module runme;
import std.stdio;
static import example;
void main() {
writefln("ICONST = %s (should be 42)", example.ICONST);
writefln("FCONST = %s (should be 2.1828)", example.FCONST);
writefln("CCONST = %s (should be 'x')", example.CCONST);
writefln("CCONST2 = %s (this should be on a new line)", example.CCONST2);
writefln("SCONST = %s (should be 'Hello World')", example.SCONST);
writefln("SCONST2 = %s (should be '\"Hello World\"')", example.SCONST2);
writefln("EXPR = %s (should be 48.5484)", example.EXPR);
writefln("iconst = %s (should be 37)", example.iconst);
writefln("fconst = %s (should be 3.14)", example.fconst);
static if (is(typeof(example.EXTERN))) {
writefln("EXTERN should not be defined, but is: %s.", example.EXTERN );
} else {
writeln("EXTERN isn't defined (good)");
}
static if (is(typeof(example.FOO))) {
writefln("FOO should not be defined, but is: %s.", example.FOO);
} else {
writeln("FOO isn't defined (good)");
}
}

View file

@ -0,0 +1,23 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.41
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
module example;
static import example_wrap;
static import tango.stdc.stringz;
public const int ICONST = 42;
public const double FCONST = 2.1828;
public const char CCONST = 'x';
public const char CCONST2 = '\n';
public const char[] SCONST = "Hello World";
public const char[] SCONST2 = "\"Hello World\"";
public const double EXPR = 42+3*(2.1828);
public const int iconst = 37;
public const double fconst = 3.14;

View file

@ -0,0 +1,32 @@
/* File : example.i */
%module example
/* Force the generated D code to use the C constant values rather than
retrieving them at runtime. You can also try disabling the feature and
compare the generated code. */
%dnativeconst;
/* A few preprocessor macros */
#define ICONST 42
#define FCONST 2.1828
#define CCONST 'x'
#define CCONST2 '\n'
#define SCONST "Hello World"
#define SCONST2 "\"Hello World\""
/* This should work just fine */
#define EXPR ICONST + 3*(FCONST)
/* This shouldn't do anything */
#define EXTERN extern
/* Neither should this (BAR isn't defined) */
#define FOO (ICONST + BAR)
/* The following directives also produce constants */
%constant int iconst = 37;
%constant double fconst = 3.14;