[Vm-dev] [commit][3013] Check in KedamaPlugin2 (from
http://www.squeaksource.com/ KedamaPlugins).
commits at squeakvm.org
commits at squeakvm.org
Mon Jun 23 23:04:45 UTC 2014
Revision: 3013
Author: lewis
Date: 2014-06-23 16:03:59 -0700 (Mon, 23 Jun 2014)
Log Message:
-----------
Check in KedamaPlugin2 (from http://www.squeaksource.com/KedamaPlugins).
Change plugins.ext to include KedamaPlugin2 only (remove KedamaPlugin).
Modified Paths:
--------------
trunk/src/plugins.ext
Added Paths:
-----------
trunk/src/plugins/KedamaPlugin2/
trunk/src/plugins/KedamaPlugin2/KedamaPlugin2.c
Added: trunk/src/plugins/KedamaPlugin2/KedamaPlugin2.c
===================================================================
--- trunk/src/plugins/KedamaPlugin2/KedamaPlugin2.c (rev 0)
+++ trunk/src/plugins/KedamaPlugin2/KedamaPlugin2.c 2014-06-23 23:03:59 UTC (rev 3013)
@@ -0,0 +1,4563 @@
+/* Smalltalk from Squeak4.5 with VMMaker 4.13.5 translated as C source on 23 June 2014 6:57:27 pm */
+/* Automatically generated by
+ VMPluginCodeGenerator VMMaker-dtl.347 uuid: 0e985655-74a3-4561-8daf-4a4740c19a3b
+ from
+ KedamaPlugin2 Kedama-Plugins-yo.1 uuid: 3fc7d691-0149-ba4d-a339-5d27cd44a2f8
+ */
+static char __buildInfo[] = "KedamaPlugin2 Kedama-Plugins-yo.1 uuid: 3fc7d691-0149-ba4d-a339-5d27cd44a2f8 " __DATE__ ;
+
+
+
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/* Default EXPORT macro that does nothing (see comment in sq.h): */
+#define EXPORT(returnType) returnType
+
+/* Do not include the entire sq.h file but just those parts needed. */
+/* The virtual machine proxy definition */
+#include "sqVirtualMachine.h"
+/* Configuration options */
+#include "sqConfig.h"
+/* Platform specific definitions */
+#include "sqPlatformSpecific.h"
+
+#define true 1
+#define false 0
+#define null 0 /* using 'null' because nil is predefined in Think C */
+#ifdef SQUEAK_BUILTIN_PLUGIN
+#undef EXPORT
+// was #undef EXPORT(returnType) but screws NorCroft cc
+#define EXPORT(returnType) static returnType
+#endif
+
+#include "sqMemoryAccess.h"
+
+
+/*** Constants ***/
+
+/*** Function Prototypes ***/
+static double degreesFromXy(double x, double y);
+static double degreesToRadians(double degrees);
+#pragma export on
+EXPORT(sqInt) drawTurtlesInArray(void);
+EXPORT(sqInt) getHeadingArrayInto(void);
+EXPORT(const char*) getModuleName(void);
+EXPORT(sqInt) getScalarHeading(void);
+#pragma export off
+static sqInt halt(void);
+#pragma export on
+EXPORT(sqInt) initialiseModule(void);
+#pragma export off
+static sqInt kedamaRandom2(sqInt range);
+#pragma export on
+EXPORT(sqInt) kedamaSetRandomSeed(void);
+EXPORT(sqInt) makeMask(void);
+EXPORT(sqInt) makeMaskLog(void);
+EXPORT(sqInt) makeTurtlesMap(void);
+EXPORT(sqInt) primPixelAtXY(void);
+EXPORT(sqInt) primPixelAtXYPut(void);
+EXPORT(sqInt) primPixelsAtXY(void);
+EXPORT(sqInt) primScalarForward(void);
+EXPORT(sqInt) primSetPixelsAtXY(void);
+EXPORT(sqInt) primTurtlesForward(void);
+EXPORT(sqInt) primUpHill(void);
+EXPORT(sqInt) primitiveAddArrays(void);
+EXPORT(sqInt) primitiveAddScalar(void);
+EXPORT(sqInt) primitiveAndByteArray(void);
+EXPORT(sqInt) primitiveDivArrays(void);
+EXPORT(sqInt) primitiveDivScalar(void);
+EXPORT(sqInt) primitiveEQArrays(void);
+EXPORT(sqInt) primitiveEQScalar(void);
+EXPORT(sqInt) primitiveGEArrays(void);
+EXPORT(sqInt) primitiveGEScalar(void);
+EXPORT(sqInt) primitiveGTArrays(void);
+EXPORT(sqInt) primitiveGTScalar(void);
+EXPORT(sqInt) primitiveLEArrays(void);
+EXPORT(sqInt) primitiveLEScalar(void);
+EXPORT(sqInt) primitiveLTArrays(void);
+EXPORT(sqInt) primitiveLTScalar(void);
+EXPORT(sqInt) primitiveMulArrays(void);
+EXPORT(sqInt) primitiveMulScalar(void);
+EXPORT(sqInt) primitiveNEArrays(void);
+EXPORT(sqInt) primitiveNEScalar(void);
+EXPORT(sqInt) primitiveNotByteArray(void);
+EXPORT(sqInt) primitiveOrByteArray(void);
+EXPORT(sqInt) primitivePredicateAtAllPutBoolean(void);
+EXPORT(sqInt) primitivePredicateAtAllPutColor(void);
+EXPORT(sqInt) primitivePredicateAtAllPutNumber(void);
+EXPORT(sqInt) primitivePredicateAtAllPutObject(void);
+EXPORT(sqInt) primitivePredicateReplaceBytes(void);
+EXPORT(sqInt) primitivePredicateReplaceWords(void);
+EXPORT(sqInt) primitiveRemArrays(void);
+EXPORT(sqInt) primitiveRemScalar(void);
+EXPORT(sqInt) primitiveSubArrays(void);
+EXPORT(sqInt) primitiveSubScalar(void);
+EXPORT(sqInt) randomIntoFloatArray(void);
+EXPORT(sqInt) randomIntoIntegerArray(void);
+EXPORT(sqInt) randomRange(void);
+EXPORT(sqInt) scalarGetAngleTo(void);
+EXPORT(sqInt) scalarGetDistanceTo(void);
+EXPORT(sqInt) setHeadingArrayFrom(void);
+EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter);
+EXPORT(sqInt) setScalarHeading(void);
+EXPORT(sqInt) shutdownModule(void);
+EXPORT(sqInt) turtleScalarSetX(void);
+EXPORT(sqInt) turtleScalarSetY(void);
+EXPORT(sqInt) turtlesSetX(void);
+EXPORT(sqInt) turtlesSetY(void);
+EXPORT(sqInt) vectorGetAngleTo(void);
+EXPORT(sqInt) vectorGetDistanceTo(void);
+EXPORT(sqInt) zoomBitmap(void);
+#pragma export off
+/*** Variables ***/
+
+#ifdef SQUEAK_BUILTIN_PLUGIN
+extern
+#endif
+struct VirtualMachine* interpreterProxy;
+static unsigned int kedamaRandomSeed;
+static const char *moduleName =
+#ifdef SQUEAK_BUILTIN_PLUGIN
+ "KedamaPlugin2 23 June 2014 (i)"
+#else
+ "KedamaPlugin2 23 June 2014 (e)"
+#endif
+;
+static unsigned int randA;
+static unsigned int randM;
+static unsigned int randQ;
+static unsigned int randR;
+
+
+static double degreesFromXy(double x, double y) {
+ double tanVal;
+ double theta;
+
+ if (x == 0.0) {
+ if (y >= 0.0) {
+ return 90.0;
+ } else {
+ return 270.0;
+ }
+ } else {
+ tanVal = y / x;
+ theta = atan(tanVal);
+ if (x >= 0.0) {
+ if (y >= 0.0) {
+ return theta / 0.0174532925199433;
+ } else {
+ return 360.0 + (theta / 0.0174532925199433);
+ }
+ } else {
+ return 180.0 + (theta / 0.0174532925199433);
+ }
+ }
+ return 0.0;
+}
+
+static double degreesToRadians(double degrees) {
+ double deg;
+ double headingRadians;
+ int q;
+
+ deg = 90.0 - degrees;
+ q = deg / 360.0;
+ if (deg < 0.0) {
+ q -= 1;
+ }
+ headingRadians = (deg - (q * 360.0)) * 0.0174532925199433;
+ return headingRadians;
+}
+
+EXPORT(sqInt) drawTurtlesInArray(void) {
+ sqInt bitsIndex;
+ unsigned int *colorArray;
+ sqInt colorOop;
+ unsigned int *destBits;
+ sqInt destHeight;
+ sqInt destOop;
+ sqInt destWidth;
+ sqInt i;
+ sqInt size;
+ sqInt visible;
+ unsigned char *visibleArray;
+ sqInt visibleOop;
+ sqInt x;
+ float *xArray;
+ sqInt xOop;
+ sqInt y;
+ float *yArray;
+ sqInt yOop;
+
+ visibleOop = interpreterProxy->stackValue(0);
+ colorOop = interpreterProxy->stackValue(1);
+ yOop = interpreterProxy->stackValue(2);
+ xOop = interpreterProxy->stackValue(3);
+ destHeight = interpreterProxy->stackIntegerValue(4);
+ destWidth = interpreterProxy->stackIntegerValue(5);
+ destOop = interpreterProxy->stackValue(6);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(destOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(xOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(yOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(colorOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isBytes(visibleOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((destHeight * destWidth) != (interpreterProxy->slotSizeOf(destOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ size = interpreterProxy->slotSizeOf(xOop);
+ if ((interpreterProxy->slotSizeOf(yOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(colorOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(visibleOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ xArray = interpreterProxy->firstIndexableField(xOop);
+ yArray = interpreterProxy->firstIndexableField(yOop);
+ colorArray = interpreterProxy->firstIndexableField(colorOop);
+ visibleArray = interpreterProxy->firstIndexableField(visibleOop);
+ destBits = interpreterProxy->firstIndexableField(destOop);
+ for (i = 0; i <= (size - 1); i += 1) {
+ x = ((int) (xArray[i]));
+ ;
+ y = ((int) (yArray[i]));
+ ;
+ visible = visibleArray[i];
+ if ((visible != 0) && (((x >= 0) && (y >= 0)) && ((x < destWidth) && (y < destHeight)))) {
+ bitsIndex = (y * destWidth) + x;
+ destBits[bitsIndex] = (colorArray[i]);
+ }
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(7);
+}
+
+EXPORT(sqInt) getHeadingArrayInto(void) {
+ double heading;
+ float *headingArray;
+ sqInt headingOop;
+ sqInt i;
+ float *resultArray;
+ sqInt resultOop;
+ sqInt size;
+
+ resultOop = interpreterProxy->stackValue(0);
+ headingOop = interpreterProxy->stackValue(1);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(headingOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(resultOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ size = interpreterProxy->slotSizeOf(headingOop);
+ if ((interpreterProxy->slotSizeOf(resultOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ headingArray = interpreterProxy->firstIndexableField(headingOop);
+ resultArray = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (size - 1); i += 1) {
+ heading = headingArray[i];
+ heading = heading / 0.0174532925199433;
+ heading = 90.0 - heading;
+ if (!(heading > 0.0)) {
+ heading += 360.0;
+ }
+ resultArray[i] = heading;
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(2);
+}
+
+
+/* Note: This is hardcoded so it can be run from Squeak.
+ The module name is used for validating a module *after*
+ it is loaded to check if it does really contain the module
+ we're thinking it contains. This is important! */
+
+EXPORT(const char*) getModuleName(void) {
+ return moduleName;
+}
+
+EXPORT(sqInt) getScalarHeading(void) {
+ double heading;
+ float *headingArray;
+ sqInt headingOop;
+ sqInt index;
+ double deg;
+ double degrees;
+
+ headingOop = interpreterProxy->stackValue(0);
+ index = interpreterProxy->stackIntegerValue(1);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(headingOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(headingOop)) < index) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ headingArray = interpreterProxy->firstIndexableField(headingOop);
+ heading = headingArray[index - 1];
+ /* begin radiansToDegrees: */
+ degrees = heading / 0.0174532925199433;
+ deg = 90.0 - degrees;
+ if (!(deg > 0.0)) {
+ deg += 360.0;
+ }
+ heading = deg;
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(3);
+ interpreterProxy->pushFloat(heading);
+}
+
+static sqInt halt(void) {
+ ;
+}
+
+EXPORT(sqInt) initialiseModule(void) {
+ kedamaRandomSeed = 17;
+
+ /* magic constant = 16807 */
+
+ randA = 16807;
+
+ /* magic constant = 2147483647 */
+
+ randM = 2147483647U;
+ randQ = randM / randA;
+ randR = randM % randA;
+}
+
+static sqInt kedamaRandom2(sqInt range) {
+ sqInt hi;
+ sqInt lo;
+ sqInt r;
+ sqInt v;
+ sqInt val;
+
+ if (range < 0) {
+ r = 0 - range;
+ } else {
+ r = range;
+ }
+ hi = kedamaRandomSeed / randQ;
+ lo = kedamaRandomSeed % randQ;
+ kedamaRandomSeed = (randA * lo) - (randR * hi);
+ v = kedamaRandomSeed & 65535;
+ val = ((usqInt) (v * (r + 1))) >> 16;
+ if (range < 0) {
+ return 0 - val;
+ } else {
+ return val;
+ }
+}
+
+EXPORT(sqInt) kedamaSetRandomSeed(void) {
+ sqInt seed;
+
+ seed = interpreterProxy->stackIntegerValue(0);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ kedamaRandomSeed = seed & 65536;
+ interpreterProxy->pop(1);
+}
+
+EXPORT(sqInt) makeMask(void) {
+ unsigned int alpha;
+ unsigned int* dOrigin;
+ sqInt data;
+ sqInt dataBits;
+ sqInt dataSize;
+ unsigned int highMask;
+ sqInt i;
+ unsigned int* mOrigin;
+ sqInt maskBits;
+ sqInt maskSize;
+ unsigned int pixel;
+ sqInt shiftAmount;
+
+ shiftAmount = interpreterProxy->stackIntegerValue(0);
+ pixel = interpreterProxy->stackIntegerValue(1);
+ maskBits = interpreterProxy->stackValue(2);
+ dataBits = interpreterProxy->stackValue(3);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ dataSize = interpreterProxy->slotSizeOf(dataBits);
+ maskSize = interpreterProxy->slotSizeOf(maskBits);
+ if (!(dataSize == maskSize)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (shiftAmount < -32) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (shiftAmount > 8) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ dOrigin = interpreterProxy->firstIndexableField(dataBits);
+ mOrigin = interpreterProxy->firstIndexableField(maskBits);
+ highMask = 4278190080U;
+ for (i = 0; i <= (dataSize - 1); i += 1) {
+ data = dOrigin[i];
+ alpha = ((shiftAmount < 0) ? ((usqInt) data >> -shiftAmount) : ((usqInt) data << shiftAmount));
+ if (alpha > 255) {
+ alpha = 255;
+ }
+ if (alpha < 0) {
+ alpha = 0;
+ }
+ mOrigin[i] = (((alpha << 24) & highMask) | pixel);
+ }
+ interpreterProxy->pop(4);
+}
+
+EXPORT(sqInt) makeMaskLog(void) {
+ unsigned int alpha;
+ unsigned int* dOrigin;
+ sqInt data;
+ sqInt dataBits;
+ sqInt dataSize;
+ unsigned int highMask;
+ sqInt i;
+ unsigned int* mOrigin;
+ sqInt maskBits;
+ sqInt maskSize;
+ unsigned int max;
+ unsigned int* maxFirst;
+ double maxLog;
+ sqInt maxOop;
+ unsigned int pixel;
+
+ maxOop = interpreterProxy->stackValue(0);
+ pixel = interpreterProxy->stackIntegerValue(1);
+ maskBits = interpreterProxy->stackValue(2);
+ dataBits = interpreterProxy->stackValue(3);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ maxFirst = interpreterProxy->firstIndexableField(maxOop);
+ max = maxFirst[0];
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ maxLog = log(max);
+ dataSize = interpreterProxy->slotSizeOf(dataBits);
+ maskSize = interpreterProxy->slotSizeOf(maskBits);
+ if (!(dataSize == maskSize)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ dOrigin = interpreterProxy->firstIndexableField(dataBits);
+ mOrigin = interpreterProxy->firstIndexableField(maskBits);
+ highMask = 4278190080U;
+ for (i = 0; i <= (dataSize - 1); i += 1) {
+ data = dOrigin[i];
+ if (data == 0) {
+ alpha = 0;
+ } else {
+ alpha = ((sqInt)((255.0 / maxLog) * (log(data))));
+ }
+ if (alpha > 255) {
+ alpha = 255;
+ }
+ mOrigin[i] = (((alpha << 24) & highMask) | pixel);
+ }
+ interpreterProxy->pop(4);
+}
+
+EXPORT(sqInt) makeTurtlesMap(void) {
+ sqInt height;
+ sqInt index;
+ unsigned int *map;
+ sqInt mapIndex;
+ sqInt mapOop;
+ sqInt size;
+ unsigned int *whoArray;
+ sqInt whoOop;
+ sqInt width;
+ sqInt x;
+ float *xArray;
+ sqInt xOop;
+ sqInt y;
+ float *yArray;
+ sqInt yOop;
+
+ height = interpreterProxy->stackIntegerValue(0);
+ width = interpreterProxy->stackIntegerValue(1);
+ yOop = interpreterProxy->stackValue(2);
+ xOop = interpreterProxy->stackValue(3);
+ whoOop = interpreterProxy->stackValue(4);
+ mapOop = interpreterProxy->stackValue(5);
+ if (!(interpreterProxy->isWords(yOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(xOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(whoOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(mapOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ size = interpreterProxy->slotSizeOf(whoOop);
+ if ((interpreterProxy->slotSizeOf(xOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(yOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(mapOop)) != (height * width)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ xArray = interpreterProxy->firstIndexableField(xOop);
+ yArray = interpreterProxy->firstIndexableField(yOop);
+ whoArray = interpreterProxy->firstIndexableField(whoOop);
+ map = interpreterProxy->firstIndexableField(mapOop);
+ for (index = 0; index <= ((height * width) - 1); index += 1) {
+ map[index] = 0;
+ }
+ for (index = 0; index <= (size - 1); index += 1) {
+ x = xArray[index];
+ y = yArray[index];
+ mapIndex = (width * y) + x;
+ if ((mapIndex >= 0) && (mapIndex < (height * width))) {
+ map[mapIndex] = (whoArray[index]);
+ }
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(6);
+}
+
+EXPORT(sqInt) primPixelAtXY(void) {
+ unsigned int *bits;
+ sqInt bitsOop;
+ sqInt height;
+ sqInt index;
+ sqInt ret;
+ sqInt width;
+ sqInt x;
+ double xPos;
+ sqInt y;
+ double yPos;
+
+ height = interpreterProxy->stackIntegerValue(0);
+ width = interpreterProxy->stackIntegerValue(1);
+ yPos = interpreterProxy->stackFloatValue(2);
+ xPos = interpreterProxy->stackFloatValue(3);
+ bitsOop = interpreterProxy->stackValue(4);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(bitsOop)) != (height * width)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ x = xPos;
+ y = yPos;
+ bits = interpreterProxy->firstIndexableField(bitsOop);
+ if ((((x >= 0) && (x < width)) && (y >= 0)) && (y < height)) {
+ index = (y * width) + x;
+ ret = bits[index];
+ } else {
+ ret = 0;
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(6);
+ interpreterProxy->pushInteger(ret);
+}
+
+EXPORT(sqInt) primPixelAtXYPut(void) {
+ unsigned int *bits;
+ sqInt bitsOop;
+ sqInt height;
+ sqInt index;
+ sqInt v;
+ sqInt value;
+ sqInt width;
+ sqInt x;
+ double xPos;
+ sqInt y;
+ double yPos;
+
+ height = interpreterProxy->stackIntegerValue(0);
+ width = interpreterProxy->stackIntegerValue(1);
+ value = interpreterProxy->stackIntegerValue(2);
+ yPos = interpreterProxy->stackFloatValue(3);
+ xPos = interpreterProxy->stackFloatValue(4);
+ bitsOop = interpreterProxy->stackValue(5);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(bitsOop)) != (height * width)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ x = xPos;
+ y = yPos;
+ v = value;
+ if (v > 1073741823) {
+ v = 1073741823;
+ }
+ if (v < 0) {
+ v = 0;
+ }
+ bits = interpreterProxy->firstIndexableField(bitsOop);
+ if ((((x >= 0) && (x < width)) && (y >= 0)) && (y < height)) {
+ index = (y * width) + x;
+ bits[index] = v;
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(6);
+}
+
+EXPORT(sqInt) primPixelsAtXY(void) {
+ unsigned int *bits;
+ sqInt bitsHeight;
+ sqInt bitsIndex;
+ sqInt bitsOop;
+ sqInt bitsWidth;
+ unsigned int *destWords;
+ sqInt destWordsOop;
+ sqInt i;
+ sqInt size;
+ sqInt x;
+ float *xArray;
+ sqInt xArrayOop;
+ sqInt y;
+ float *yArray;
+ sqInt yArrayOop;
+
+ destWordsOop = interpreterProxy->stackValue(0);
+ bitsHeight = interpreterProxy->stackIntegerValue(1);
+ bitsWidth = interpreterProxy->stackIntegerValue(2);
+ bitsOop = interpreterProxy->stackValue(3);
+ yArrayOop = interpreterProxy->stackValue(4);
+ xArrayOop = interpreterProxy->stackValue(5);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(destWordsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(xArrayOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(yArrayOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((bitsHeight * bitsWidth) != (interpreterProxy->slotSizeOf(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ size = interpreterProxy->slotSizeOf(xArrayOop);
+ if ((interpreterProxy->slotSizeOf(yArrayOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(destWordsOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ xArray = interpreterProxy->firstIndexableField(xArrayOop);
+ yArray = interpreterProxy->firstIndexableField(yArrayOop);
+ destWords = interpreterProxy->firstIndexableField(destWordsOop);
+ bits = interpreterProxy->firstIndexableField(bitsOop);
+ for (i = 0; i <= (size - 1); i += 1) {
+ x = ((int) (xArray[i]));
+ ;
+ y = ((int) (yArray[i]));
+ ;
+ if (((x >= 0) && (y >= 0)) && ((x < bitsWidth) && (y < bitsHeight))) {
+ bitsIndex = (y * bitsWidth) + x;
+ destWords[i] = (bits[bitsIndex]);
+ }
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(6);
+}
+
+EXPORT(sqInt) primScalarForward(void) {
+ sqInt bottomEdgeMode;
+ double destHeight;
+ double destWidth;
+ double dist;
+ float *headingArray;
+ sqInt headingOop;
+ sqInt i;
+ sqInt index;
+ sqInt leftEdgeMode;
+ double newX;
+ double newY;
+ sqInt rightEdgeMode;
+ sqInt size;
+ sqInt topEdgeMode;
+ double val;
+ float *xArray;
+ sqInt xOop;
+ float *yArray;
+ sqInt yOop;
+ double headingRadians;
+ double newX1;
+ double newY1;
+
+ bottomEdgeMode = interpreterProxy->stackIntegerValue(0);
+ topEdgeMode = interpreterProxy->stackIntegerValue(1);
+ rightEdgeMode = interpreterProxy->stackIntegerValue(2);
+ leftEdgeMode = interpreterProxy->stackIntegerValue(3);
+ destHeight = interpreterProxy->stackFloatValue(4);
+ destWidth = interpreterProxy->stackFloatValue(5);
+ val = interpreterProxy->stackFloatValue(6);
+ headingOop = interpreterProxy->stackValue(7);
+ yOop = interpreterProxy->stackValue(8);
+ xOop = interpreterProxy->stackValue(9);
+ index = interpreterProxy->stackIntegerValue(10);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(xOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(yOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(headingOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ size = interpreterProxy->slotSizeOf(xOop);
+ if ((interpreterProxy->slotSizeOf(yOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(headingOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ xArray = interpreterProxy->firstIndexableField(xOop);
+ yArray = interpreterProxy->firstIndexableField(yOop);
+ headingArray = interpreterProxy->firstIndexableField(headingOop);
+ dist = val;
+ i = index - 1;
+ newX = (xArray[i]) + (dist * (cos(headingArray[i])));
+ newY = (yArray[i]) - (dist * (sin(headingArray[i])));
+ /* begin scalarXAt:xArray:headingArray:value:destWidth:leftEdgeMode:rightEdgeMode: */
+ newX1 = newX;
+ if (newX1 < 0.0) {
+ if (leftEdgeMode == 1) {
+ newX1 += destWidth;
+ }
+ if (leftEdgeMode == 2) {
+ newX1 = 0.0;
+ }
+ if (leftEdgeMode == 3) {
+ newX1 = 0.0 - newX1;
+ headingRadians = headingArray[i];
+ if (headingRadians < 3.141592653589793) {
+ headingArray[i] = (3.141592653589793 - headingRadians);
+ } else {
+ headingArray[i] = (9.42477796076938 - headingRadians);
+ }
+ }
+ }
+ if (newX1 >= destWidth) {
+ if (rightEdgeMode == 1) {
+ newX1 -= destWidth;
+ }
+ if (rightEdgeMode == 2) {
+ newX1 = destWidth - 1.0e-6;
+ }
+ if (rightEdgeMode == 3) {
+ newX1 = (destWidth - 1.0e-6) - (newX1 - destWidth);
+ headingRadians = headingArray[i];
+ if (headingRadians < 3.141592653589793) {
+ headingArray[i] = (3.141592653589793 - headingRadians);
+ } else {
+ headingArray[i] = (9.42477796076938 - headingRadians);
+ }
+ }
+ }
+ xArray[i] = newX1;
+ /* begin scalarYAt:yArray:headingArray:value:destHeight:topEdgeMode:bottomEdgeMode: */
+ newY1 = newY;
+ if (newY1 < 0.0) {
+ if (topEdgeMode == 1) {
+ newY1 += destHeight;
+ }
+ if (topEdgeMode == 2) {
+ newY1 = 0.0;
+ }
+ if (topEdgeMode == 3) {
+ newY1 = 0.0 - newY1;
+ headingArray[i] = (6.283185307179586 - (headingArray[i]));
+ }
+ }
+ if (newY1 >= destHeight) {
+ if (bottomEdgeMode == 1) {
+ newY1 -= destHeight;
+ }
+ if (bottomEdgeMode == 2) {
+ newY1 = destHeight - 1.0e-6;
+ }
+ if (bottomEdgeMode == 3) {
+ newY1 = (destHeight - 1.0e-6) - (newY1 - destHeight);
+ headingArray[i] = (6.283185307179586 - (headingArray[i]));
+ }
+ }
+ yArray[i] = newY1;
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(11);
+}
+
+EXPORT(sqInt) primSetPixelsAtXY(void) {
+ unsigned int *bits;
+ sqInt bitsHeight;
+ sqInt bitsIndex;
+ sqInt bitsOop;
+ sqInt bitsWidth;
+ float *floatsValue;
+ sqInt fv;
+ sqInt i;
+ unsigned int intValue;
+ sqInt isValueInt;
+ sqInt isValueWordArray;
+ unsigned char *pArray;
+ sqInt pArrayOop;
+ sqInt size;
+ unsigned int value;
+ sqInt valueOop;
+ unsigned int *wordsValue;
+ sqInt x;
+ float *xArray;
+ sqInt xArrayOop;
+ sqInt y;
+ float *yArray;
+ sqInt yArrayOop;
+
+ valueOop = interpreterProxy->stackValue(0);
+ bitsHeight = interpreterProxy->stackIntegerValue(1);
+ bitsWidth = interpreterProxy->stackIntegerValue(2);
+ bitsOop = interpreterProxy->stackValue(3);
+ yArrayOop = interpreterProxy->stackValue(4);
+ xArrayOop = interpreterProxy->stackValue(5);
+ pArrayOop = interpreterProxy->stackValue(6);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isBytes(pArrayOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(xArrayOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(yArrayOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((bitsHeight * bitsWidth) != (interpreterProxy->slotSizeOf(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ size = interpreterProxy->slotSizeOf(xArrayOop);
+ if ((interpreterProxy->slotSizeOf(pArrayOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(yArrayOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ pArray = interpreterProxy->firstIndexableField(pArrayOop);
+ xArray = interpreterProxy->firstIndexableField(xArrayOop);
+ yArray = interpreterProxy->firstIndexableField(yArrayOop);
+ isValueInt = (valueOop & 1);
+ if (isValueInt) {
+ intValue = (valueOop >> 1);
+ value = intValue;
+ } else {
+ if ((interpreterProxy->slotSizeOf(valueOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ isValueWordArray = interpreterProxy->isMemberOf(valueOop, "WordArray");
+ if (isValueWordArray) {
+ wordsValue = interpreterProxy->firstIndexableField(valueOop);
+ } else {
+ floatsValue = interpreterProxy->firstIndexableField(valueOop);
+ }
+ }
+ bits = interpreterProxy->firstIndexableField(bitsOop);
+ for (i = 0; i <= (size - 1); i += 1) {
+ if ((pArray[i]) == 1) {
+ x = ((int) (xArray[i]));
+ ;
+ y = ((int) (yArray[i]));
+ ;
+ if (((x >= 0) && (y >= 0)) && ((x < bitsWidth) && (y < bitsHeight))) {
+ bitsIndex = (y * bitsWidth) + x;
+ if (isValueInt) {
+ bits[bitsIndex] = value;
+ } else {
+ if (isValueWordArray) {
+ bits[bitsIndex] = (wordsValue[i]);
+ } else {
+ fv = floatsValue[i];
+ ;
+ bits[bitsIndex] = fv;
+ }
+ }
+ }
+ }
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(7);
+}
+
+EXPORT(sqInt) primTurtlesForward(void) {
+ sqInt bottomEdgeMode;
+ double destHeight;
+ double destWidth;
+ double dist;
+ float *headingArray;
+ sqInt headingOop;
+ sqInt i;
+ sqInt isValVector;
+ sqInt leftEdgeMode;
+ double newX;
+ double newY;
+ unsigned char *pArray;
+ sqInt pOop;
+ sqInt rightEdgeMode;
+ sqInt size;
+ sqInt topEdgeMode;
+ double val;
+ float *valArray;
+ sqInt valOop;
+ float *xArray;
+ sqInt xOop;
+ float *yArray;
+ sqInt yOop;
+ double headingRadians;
+ double newX1;
+ double newY1;
+
+ bottomEdgeMode = interpreterProxy->stackIntegerValue(0);
+ topEdgeMode = interpreterProxy->stackIntegerValue(1);
+ rightEdgeMode = interpreterProxy->stackIntegerValue(2);
+ leftEdgeMode = interpreterProxy->stackIntegerValue(3);
+ destHeight = interpreterProxy->stackFloatValue(4);
+ destWidth = interpreterProxy->stackFloatValue(5);
+ valOop = interpreterProxy->stackValue(6);
+ headingOop = interpreterProxy->stackValue(7);
+ yOop = interpreterProxy->stackValue(8);
+ xOop = interpreterProxy->stackValue(9);
+ pOop = interpreterProxy->stackValue(10);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isBytes(pOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(xOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(yOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (!(interpreterProxy->isWords(headingOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (interpreterProxy->isFloatObject(valOop)) {
+ isValVector = 0;
+ } else {
+ if (interpreterProxy->isWords(valOop)) {
+ isValVector = 1;
+ } else {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ size = interpreterProxy->slotSizeOf(xOop);
+ if ((interpreterProxy->slotSizeOf(yOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(headingOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(pOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if (isValVector) {
+ if ((interpreterProxy->slotSizeOf(valOop)) != size) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ pArray = interpreterProxy->firstIndexableField(pOop);
+ xArray = interpreterProxy->firstIndexableField(xOop);
+ yArray = interpreterProxy->firstIndexableField(yOop);
+ headingArray = interpreterProxy->firstIndexableField(headingOop);
+ if (isValVector) {
+ valArray = interpreterProxy->firstIndexableField(valOop);
+ } else {
+ val = interpreterProxy->floatValueOf(valOop);
+ }
+ for (i = 0; i <= (size - 1); i += 1) {
+ if ((pArray[i]) == 1) {
+ if (isValVector) {
+ dist = valArray[i];
+ } else {
+ dist = val;
+ }
+ newX = (xArray[i]) + (dist * (cos(headingArray[i])));
+ newY = (yArray[i]) - (dist * (sin(headingArray[i])));
+ /* begin scalarXAt:xArray:headingArray:value:destWidth:leftEdgeMode:rightEdgeMode: */
+ newX1 = newX;
+ if (newX1 < 0.0) {
+ if (leftEdgeMode == 1) {
+ newX1 += destWidth;
+ }
+ if (leftEdgeMode == 2) {
+ newX1 = 0.0;
+ }
+ if (leftEdgeMode == 3) {
+ newX1 = 0.0 - newX1;
+ headingRadians = headingArray[i];
+ if (headingRadians < 3.141592653589793) {
+ headingArray[i] = (3.141592653589793 - headingRadians);
+ } else {
+ headingArray[i] = (9.42477796076938 - headingRadians);
+ }
+ }
+ }
+ if (newX1 >= destWidth) {
+ if (rightEdgeMode == 1) {
+ newX1 -= destWidth;
+ }
+ if (rightEdgeMode == 2) {
+ newX1 = destWidth - 1.0e-6;
+ }
+ if (rightEdgeMode == 3) {
+ newX1 = (destWidth - 1.0e-6) - (newX1 - destWidth);
+ headingRadians = headingArray[i];
+ if (headingRadians < 3.141592653589793) {
+ headingArray[i] = (3.141592653589793 - headingRadians);
+ } else {
+ headingArray[i] = (9.42477796076938 - headingRadians);
+ }
+ }
+ }
+ xArray[i] = newX1;
+ /* begin scalarYAt:yArray:headingArray:value:destHeight:topEdgeMode:bottomEdgeMode: */
+ newY1 = newY;
+ if (newY1 < 0.0) {
+ if (topEdgeMode == 1) {
+ newY1 += destHeight;
+ }
+ if (topEdgeMode == 2) {
+ newY1 = 0.0;
+ }
+ if (topEdgeMode == 3) {
+ newY1 = 0.0 - newY1;
+ headingArray[i] = (6.283185307179586 - (headingArray[i]));
+ }
+ }
+ if (newY1 >= destHeight) {
+ if (bottomEdgeMode == 1) {
+ newY1 -= destHeight;
+ }
+ if (bottomEdgeMode == 2) {
+ newY1 = destHeight - 1.0e-6;
+ }
+ if (bottomEdgeMode == 3) {
+ newY1 = (destHeight - 1.0e-6) - (newY1 - destHeight);
+ headingArray[i] = (6.283185307179586 - (headingArray[i]));
+ }
+ }
+ yArray[i] = newY1;
+ }
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(11);
+}
+
+EXPORT(sqInt) primUpHill(void) {
+ unsigned int *bits;
+ sqInt bitsOop;
+ sqInt endX;
+ sqInt endY;
+ sqInt height;
+ sqInt maxVal;
+ sqInt maxValX;
+ sqInt maxValY;
+ double ret;
+ sqInt rowOffset;
+ sqInt sniffRange;
+ sqInt startX;
+ sqInt startY;
+ double tH;
+ double tX;
+ double tY;
+ sqInt thisVal;
+ sqInt turtleX;
+ sqInt turtleY;
+ sqInt width;
+ sqInt x;
+ sqInt y;
+ double deg;
+ double degrees;
+
+ sniffRange = interpreterProxy->stackIntegerValue(0);
+ height = interpreterProxy->stackIntegerValue(1);
+ width = interpreterProxy->stackIntegerValue(2);
+ bitsOop = interpreterProxy->stackValue(3);
+ tH = interpreterProxy->stackFloatValue(4);
+ tY = interpreterProxy->stackFloatValue(5);
+ tX = interpreterProxy->stackFloatValue(6);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ if (!(interpreterProxy->isWords(bitsOop))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ if ((interpreterProxy->slotSizeOf(bitsOop)) != (height * width)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ bits = interpreterProxy->firstIndexableField(bitsOop);
+ turtleX = tX;
+ turtleY = tY;
+ turtleX = ((turtleX < 0) ? 0 : turtleX);
+ turtleY = ((turtleY < 0) ? 0 : turtleY);
+ turtleX = ((turtleX < (width - 1)) ? turtleX : (width - 1));
+ turtleY = ((turtleY < (height - 1)) ? turtleY : (height - 1));
+ startX = (((turtleX - sniffRange) < 0) ? 0 : (turtleX - sniffRange));
+ endX = (((turtleX + sniffRange) < (width - 1)) ? (turtleX + sniffRange) : (width - 1));
+ startY = (((turtleY - sniffRange) < 0) ? 0 : (turtleY - sniffRange));
+ endY = (((turtleY + sniffRange) < (height - 1)) ? (turtleY + sniffRange) : (height - 1));
+ maxVal = bits[(turtleY * width) + turtleX];
+ maxValX = -1;
+ for (y = startY; y <= endY; y += 1) {
+ rowOffset = y * width;
+ for (x = startX; x <= endX; x += 1) {
+ thisVal = bits[rowOffset + x];
+ if (thisVal > maxVal) {
+ maxValX = x;
+ maxValY = y;
+ maxVal = thisVal;
+ }
+ }
+ }
+ if (-1 == maxValX) {
+ /* begin radiansToDegrees: */
+ degrees = tH / 0.0174532925199433;
+ deg = 90.0 - degrees;
+ if (!(deg > 0.0)) {
+ deg += 360.0;
+ }
+ ret = deg;
+ } else {
+ ret = (degreesFromXy(((double) (maxValX - turtleX)), ((double) (maxValY - turtleY)))) + 90.0;
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(8);
+ interpreterProxy->pushFloat(ret);
+}
+
+EXPORT(sqInt) primitiveAddArrays(void) {
+ sqInt argOop;
+ float *floatsArg;
+ float *floatsRcvr;
+ float *floatsResult;
+ sqInt i;
+ sqInt isArgWords;
+ sqInt isRcvrWords;
+ sqInt length;
+ sqInt rcvrOop;
+ sqInt resultOop;
+ unsigned int *wordsArg;
+ unsigned int *wordsRcvr;
+ unsigned int *wordsResult;
+
+ resultOop = interpreterProxy->stackObjectValue(0);
+ argOop = interpreterProxy->stackObjectValue(1);
+ rcvrOop = interpreterProxy->stackObjectValue(2);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isWords(argOop));
+ interpreterProxy->success(interpreterProxy->isWords(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isWords(resultOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = interpreterProxy->stSizeOf(argOop);
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(rcvrOop)));
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(resultOop)));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ isArgWords = interpreterProxy->isMemberOf(argOop, "WordArray");
+ isRcvrWords = interpreterProxy->isMemberOf(rcvrOop, "WordArray");
+ if (isArgWords && isRcvrWords) {
+ if (!(interpreterProxy->isMemberOf(resultOop, "WordArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ } else {
+ if (!(interpreterProxy->isMemberOf(resultOop, "KedamaFloatArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ if (isRcvrWords) {
+ if (isArgWords) {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ wordsArg = interpreterProxy->firstIndexableField(argOop);
+ wordsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ wordsResult[i] = ((wordsRcvr[i]) + (wordsArg[i]));
+ }
+ } else {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatsArg = interpreterProxy->firstIndexableField(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((wordsRcvr[i]) + (floatsArg[i]));
+ }
+ }
+ } else {
+ if (isArgWords) {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ wordsArg = interpreterProxy->firstIndexableField(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) + (wordsArg[i]));
+ }
+ } else {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatsArg = interpreterProxy->firstIndexableField(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) + (floatsArg[i]));
+ }
+ }
+ }
+ interpreterProxy->pop(4);
+ interpreterProxy->push(resultOop);
+}
+
+EXPORT(sqInt) primitiveAddScalar(void) {
+ sqInt argOop;
+ double floatArg;
+ float *floatsRcvr;
+ float *floatsResult;
+ sqInt i;
+ int intArg;
+ sqInt isArgInt;
+ sqInt isRcvrWords;
+ sqInt length;
+ sqInt rcvrOop;
+ sqInt resultOop;
+ unsigned int *wordsRcvr;
+ unsigned int *wordsResult;
+
+ resultOop = interpreterProxy->stackObjectValue(0);
+ argOop = interpreterProxy->stackValue(1);
+ rcvrOop = interpreterProxy->stackObjectValue(2);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isWords(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isWords(resultOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = interpreterProxy->stSizeOf(rcvrOop);
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(resultOop)));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ isArgInt = (argOop & 1);
+ isRcvrWords = interpreterProxy->isMemberOf(rcvrOop, "WordArray");
+ if (isArgInt && isRcvrWords) {
+ if (!(interpreterProxy->isMemberOf(resultOop, "WordArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ } else {
+ if (!(interpreterProxy->isMemberOf(resultOop, "KedamaFloatArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ if (isRcvrWords) {
+ if (isArgInt) {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ intArg = (argOop >> 1);
+ wordsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ wordsResult[i] = ((wordsRcvr[i]) + intArg);
+ }
+ } else {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatArg = interpreterProxy->floatValueOf(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((wordsRcvr[i]) + floatArg);
+ }
+ }
+ } else {
+ if (isArgInt) {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ intArg = (argOop >> 1);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) + intArg);
+ }
+ } else {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatArg = interpreterProxy->floatValueOf(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) + floatArg);
+ }
+ }
+ }
+ interpreterProxy->pop(4);
+ interpreterProxy->push(resultOop);
+}
+
+EXPORT(sqInt) primitiveAndByteArray(void) {
+ sqInt i;
+ sqInt length;
+ sqInt length1;
+ sqInt length2;
+ unsigned char *otherArray;
+ sqInt otherOop;
+ unsigned char *rcvrArray;
+ sqInt rcvrOop;
+
+ otherOop = interpreterProxy->stackObjectValue(0);
+ rcvrOop = interpreterProxy->stackValue(1);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isBytes(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isBytes(otherOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length1 = interpreterProxy->stSizeOf(rcvrOop);
+ length2 = interpreterProxy->stSizeOf(otherOop);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = length1;
+ if (length1 > length2) {
+ length = length2;
+ }
+ otherArray = interpreterProxy->firstIndexableField(otherOop);
+ rcvrArray = interpreterProxy->firstIndexableField(rcvrOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ rcvrArray[i] = (((rcvrArray[i]) + (otherArray[i])) == 2);
+ }
+ interpreterProxy->pop(1);
+}
+
+EXPORT(sqInt) primitiveDivArrays(void) {
+ sqInt argOop;
+ float *floatsArg;
+ float *floatsRcvr;
+ float *floatsResult;
+ sqInt i;
+ sqInt isArgWords;
+ sqInt isRcvrWords;
+ sqInt length;
+ sqInt rcvrOop;
+ sqInt resultOop;
+ unsigned int *wordsArg;
+ unsigned int *wordsRcvr;
+ unsigned int *wordsResult;
+
+ resultOop = interpreterProxy->stackObjectValue(0);
+ argOop = interpreterProxy->stackObjectValue(1);
+ rcvrOop = interpreterProxy->stackObjectValue(2);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isWords(argOop));
+ interpreterProxy->success(interpreterProxy->isWords(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isWords(resultOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = interpreterProxy->stSizeOf(argOop);
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(rcvrOop)));
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(resultOop)));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ isArgWords = interpreterProxy->isMemberOf(argOop, "WordArray");
+ isRcvrWords = interpreterProxy->isMemberOf(rcvrOop, "WordArray");
+ if (isArgWords && isRcvrWords) {
+ if (!(interpreterProxy->isMemberOf(resultOop, "WordArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ } else {
+ if (!(interpreterProxy->isMemberOf(resultOop, "KedamaFloatArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ if (isRcvrWords) {
+ if (isArgWords) {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ wordsArg = interpreterProxy->firstIndexableField(argOop);
+ wordsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ wordsResult[i] = ((wordsRcvr[i]) / (wordsArg[i]));
+ }
+ } else {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatsArg = interpreterProxy->firstIndexableField(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((wordsRcvr[i]) / (floatsArg[i]));
+ }
+ }
+ } else {
+ if (isArgWords) {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ wordsArg = interpreterProxy->firstIndexableField(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) / (wordsArg[i]));
+ }
+ } else {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatsArg = interpreterProxy->firstIndexableField(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) / (floatsArg[i]));
+ }
+ }
+ }
+ interpreterProxy->pop(4);
+ interpreterProxy->push(resultOop);
+}
+
+EXPORT(sqInt) primitiveDivScalar(void) {
+ sqInt argOop;
+ double floatArg;
+ float *floatsRcvr;
+ float *floatsResult;
+ sqInt i;
+ int intArg;
+ sqInt isArgInt;
+ sqInt isRcvrWords;
+ sqInt length;
+ sqInt rcvrOop;
+ sqInt resultOop;
+ unsigned int *wordsRcvr;
+ unsigned int *wordsResult;
+
+ resultOop = interpreterProxy->stackObjectValue(0);
+ argOop = interpreterProxy->stackValue(1);
+ rcvrOop = interpreterProxy->stackObjectValue(2);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isWords(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isWords(resultOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = interpreterProxy->stSizeOf(rcvrOop);
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(resultOop)));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ isArgInt = (argOop & 1);
+ isRcvrWords = interpreterProxy->isMemberOf(rcvrOop, "WordArray");
+ if (isArgInt && isRcvrWords) {
+ if (!(interpreterProxy->isMemberOf(resultOop, "WordArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ } else {
+ if (!(interpreterProxy->isMemberOf(resultOop, "KedamaFloatArray"))) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ if (isRcvrWords) {
+ if (isArgInt) {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ intArg = (argOop >> 1);
+ wordsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ wordsResult[i] = ((wordsRcvr[i]) / intArg);
+ }
+ } else {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatArg = interpreterProxy->floatValueOf(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((wordsRcvr[i]) / floatArg);
+ }
+ }
+ } else {
+ if (isArgInt) {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ intArg = (argOop >> 1);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) / intArg);
+ }
+ } else {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatArg = interpreterProxy->floatValueOf(argOop);
+ floatsResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ floatsResult[i] = ((floatsRcvr[i]) / floatArg);
+ }
+ }
+ }
+ interpreterProxy->pop(4);
+ interpreterProxy->push(resultOop);
+}
+
+EXPORT(sqInt) primitiveEQArrays(void) {
+ sqInt argOop;
+ unsigned char *bytesResult;
+ float *floatsArg;
+ float *floatsRcvr;
+ sqInt i;
+ sqInt isArgWords;
+ sqInt isRcvrWords;
+ sqInt length;
+ sqInt rcvrOop;
+ sqInt resultOop;
+ unsigned int *wordsArg;
+ unsigned int *wordsRcvr;
+
+ resultOop = interpreterProxy->stackObjectValue(0);
+ argOop = interpreterProxy->stackObjectValue(1);
+ rcvrOop = interpreterProxy->stackObjectValue(2);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isWords(argOop));
+ interpreterProxy->success(interpreterProxy->isWords(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isBytes(resultOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = interpreterProxy->stSizeOf(argOop);
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(rcvrOop)));
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(resultOop)));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ isArgWords = interpreterProxy->isMemberOf(argOop, "WordArray");
+ isRcvrWords = interpreterProxy->isMemberOf(rcvrOop, "WordArray");
+ if (isRcvrWords) {
+ if (isArgWords) {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ wordsArg = interpreterProxy->firstIndexableField(argOop);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ bytesResult[i] = ((wordsRcvr[i]) == (wordsArg[i]));
+ }
+ } else {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatsArg = interpreterProxy->firstIndexableField(argOop);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ bytesResult[i] = ((wordsRcvr[i]) == (floatsArg[i]));
+ }
+ }
+ } else {
+ if (isArgWords) {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ wordsArg = interpreterProxy->firstIndexableField(argOop);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ bytesResult[i] = ((floatsRcvr[i]) == (wordsArg[i]));
+ }
+ } else {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatsArg = interpreterProxy->firstIndexableField(argOop);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ bytesResult[i] = ((floatsRcvr[i]) == (floatsArg[i]));
+ }
+ }
+ }
+ interpreterProxy->pop(4);
+ interpreterProxy->push(resultOop);
+}
+
+EXPORT(sqInt) primitiveEQScalar(void) {
+ sqInt argOop;
+ unsigned char *bytesResult;
+ double floatArg;
+ float *floatsRcvr;
+ sqInt i;
+ int intArg;
+ sqInt isArgInt;
+ sqInt isRcvrWords;
+ sqInt length;
+ sqInt rcvrOop;
+ sqInt resultOop;
+ unsigned int *wordsRcvr;
+
+ resultOop = interpreterProxy->stackObjectValue(0);
+ argOop = interpreterProxy->stackValue(1);
+ rcvrOop = interpreterProxy->stackObjectValue(2);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->success(interpreterProxy->isWords(rcvrOop));
+ interpreterProxy->success(interpreterProxy->isBytes(resultOop));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ length = interpreterProxy->stSizeOf(rcvrOop);
+ interpreterProxy->success(length == (interpreterProxy->stSizeOf(resultOop)));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ isArgInt = (argOop & 1);
+ isRcvrWords = interpreterProxy->isMemberOf(rcvrOop, "WordArray");
+ if (isRcvrWords) {
+ if (isArgInt) {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ intArg = (argOop >> 1);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ bytesResult[i] = ((wordsRcvr[i]) == intArg);
+ }
+ } else {
+ wordsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ floatArg = interpreterProxy->floatValueOf(argOop);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
+ for (i = 0; i <= (length - 1); i += 1) {
+ bytesResult[i] = ((wordsRcvr[i]) == floatArg);
+ }
+ }
+ } else {
+ if (isArgInt) {
+ floatsRcvr = interpreterProxy->firstIndexableField(rcvrOop);
+ intArg = (argOop >> 1);
+ bytesResult = interpreterProxy->firstIndexableField(resultOop);
@@ Diff output truncated at 50000 characters. @@
More information about the Vm-dev
mailing list