Added callables
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@29 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
722d67666a
commit
c595c94f1d
5 changed files with 110 additions and 37 deletions
|
|
@ -9,7 +9,7 @@
|
|||
# Set your C++ compiler here. g++ works on most machines,
|
||||
# but you might have to change it depending on your installation.
|
||||
#
|
||||
CC = gcc -g -Wall -DDOH_STRING_UPDATE_LINES -O2
|
||||
CC = cc
|
||||
prefix = /usr/local
|
||||
|
||||
# Comment out the following line if you're on an SGI or don't have ranlib!
|
||||
|
|
@ -20,9 +20,9 @@ AR = ar
|
|||
# Normally, you shouldn't have to change anything below this point #
|
||||
########################################################################
|
||||
|
||||
LIBOBJS = void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
LIBOBJS = callable.o void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
|
||||
LIBSRCS = void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
LIBSRCS = callable.c void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
|
||||
LIBHEADERS = ../Include/doh.h
|
||||
LIB = ../libdoh.a
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ AR = @AR@
|
|||
# Normally, you shouldn't have to change anything below this point #
|
||||
########################################################################
|
||||
|
||||
LIBOBJS = void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
LIBOBJS = callable.o void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
|
||||
LIBSRCS = void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
LIBSRCS = callable.c void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
|
||||
LIBHEADERS = ../Include/doh.h
|
||||
LIB = ../libdoh.a
|
||||
|
|
|
|||
|
|
@ -91,33 +91,6 @@ static DOH *find_internal(DOH *co) {
|
|||
c = (char *) co;
|
||||
n = NewString(c);
|
||||
return n;
|
||||
|
||||
if (doh_debug_level) {
|
||||
DohError(DOH_CONVERSION,"Unknown object '%s' being treated as 'char *'.\n", c);
|
||||
}
|
||||
r = root;
|
||||
s = 0;
|
||||
while (r) {
|
||||
s = r;
|
||||
/* printf("checking %s\n", r->cstr); */
|
||||
d = strcmp(r->cstr,c);
|
||||
if (d == 0) return r->sstr;
|
||||
if (d < 0) r = r->left;
|
||||
else r = r->right;
|
||||
}
|
||||
r = (StringNode *) DohMalloc(sizeof(StringNode));
|
||||
r->cstr = (char *) DohMalloc(strlen(c)+1);
|
||||
strcpy(r->cstr,c);
|
||||
r->sstr = NewString(c);
|
||||
Incref(r->sstr);
|
||||
r->left = 0;
|
||||
r->right = 0;
|
||||
if (!s) { root = r; }
|
||||
else {
|
||||
if (d < 0) s->left = r;
|
||||
else s->right = r;
|
||||
}
|
||||
return r->sstr;
|
||||
}
|
||||
|
||||
/* Destroy an object */
|
||||
|
|
@ -844,6 +817,21 @@ int DohReplace(DOH *src, DOH *token, DOH *rep, int flags) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable methods
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *DohCall(DOH *obj, DOH *args) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohError(DOH_CALLS,"DohCall %x\n",obj);
|
||||
if (DohCheck(b)) {
|
||||
if ((b->objinfo->doh_callable) && (b->objinfo->doh_callable->doh_call)) {
|
||||
return (b->objinfo->doh_callable->doh_call)(b,args);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DohInit(DOH *b) {
|
||||
DohBase *bs = (DohBase *) b;
|
||||
bs->refcount = 1;
|
||||
|
|
|
|||
86
SWIG/Source/DOH/Doh/callable.c
Normal file
86
SWIG/Source/DOH/Doh/callable.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 1100 E 58th Street
|
||||
* Chicago, IL 60637
|
||||
* beazley@cs.uchicago.edu
|
||||
*
|
||||
* Please read the file LICENSE for the copyright and terms by which SWIG
|
||||
* can be used and distributed.
|
||||
****************************************************************************/
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* callable.c
|
||||
*
|
||||
* Callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
DOHCOMMON;
|
||||
DOH *(*func)(DOH *, DOH *);
|
||||
} CallableObj;
|
||||
|
||||
void Callable_delete(DOH *);
|
||||
DOH *Callable_copy(DOH *);
|
||||
DOH *Callable_call(DOH *, DOH *);
|
||||
|
||||
static DohCallableMethods doh_callable_methods = {
|
||||
Callable_call
|
||||
};
|
||||
|
||||
static DohObjInfo DohCallableType = {
|
||||
"CallableObj", /* objname */
|
||||
sizeof(CallableObj), /* objsize */
|
||||
Callable_delete, /* doh_del */
|
||||
Callable_copy, /* doh_copy */
|
||||
0, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
0, /* doh_str */
|
||||
0, /* doh_data */
|
||||
0, /* doh_dump */
|
||||
0, /* doh_load */
|
||||
0, /* doh_len */
|
||||
0, /* doh_hash */
|
||||
0, /* doh_cmp */
|
||||
0, /* doh_mapping */
|
||||
0, /* doh_sequence */
|
||||
0, /* doh_file */
|
||||
0, /* doh_string */
|
||||
&doh_callable_methods, /* doh_callable */
|
||||
0, /* reserved4 */
|
||||
0, /* reserved5 */
|
||||
0, /* reserved6 */
|
||||
0, /* user1 */
|
||||
0, /* user2 */
|
||||
0, /* user3 */
|
||||
0, /* user4 */
|
||||
};
|
||||
|
||||
DOH *NewCallable(DOH *(*func)(DOH *, DOH *)) {
|
||||
CallableObj *c;
|
||||
c = (CallableObj *) DohObjMalloc(sizeof(CallableObj));
|
||||
c->objinfo = &DohCallableType;
|
||||
c->func = func;
|
||||
return (DOH *) c;
|
||||
}
|
||||
|
||||
void Callable_delete(DOH *co) {
|
||||
DohObjFree(co);
|
||||
}
|
||||
|
||||
DOH *Callable_copy(DOH *co) {
|
||||
CallableObj *c = (CallableObj *) co;
|
||||
return NewCallable(c->func);
|
||||
}
|
||||
|
||||
DOH *Callable_call(DOH *co, DOH *args) {
|
||||
CallableObj *c = (CallableObj *) co;
|
||||
return (*c->func)(c,args);
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ typedef struct {
|
|||
|
||||
/* Callable */
|
||||
typedef struct {
|
||||
DOH (*doh_call)(DOH *obj, DOH *args); /* Callable */
|
||||
DOH *(*doh_call)(DOH *obj, DOH *args); /* Callable */
|
||||
} DohCallableMethods;
|
||||
|
||||
|
||||
|
|
@ -200,12 +200,11 @@ extern int DohUngetc(int ch, DOH *obj);
|
|||
extern void DohEncoding(char *name, DOH *(*fn)(DOH *s));
|
||||
extern int DohPrintf(DOH *obj, char *format, ...);
|
||||
extern int DohvPrintf(DOH *obj, char *format, va_list ap);
|
||||
/* extern int DohScanf(DOH *obj, char *format, ...);
|
||||
extern int DohvScanf(DOH *obj, char *format, va_list ap); */
|
||||
|
||||
extern int DohReplace(DOH *src, DOH *token, DOH *rep, int flags);
|
||||
extern DOH *DohReadline(DOH *in);
|
||||
|
||||
extern DOH *DohCall(DOH *obj, DOH *args);
|
||||
|
||||
#ifndef DOH_LONG_NAMES
|
||||
/* Macros to invoke the above functions. Includes the location of
|
||||
the caller to simplify debugging if something goes wrong */
|
||||
|
|
@ -258,7 +257,7 @@ extern DOH *DohReadline(DOH *in);
|
|||
#define Replace DohReplace
|
||||
#define NewScope DohNewScope
|
||||
#define DelScope DohDelScope
|
||||
|
||||
#define Call DohCall
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue