#if (!defined(__macintosh__) && !defined(WIN32)) 
#	define HAVE_CONFIG_H
#endif

extern "C"
{
# include "sq.h"
  int nilObj;
  int specialObjectsOop;

  int findClassOfMethodforClass(int meth, int currClass);
  int findSelectorOfMethodforClass(int meth, int currClass);
  int printCallStack(void);
};

/* memory access macros */
#define byteAt(i) (*((unsigned char *) (i)))
#define byteAtput(i, val) (*((unsigned char *) (i)) = val)
#define longAt(i) (*((int *) (i)))
#define longAtput(i, val) (*((int *) (i)) = val)

int findClassOfMethodforClass(int meth, int initClass) {
    int methodArray;
    int i;
    int done;
    int classDict;
    int classDictSize;
    int currClass= initClass;
    int sz;
    int header;

	done = 0;
	while (!(done)) {
		classDict = longAt(((((char *) currClass)) + 4) + (1 << 2));
		/* begin fetchWordLengthOf: */
		/* begin sizeBitsOf: */
		header = longAt(classDict);
		if ((header & 3) == 0) {
			sz = (longAt(classDict - 8)) & 4294967292U;
			goto l1;
		} else {
			sz = header & 252;
			goto l1;
		}
	l1:	/* end sizeBitsOf: */;
		classDictSize = ((unsigned) (sz - 4)) >> 2;
		methodArray = longAt(((((char *) classDict)) + 4) + (1 << 2));
		i = 0;
		while (i < (classDictSize - 2)) {
			if (meth == (longAt(((((char *) methodArray)) + 4) + (i << 2)))) {
				return currClass;
			}
			i += 1;
		}
		currClass = longAt(((((char *) currClass)) + 4) + (0 << 2));
		done = currClass == nilObj;
	}
	return initClass;
}



int findSelectorOfMethodforClass(int meth, int currClass) {
    int methodArray;
    int done;
    int i;
    int classDict;
    int classDictSize;
    int sz;
    int header;

	done = 0;
	while (!(done)) {
		classDict = longAt(((((char *) currClass)) + 4) + (1 << 2));
		/* begin fetchWordLengthOf: */
		/* begin sizeBitsOf: */
		header = longAt(classDict);
		if ((header & 3) == 0) {
			sz = (longAt(classDict - 8)) & 4294967292U;
			goto l1;
		} else {
			sz = header & 252;
			goto l1;
		}
	l1:	/* end sizeBitsOf: */;
		classDictSize = ((unsigned) (sz - 4)) >> 2;
		methodArray = longAt(((((char *) classDict)) + 4) + (1 << 2));
		i = 0;
		while (i <= (classDictSize - 2)) {
			if (meth == (longAt(((((char *) methodArray)) + 4) + (i << 2)))) {
				return longAt(((((char *) classDict)) + 4) + ((i + 2) << 2));
			}
			i += 1;
		}
		currClass = longAt(((((char *) currClass)) + 4) + (0 << 2));
		done = currClass == nilObj;
	}
	return longAt(((((char *) specialObjectsOop)) + 4) + (20 << 2));
}

