Spaces:
Running
Running
File size: 11,687 Bytes
8f3f8db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
/* Smalltalk from Squeak4.5 with VMMaker 4.13.6 translated as JS source on 14 November 2014 12:21:50 am */
/* Automatically generated by
JSSmartSyntaxPluginCodeGenerator VMMakerJS-bf.17 uuid: 399be48b-95d8-4722-bdcc-39a94a12c486
from
GeniePlugin VMMaker-bf.353 uuid: 8ae25e7e-8d2c-451e-8277-598b30e9c002
*/
(function GeniePlugin() {
"use strict";
var VM_PROXY_MAJOR = 1;
var VM_PROXY_MINOR = 11;
/*** Functions ***/
function CLASSOF(obj) { return typeof obj === "number" ? interpreterProxy.classSmallInteger() : obj.sqClass }
function SIZEOF(obj) { return obj.pointers ? obj.pointers.length : obj.words ? obj.words.length : obj.bytes ? obj.bytes.length : 0 }
function BYTESIZEOF(obj) { return obj.bytes ? obj.bytes.length : obj.words ? obj.words.length * 4 : 0 }
function DIV(a, b) { return Math.floor(a / b) | 0; } // integer division
function MOD(a, b) { return a - DIV(a, b) * b | 0; } // signed modulus
function SHL(a, b) { return b > 31 ? 0 : a << b; } // fix JS shift
function SHR(a, b) { return b > 31 ? 0 : a >>> b; } // fix JS shift
function SHIFT(a, b) { return b < 0 ? (b < -31 ? 0 : a >>> (0-b) ) : (b > 31 ? 0 : a << b); }
function PTR_ADD(p, n) { return new Int32Array(p.buffer, p.byteOffset + n * 4); }
function FPTR_ADD(p, n) { return new Float32Array(p.buffer, p.byteOffset + n * 4); }
/*** Variables ***/
var interpreterProxy = null;
var moduleName = "GeniePlugin v2.0 14 November 2014 (e)";
/* arguments are pointer to ints paired as x,y coordinates of points */
function cSquaredDistanceFromto(aPoint, bPoint) {
var aPointX;
var bPointX;
var xDiff;
var aPointY;
var bPointY;
var yDiff;
aPointX = aPoint[0];
aPointY = aPoint[1];
bPointX = bPoint[0];
bPointY = bPoint[1];
xDiff = bPointX - aPointX;
yDiff = bPointY - aPointY;
return (xDiff * xDiff) + (yDiff * yDiff);
}
function cSubstAngleFactorFromto(startDegreeNumber, endDegreeNumber) {
var absDiff;
absDiff = Math.abs(endDegreeNumber - startDegreeNumber);
if (absDiff > 180) {
absDiff = 360 - absDiff;
}
return (absDiff * absDiff) >>> 6;
}
/* 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! */
function getModuleName() {
return moduleName;
}
function halt() {
;
}
function majorNO() {
return 2;
}
function minorNO() {
return 0;
}
function msg(s) {
console.log(moduleName + ": " + s);
}
function primSameClassAbsoluteStrokeDistanceMyPoints_otherPoints_myVectors_otherVectors_mySquaredLengths_otherSquaredLengths_myAngles_otherAngles_maxSizeAndReferenceFlag_rowBase_rowInsertRemove_rowInsertRemoveCount() {
var otherAngles;
var otherSquaredLengthsSize;
var forReference;
var jM1;
var iM1;
var jM1T2;
var base;
var insert;
var otherVectors;
var otherVectorsSize;
var otherSquaredLengths;
var rowBaseSize;
var myPoints;
var jLimiT;
var mySquaredLengths;
var additionalMultiInsertRemoveCost;
var remove;
var otherPoints;
var otherPointsSize;
var myVectors;
var rowInsertRemoveCount;
var rowBase;
var maxDist;
var iM1T2;
var j;
var insertRemove;
var i;
var myVectorsSize;
var subst;
var maxSize;
var removeBase;
var substBase;
var myAngles;
var insertRemoveCount;
var rowInsertRemove;
var insertBase;
var myPointsOop;
var otherPointsOop;
var myVectorsOop;
var otherVectorsOop;
var mySquaredLengthsOop;
var otherSquaredLengthsOop;
var myAnglesOop;
var otherAnglesOop;
var maxSizeAndRefFlag;
var rowBaseOop;
var rowInsertRemoveOop;
var rowInsertRemoveCountOop;
var _return_value;
myPointsOop = interpreterProxy.stackValue(11);
otherPointsOop = interpreterProxy.stackValue(10);
myVectorsOop = interpreterProxy.stackValue(9);
otherVectorsOop = interpreterProxy.stackValue(8);
mySquaredLengthsOop = interpreterProxy.stackValue(7);
otherSquaredLengthsOop = interpreterProxy.stackValue(6);
myAnglesOop = interpreterProxy.stackValue(5);
otherAnglesOop = interpreterProxy.stackValue(4);
maxSizeAndRefFlag = interpreterProxy.stackIntegerValue(3);
rowBaseOop = interpreterProxy.stackValue(2);
rowInsertRemoveOop = interpreterProxy.stackValue(1);
rowInsertRemoveCountOop = interpreterProxy.stackValue(0);
if (interpreterProxy.failed()) {
return null;
}
if (interpreterProxy.failed()) {
msg("failed 1");
return null;
}
interpreterProxy.success((((((((((interpreterProxy.isWords(myPointsOop) && interpreterProxy.isWords(otherPointsOop)) && interpreterProxy.isWords(myVectorsOop)) && interpreterProxy.isWords(otherVectorsOop)) && interpreterProxy.isWords(mySquaredLengthsOop)) && interpreterProxy.isWords(otherSquaredLengthsOop)) && interpreterProxy.isWords(myAnglesOop)) && interpreterProxy.isWords(otherAnglesOop)) && interpreterProxy.isWords(rowBaseOop)) && interpreterProxy.isWords(rowInsertRemoveOop)) && interpreterProxy.isWords(rowInsertRemoveCountOop));
if (interpreterProxy.failed()) {
msg("failed 2");
return null;
}
interpreterProxy.success(interpreterProxy.isMemberOf(myPointsOop, "PointArray") && interpreterProxy.isMemberOf(otherPointsOop, "PointArray"));
if (interpreterProxy.failed()) {
msg("failed 3");
return null;
}
myPoints = myPointsOop.wordsAsInt32Array();
otherPoints = otherPointsOop.wordsAsInt32Array();
myVectors = myVectorsOop.wordsAsInt32Array();
otherVectors = otherVectorsOop.wordsAsInt32Array();
mySquaredLengths = mySquaredLengthsOop.wordsAsInt32Array();
otherSquaredLengths = otherSquaredLengthsOop.wordsAsInt32Array();
myAngles = myAnglesOop.wordsAsInt32Array();
otherAngles = otherAnglesOop.wordsAsInt32Array();
rowBase = rowBaseOop.wordsAsInt32Array();
rowInsertRemove = rowInsertRemoveOop.wordsAsInt32Array();
/* Note: myPointsSize and mySquaredLengthsSize variables eliminated to reduce
method temporary variable count for closure-enabled images */
/* PointArrays */
/* myPointsSize := (interpreterProxy stSizeOf: myPointsOop) bitShift: -1. */
rowInsertRemoveCount = rowInsertRemoveCountOop.wordsAsInt32Array();
otherPointsSize = SIZEOF(otherPointsOop) >>> 1;
myVectorsSize = SIZEOF(myVectorsOop) >>> 1;
/* IntegerArrays */
/* mySquaredLengthsSize := interpreterProxy stSizeOf: mySquaredLengthsOop. */
otherVectorsSize = SIZEOF(otherVectorsOop) >>> 1;
otherSquaredLengthsSize = SIZEOF(otherSquaredLengthsOop);
rowBaseSize = SIZEOF(rowBaseOop);
interpreterProxy.success(((rowBaseSize === SIZEOF(rowInsertRemoveOop)) && (rowBaseSize === SIZEOF(rowInsertRemoveCountOop))) && (rowBaseSize > otherVectorsSize));
if (interpreterProxy.failed()) {
msg("failed 4");
return null;
}
interpreterProxy.success((((((SIZEOF(mySquaredLengthsOop) >= (myVectorsSize - 1)) && ((SIZEOF(myPointsOop) >>> 1) >= myVectorsSize)) && (otherSquaredLengthsSize >= (otherVectorsSize - 1))) && (otherPointsSize >= otherVectorsSize)) && (SIZEOF(myAnglesOop) >= (myVectorsSize - 1))) && (SIZEOF(otherAnglesOop) >= (otherVectorsSize - 1)));
if (interpreterProxy.failed()) {
msg("failed 5");
return null;
}
forReference = maxSizeAndRefFlag & 1;
maxSize = maxSizeAndRefFlag >>> 1;
maxDist = 1 << 29;
if (forReference) {
additionalMultiInsertRemoveCost = 0;
} else {
additionalMultiInsertRemoveCost = (maxSize * maxSize) >>> 10;
}
rowBase[0] = 0;
rowInsertRemove[0] = 0;
rowInsertRemoveCount[0] = 2;
insertRemove = 0 - additionalMultiInsertRemoveCost;
jLimiT = otherVectorsSize;
if (!((otherPointsSize >= (jLimiT - 1)) && (otherSquaredLengthsSize >= (jLimiT - 1)))) {
interpreterProxy.primitiveFail();
return null;
}
for (j = 1; j <= jLimiT; j++) {
jM1 = j - 1;
insertRemove = (insertRemove + ((otherSquaredLengths[jM1] + cSquaredDistanceFromto(PTR_ADD(otherPoints, (jM1 << 1)), myPoints)) >>> 7)) + additionalMultiInsertRemoveCost;
rowInsertRemove[j] = insertRemove;
rowBase[j] = (insertRemove * j);
rowInsertRemoveCount[j] = (j + 1);
}
insertRemove = rowInsertRemove[0] - additionalMultiInsertRemoveCost;
for (i = 1; i <= myVectorsSize; i++) {
iM1 = i - 1;
iM1T2 = iM1 << 1;
substBase = rowBase[0];
insertRemove = (insertRemove + ((mySquaredLengths[iM1] + cSquaredDistanceFromto(PTR_ADD(myPoints, iM1T2), otherPoints)) >>> 7)) + additionalMultiInsertRemoveCost;
rowInsertRemove[0] = insertRemove;
rowBase[0] = (insertRemove * i);
rowInsertRemoveCount[0] = (i + 1);
jLimiT = otherVectorsSize;
for (j = 1; j <= jLimiT; j++) {
jM1 = j - 1;
jM1T2 = jM1 << 1;
removeBase = rowBase[j];
insertBase = rowBase[jM1];
remove = (mySquaredLengths[iM1] + cSquaredDistanceFromto(PTR_ADD(myPoints, iM1T2), PTR_ADD(otherPoints, (j << 1)))) >>> 7;
if (((insertRemove = rowInsertRemove[j])) === 0) {
removeBase += remove;
} else {
removeBase = (removeBase + insertRemove) + (remove * rowInsertRemoveCount[j]);
remove += insertRemove;
}
insert = (otherSquaredLengths[jM1] + cSquaredDistanceFromto(PTR_ADD(otherPoints, jM1T2), PTR_ADD(myPoints, (i << 1)))) >>> 7;
if (((insertRemove = rowInsertRemove[jM1])) === 0) {
insertBase += insert;
} else {
insertBase = (insertBase + insertRemove) + (insert * rowInsertRemoveCount[jM1]);
insert += insertRemove;
}
if (forReference) {
substBase = maxDist;
} else {
subst = ((cSquaredDistanceFromto(PTR_ADD(otherVectors, jM1T2), PTR_ADD(myVectors, iM1T2)) + cSquaredDistanceFromto(PTR_ADD(otherPoints, jM1T2), PTR_ADD(myPoints, iM1T2))) * (16 + cSubstAngleFactorFromto(otherAngles[jM1], myAngles[iM1]))) >>> 11;
substBase += subst;
}
if ((substBase <= removeBase) && (substBase <= insertBase)) {
base = substBase;
insertRemove = 0;
insertRemoveCount = 1;
} else {
if (removeBase <= insertBase) {
base = removeBase;
insertRemove = remove + additionalMultiInsertRemoveCost;
insertRemoveCount = rowInsertRemoveCount[j] + 1;
} else {
base = insertBase;
insertRemove = insert + additionalMultiInsertRemoveCost;
insertRemoveCount = rowInsertRemoveCount[jM1] + 1;
}
}
substBase = rowBase[j];
rowBase[j] = Math.min(base, maxDist);
rowInsertRemove[j] = Math.min(insertRemove, maxDist);
rowInsertRemoveCount[j] = insertRemoveCount;
}
insertRemove = rowInsertRemove[0];
}
_return_value = base;
if (interpreterProxy.failed()) {
return null;
}
interpreterProxy.popthenPush(13, _return_value);
return null;
}
/* majorNO * 1000 + minorNO */
function primVersionNO() {
var _return_value;
_return_value = ((majorNO() * 1000) + minorNO());
if (interpreterProxy.failed()) {
return null;
}
interpreterProxy.popthenPush(1, _return_value);
return null;
}
/* Note: This is coded so that is can be run from Squeak. */
function setInterpreter(anInterpreter) {
var ok;
interpreterProxy = anInterpreter;
ok = interpreterProxy.majorVersion() == VM_PROXY_MAJOR;
if (ok === false) {
return false;
}
ok = interpreterProxy.minorVersion() >= VM_PROXY_MINOR;
return ok;
}
function registerPlugin() {
if (typeof Squeak === "object" && Squeak.registerExternalModule) {
Squeak.registerExternalModule("GeniePlugin", {
primVersionNO: primVersionNO,
setInterpreter: setInterpreter,
primSameClassAbsoluteStrokeDistanceMyPoints_otherPoints_myVectors_otherVectors_mySquaredLengths_otherSquaredLengths_myAngles_otherAngles_maxSizeAndReferenceFlag_rowBase_rowInsertRemove_rowInsertRemoveCount: primSameClassAbsoluteStrokeDistanceMyPoints_otherPoints_myVectors_otherVectors_mySquaredLengths_otherSquaredLengths_myAngles_otherAngles_maxSizeAndReferenceFlag_rowBase_rowInsertRemove_rowInsertRemoveCount,
getModuleName: getModuleName,
});
} else self.setTimeout(registerPlugin, 100);
}
registerPlugin();
})(); // Register module/plugin
|