update swig on windows

This commit is contained in:
Bassem Girgis
2019-08-04 21:38:19 -05:00
parent 8414b7136b
commit 76ad52be58
5943 changed files with 91790 additions and 71892 deletions

View File

@@ -0,0 +1,17 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SRCS = matrix.c vector.c
TARGET = my-guile
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-lm' guile_augmented
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean

View File

@@ -0,0 +1,13 @@
Matrix example. To run the example, execute the program 'matrix' and
type the following :
(load "runme.scm")
(do-test 0)
Alternatively, use the command-line:
./my-guile -e do-test -s runme.scm
Or, if your operating system is spiffy enough:
./runme.scm

View File

@@ -0,0 +1,17 @@
/*** Matrix and vector example ***/
%module Matrix
%{
#include <math.h>
%}
%include guilemain.i
%include matrix.i
%include vector.i
// Include the math library so we can get some random numbers and
// other stuff
%include math.i
extern double drand48();

View File

@@ -0,0 +1,61 @@
/* FILE : matrix.c : some simple 4x4 matrix operations */
#include <stdlib.h>
#include <stdio.h>
double **new_matrix() {
int i;
double **M;
M = (double **) malloc(4*sizeof(double *));
M[0] = (double *) malloc(16*sizeof(double));
for (i = 0; i < 4; i++) {
M[i] = M[0] + 4*i;
}
return M;
}
void destroy_matrix(double **M) {
free(M[0]);
free(M);
}
void print_matrix(double **M) {
int i,j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
printf("%10g ", M[i][j]);
}
printf("\n");
}
}
void mat_mult(double **m1, double **m2, double **m3) {
int i,j,k;
double temp[4][4];
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++) {
temp[i][j] = 0;
for (k = 0; k < 4; k++)
temp[i][j] += m1[i][k]*m2[k][j];
}
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
m3[i][j] = temp[i][j];
}

View File

@@ -0,0 +1,36 @@
//
// FILE : matrix.i
%{
void set_m(double **M, int i, int j, double val) {
M[i][j] = val;
}
double get_m(double **M, int i, int j) {
return M[i][j];
}
%}
%inline {
/*** Matrix Operations ***/
extern double **new_matrix();
/* Creates a new matrix and returns a pointer to it */
extern void destroy_matrix(double **M);
/* Destroys the matrix M */
extern void print_matrix(double **M);
/* Prints out the matrix M */
extern void set_m(double **M, int i, int j, double val);
/* Sets M[i][j] = val*/
extern double get_m(double **M, int i, int j);
/* Returns M[i][j] */
extern void mat_mult(double **a, double **b, double **c);
/* Multiplies matrix a by b and places the result in c*/
}

View File

@@ -0,0 +1,210 @@
;;; Authors: David Beazley <beazley@cs.uchicago.edu>, 1999
;;; Martin Froehlich <MartinFroehlich@ACM.org>, 2000
;;;
;;; PURPOSE OF THIS FILE: This file is an example for how to use the guile
;;; scripting options with a little more than trivial script. Example
;;; derived from David Beazley's matrix evaluation example. David
;;; Beazley's annotation: >>Guile script for testing out matrix
;;; operations. Disclaimer : I'm not a very good scheme
;;; programmer<<. Martin Froehlich's annotation: >>I'm not a very good
;;; scheme programmer, too<<.
;;;
;;; Explanation: The three lines at the beginning of this script are
;;; telling the kernel to load the enhanced guile interpreter named
;;; "matrix"; to execute the function "do-test" (-e option) after loading
;;; this script (-s option). There are a lot more options which allow for
;;; even finer tuning. SEE ALSO: Section "Guile Scripts" in the "Guile
;;; reference manual -- Part I: Preliminaries".
;;;
;;;
;;; This program is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;;; Create a zero matrix
(define (zero M)
(define (zero-loop M i j)
(if (< i 4)
(if (< j 4) (begin
(set-m M i j 0.0)
(zero-loop M i (+ j 1)))
(zero-loop M (+ i 1) 0))))
(zero-loop M 0 0))
;;; Create an identity matrix
(define (identity M)
(define (iloop M i)
(if (< i 4) (begin
(set-m M i i 1.0)
(iloop M (+ i 1)))))
(zero M)
(iloop M 0))
;;; Rotate around x axis
(define (rotx M r)
(define temp (new-matrix))
(define rd (/ (* r 3.14159) 180.0))
(zero temp)
(set-m temp 0 0 1.0)
(set-m temp 1 1 (cos rd))
(set-m temp 1 2 (- 0 (sin rd)))
(set-m temp 2 1 (sin rd))
(set-m temp 2 2 (cos rd))
(set-m temp 3 3 1.0)
(mat-mult M temp M)
(destroy-matrix temp))
;;; Rotate around y axis
(define (roty M r)
(define temp (new-matrix))
(define rd (/ (* r 3.14159) 180.0))
(zero temp)
(set-m temp 1 1 1.0)
(set-m temp 0 0 (cos rd))
(set-m temp 0 2 (sin rd))
(set-m temp 2 0 (- 0 (sin rd)))
(set-m temp 2 2 (cos rd))
(set-m temp 3 3 1.0)
(mat-mult M temp M)
(destroy-matrix temp))
;;; Rotate around z axis
(define (rotz M r)
(define temp (new-matrix))
(define rd (/ (* r 3.14159) 180.0))
(zero temp)
(set-m temp 0 0 (cos rd))
(set-m temp 0 1 (- 0 (sin rd)))
(set-m temp 1 0 (sin rd))
(set-m temp 1 1 (cos rd))
(set-m temp 2 2 1.0)
(set-m temp 3 3 1.0)
(mat-mult M temp M)
(destroy-matrix temp))
;;; Scale a matrix
(define (scale M s)
(define temp (new-matrix))
(define (sloop m i s)
(if (< i 4) (begin
(set-m m i i s)
(sloop m (+ i 1) s))))
(zero temp)
(sloop temp 0 s)
(mat-mult M temp M)
(destroy-matrix temp))
;;; Make a matrix with random elements
(define (randmat M)
(define (rand-loop M i j)
(if (< i 4)
(if (< j 4)
(begin
(set-m M i j (drand48))
(rand-loop M i (+ j 1)))
(rand-loop M (+ i 1) 0))))
(rand-loop M 0 0))
;;; stray definitions collected here
(define (rot-test M v t i)
(if (< i 360) (begin
(rotx M 1)
(rotz M -0.5)
(transform M v t)
(rot-test M v t (+ i 1)))))
(define (create-matrix) ; Create some matrices
(let loop ((i 0) (result '()))
(if (< i 200)
(loop (+ i 1) (cons (new-matrix) result))
result)))
(define (add-mat M ML)
(define (add-two m1 m2 i j)
(if (< i 4)
(if (< j 4)
(begin
(set-m m1 i j (+ (get-m m1 i j) (get-m m2 i j)))
(add-two m1 m2 i (+ j 1)))
(add-two m1 m2 (+ i 1) 0))))
(if (null? ML) *unspecified*
(begin
(add-two M (car ML) 0 0)
(add-mat M (cdr ML)))))
(define (cleanup ML)
(if (null? ML) *unspecified*
(begin
(destroy-matrix (car ML))
(cleanup (cdr ML)))))
(define (make-random ML) ; Put random values in them
(if (null? ML) *unspecified*
(begin
(randmat (car ML))
(make-random (cdr ML)))))
(define (mul-mat m ML)
(if (null? ML) *unspecified*
(begin
(mat-mult m (car ML) m)
(mul-mat m (cdr ML)))))
;;; Now we'll hammer on things a little bit just to make
;;; sure everything works.
(define M1 (new-matrix)) ; a matrix
(define v (createv 1 2 3 4)) ; a vector
(define t (createv 0 0 0 0)) ; the zero-vector
(define M-list (create-matrix)) ; get list of marices
(define M (new-matrix)) ; yet another matrix
(display "variables defined\n")
(define (do-test x)
(display "Testing matrix program...\n")
(identity M1)
(print-matrix M1)
(display "Rotate-x 45 degrees\n")
(rotx M1 45)
(print-matrix M1)
(display "Rotate y 30 degrees\n")
(roty M1 30)
(print-matrix M1)
(display "Rotate z 15 degrees\n")
(rotz M1 15)
(print-matrix M1)
(display "Scale 0.5\n")
(scale M1 0.5)
(print-matrix M1)
;; Rotating ...
(display "Rotating...\n")
(rot-test M1 v t 0)
(printv t)
(make-random M-list)
(zero M1)
(display "Adding them together (in Guile)\n")
(add-mat M1 M-list)
(print-matrix M1)
(display "Doing 200 multiplications (mostly in C)\n")
(randmat M)
(mul-mat M M-list)
(display "Cleaning up\n")
(cleanup M-list))

View File

@@ -0,0 +1,44 @@
/* File : vector.c */
#include <stdlib.h>
#include <stdio.h>
#include "vector.h"
Vector *createv(double x, double y, double z, double w) {
Vector *n;
n = (Vector *) malloc(sizeof(Vector));
n->x = x;
n->y = y;
n->z = z;
n->w = w;
return n;
}
/* Destroy vector */
void destroyv(Vector *v) {
free(v);
}
/* Print a vector */
void printv(Vector *v) {
printf("x = %g, y = %g, z = %g, w = %g\n", v->x, v->y, v->z, v->w);
}
/* Do a transformation */
void transform(double **m, Vector *v, Vector *r) {
r->x = m[0][0]*v->x + m[0][1]*v->y + m[0][2]*v->z + m[0][3]*v->w;
r->y = m[1][0]*v->x + m[1][1]*v->y + m[1][2]*v->z + m[1][3]*v->w;
r->z = m[2][0]*v->x + m[2][1]*v->y + m[2][2]*v->z + m[2][3]*v->w;
r->w = m[3][0]*v->x + m[3][1]*v->y + m[3][2]*v->z + m[3][3]*v->w;
}

View File

@@ -0,0 +1,10 @@
#include <math.h>
typedef struct {
double x;
double y;
double z;
double w;
} Vector;

View File

@@ -0,0 +1,22 @@
//
// FILE : vector.i
%{
#include "vector.h"
%}
%inline {
extern Vector *createv(double x,double y,double z,double w);
/* Creates a new vector v(x,y,z,w) */
extern void destroyv(Vector *v);
/* Destroys the vector v */
extern void printv(Vector *v);
/* Prints out the vector v */
extern void transform(double **T, Vector *v, Vector *t);
/* Transforms vector c to vector t by M*v --> t */
}