[Vm-dev] [commit][2617] Initial checkin of generated sources,
beginning with sources in
commits at squeakvm.org
commits at squeakvm.org
Sat Sep 22 00:45:10 UTC 2012
Revision: 2617
Author: lewis
Date: 2012-09-21 17:45:09 -0700 (Fri, 21 Sep 2012)
Log Message:
-----------
Initial checkin of generated sources, beginning with sources in
http://squeakvm.org/unix/release/Squeak-4.10.2.2614-src.tar.gz. These
are C sources generated from Smalltalk source code managed separately
in VMMaker and related repositories and hosted under Monticello source
control on source.squeak.org and squeaksource.com.
Added Paths:
-----------
trunk/src/ckformat.c
trunk/src/plugins/
trunk/src/plugins/ADPCMCodecPlugin/
trunk/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c
trunk/src/plugins/AioPlugin/
trunk/src/plugins/AioPlugin/AioPlugin.c
trunk/src/plugins/AsynchFilePlugin/
trunk/src/plugins/AsynchFilePlugin/AsynchFilePlugin.c
trunk/src/plugins/B2DPlugin/
trunk/src/plugins/B2DPlugin/B2DPlugin.c
trunk/src/plugins/B3DAcceleratorPlugin/
trunk/src/plugins/B3DAcceleratorPlugin/B3DAcceleratorPlugin.c
trunk/src/plugins/BMPReadWriterPlugin/
trunk/src/plugins/BMPReadWriterPlugin/BMPReadWriterPlugin.c
trunk/src/plugins/BitBltPlugin/
trunk/src/plugins/BitBltPlugin/BitBltPlugin.c
trunk/src/plugins/CameraPlugin/
trunk/src/plugins/CameraPlugin/CameraPlugin.c
trunk/src/plugins/ClipboardExtendedPlugin/
trunk/src/plugins/ClipboardExtendedPlugin/ClipboardExtendedPlugin.c
trunk/src/plugins/CroquetPlugin/
trunk/src/plugins/CroquetPlugin/CroquetPlugin.c
trunk/src/plugins/DBusPlugin/
trunk/src/plugins/DBusPlugin/DBusPlugin.c
trunk/src/plugins/DSAPrims/
trunk/src/plugins/DSAPrims/DSAPrims.c
trunk/src/plugins/DropPlugin/
trunk/src/plugins/DropPlugin/DropPlugin.c
trunk/src/plugins/FFTPlugin/
trunk/src/plugins/FFTPlugin/FFTPlugin.c
trunk/src/plugins/FT2Plugin/
trunk/src/plugins/FT2Plugin/FT2Plugin.c
trunk/src/plugins/FileCopyPlugin/
trunk/src/plugins/FileCopyPlugin/FileCopyPlugin.c
trunk/src/plugins/FilePlugin/
trunk/src/plugins/FilePlugin/FilePlugin.c
trunk/src/plugins/FloatArrayPlugin/
trunk/src/plugins/FloatArrayPlugin/FloatArrayPlugin.c
trunk/src/plugins/FloatMathPlugin/
trunk/src/plugins/FloatMathPlugin/FloatMathPlugin.c
trunk/src/plugins/GeniePlugin/
trunk/src/plugins/GeniePlugin/GeniePlugin.c
trunk/src/plugins/HostWindowPlugin/
trunk/src/plugins/HostWindowPlugin/HostWindowPlugin.c
trunk/src/plugins/JPEGReadWriter2Plugin/
trunk/src/plugins/JPEGReadWriter2Plugin/JPEGReadWriter2Plugin.c
trunk/src/plugins/JPEGReaderPlugin/
trunk/src/plugins/JPEGReaderPlugin/JPEGReaderPlugin.c
trunk/src/plugins/JoystickTabletPlugin/
trunk/src/plugins/JoystickTabletPlugin/JoystickTabletPlugin.c
trunk/src/plugins/Klatt/
trunk/src/plugins/Klatt/Klatt.c
trunk/src/plugins/LargeIntegers/
trunk/src/plugins/LargeIntegers/LargeIntegers.c
trunk/src/plugins/LocalePlugin/
trunk/src/plugins/LocalePlugin/LocalePlugin.c
trunk/src/plugins/MIDIPlugin/
trunk/src/plugins/MIDIPlugin/MIDIPlugin.c
trunk/src/plugins/Matrix2x3Plugin/
trunk/src/plugins/Matrix2x3Plugin/Matrix2x3Plugin.c
trunk/src/plugins/MiscPrimitivePlugin/
trunk/src/plugins/MiscPrimitivePlugin/MiscPrimitivePlugin.c
trunk/src/plugins/Mpeg3Plugin/
trunk/src/plugins/Mpeg3Plugin/Mpeg3Plugin.c
trunk/src/plugins/RePlugin/
trunk/src/plugins/RePlugin/RePlugin.c
trunk/src/plugins/RomePlugin/
trunk/src/plugins/RomePlugin/RomePlugin.c
trunk/src/plugins/ScratchPlugin/
trunk/src/plugins/ScratchPlugin/ScratchPlugin.c
trunk/src/plugins/SecurityPlugin/
trunk/src/plugins/SecurityPlugin/SecurityPlugin.c
trunk/src/plugins/SerialPlugin/
trunk/src/plugins/SerialPlugin/SerialPlugin.c
trunk/src/plugins/SlangTestSupportPlugin/
trunk/src/plugins/SlangTestSupportPlugin/SlangTestSupportPlugin.c
trunk/src/plugins/SocketPlugin/
trunk/src/plugins/SocketPlugin/SocketPlugin.c
trunk/src/plugins/SoundCodecPrims/
trunk/src/plugins/SoundCodecPrims/SoundCodecPrims.c
trunk/src/plugins/SoundGenerationPlugin/
trunk/src/plugins/SoundGenerationPlugin/SoundGenerationPlugin.c
trunk/src/plugins/SoundPlugin/
trunk/src/plugins/SoundPlugin/SoundPlugin.c
trunk/src/plugins/Squeak3D/
trunk/src/plugins/Squeak3D/Squeak3D.c
trunk/src/plugins/SqueakFFIPrims/
trunk/src/plugins/SqueakFFIPrims/SqueakFFIPrims.c
trunk/src/plugins/StarSqueakPlugin/
trunk/src/plugins/StarSqueakPlugin/StarSqueakPlugin.c
trunk/src/plugins/UUIDPlugin/
trunk/src/plugins/UUIDPlugin/UUIDPlugin.c
trunk/src/plugins/UnicodePlugin/
trunk/src/plugins/UnicodePlugin/UnicodePlugin.c
trunk/src/plugins/UnixOSProcessPlugin/
trunk/src/plugins/UnixOSProcessPlugin/UnixOSProcessPlugin.c
trunk/src/plugins/WeDoPlugin/
trunk/src/plugins/WeDoPlugin/WeDoPlugin.c
trunk/src/plugins/XDisplayControlPlugin/
trunk/src/plugins/XDisplayControlPlugin/XDisplayControlPlugin.c
trunk/src/plugins/ZipPlugin/
trunk/src/plugins/ZipPlugin/ZipPlugin.c
trunk/src/vm/
trunk/src/vm/interp.c
trunk/src/vm/interp.h
trunk/src/vm/sqNamedPrims.h
Added: trunk/src/ckformat.c
===================================================================
--- trunk/src/ckformat.c (rev 0)
+++ trunk/src/ckformat.c 2012-09-22 00:45:09 UTC (rev 2617)
@@ -0,0 +1,217 @@
+/* ckformat: Print the image format number on standard output */
+/* for use in a shell script to test image format requirements. */
+/* A non-zero return status code indicates failure. */
+
+/* Usage: ckformat imageFileName */
+
+/* --- DO NOT EDIT THIS FILE --- */
+/* --- Automatically generated from class ImageFormat 2012-07-30T16:53:09.683-07:00--- */
+/* --- Souce code is in package ImageFormat, archive www.squeaksource.com/VMMaker --- */
+/* --- DO NOT EDIT THIS FILE --- */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+main(int argc, char **argv) {
+ FILE *f;
+ unsigned char buf[8];
+ int formatNumber;
+ unsigned char c;
+ int match;
+ if (argc != 2) {
+ printf("usage: ckformat imageFileName\n");
+ exit(1);
+ }
+ f = fopen(argv[1], "r");
+ if (f == NULL) {
+ perror(argv[1]);
+ exit(2);
+ }
+ if(fseek(f, 0L, SEEK_SET) != 0) {
+ fprintf(stderr, "cannot go to pos %d in %s\n", 0, argv[1]);
+ exit(3);
+ }
+ if (fread(buf, 1, 8, f) < 8) {
+ fprintf(stderr, "cannot read %s\n", argv[1]);
+ exit(3);
+ }
+ {
+ unsigned char b_6502_1[4]= { 0, 0, 25, 102};
+ if (strncmp(buf, b_6502_1, 4) == 0) {
+ printf("%d", 6502);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6502_2[4]= { 102, 25, 0, 0};
+ if (strncmp(buf, b_6502_2, 4) == 0) {
+ printf("%d", 6502);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6504_3[4]= { 0, 0, 25, 104};
+ if (strncmp(buf, b_6504_3, 4) == 0) {
+ printf("%d", 6504);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6504_4[4]= { 104, 25, 0, 0};
+ if (strncmp(buf, b_6504_4, 4) == 0) {
+ printf("%d", 6504);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6505_5[4]= { 0, 0, 25, 105};
+ if (strncmp(buf, b_6505_5, 4) == 0) {
+ printf("%d", 6505);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6505_6[4]= { 105, 25, 0, 0};
+ if (strncmp(buf, b_6505_6, 4) == 0) {
+ printf("%d", 6505);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68000_7[8]= { 0, 0, 0, 0, 0, 1, 9, 160};
+ if (strncmp(buf, b_68000_7, 8) == 0) {
+ printf("%d", 68000);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68000_8[8]= { 160, 9, 1, 0, 0, 0, 0, 0};
+ if (strncmp(buf, b_68000_8, 8) == 0) {
+ printf("%d", 68000);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68002_9[8]= { 0, 0, 0, 0, 0, 1, 9, 162};
+ if (strncmp(buf, b_68002_9, 8) == 0) {
+ printf("%d", 68002);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68002_10[8]= { 162, 9, 1, 0, 0, 0, 0, 0};
+ if (strncmp(buf, b_68002_10, 8) == 0) {
+ printf("%d", 68002);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68003_11[8]= { 0, 0, 0, 0, 0, 1, 9, 163};
+ if (strncmp(buf, b_68003_11, 8) == 0) {
+ printf("%d", 68003);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68003_12[8]= { 163, 9, 1, 0, 0, 0, 0, 0};
+ if (strncmp(buf, b_68003_12, 8) == 0) {
+ printf("%d", 68003);
+ exit(0);
+ }
+ }
+ if(fseek(f, 512L, SEEK_SET) != 0) {
+ fprintf(stderr, "cannot go to pos %d in %s\n", 512, argv[1]);
+ exit(3);
+ }
+ if (fread(buf, 1, 8, f) < 8) {
+ fprintf(stderr, "cannot read %s\n", argv[1]);
+ exit(3);
+ }
+ {
+ unsigned char b_6502_1[4]= { 0, 0, 25, 102};
+ if (strncmp(buf, b_6502_1, 4) == 0) {
+ printf("%d", 6502);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6502_2[4]= { 102, 25, 0, 0};
+ if (strncmp(buf, b_6502_2, 4) == 0) {
+ printf("%d", 6502);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6504_3[4]= { 0, 0, 25, 104};
+ if (strncmp(buf, b_6504_3, 4) == 0) {
+ printf("%d", 6504);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6504_4[4]= { 104, 25, 0, 0};
+ if (strncmp(buf, b_6504_4, 4) == 0) {
+ printf("%d", 6504);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6505_5[4]= { 0, 0, 25, 105};
+ if (strncmp(buf, b_6505_5, 4) == 0) {
+ printf("%d", 6505);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_6505_6[4]= { 105, 25, 0, 0};
+ if (strncmp(buf, b_6505_6, 4) == 0) {
+ printf("%d", 6505);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68000_7[8]= { 0, 0, 0, 0, 0, 1, 9, 160};
+ if (strncmp(buf, b_68000_7, 8) == 0) {
+ printf("%d", 68000);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68000_8[8]= { 160, 9, 1, 0, 0, 0, 0, 0};
+ if (strncmp(buf, b_68000_8, 8) == 0) {
+ printf("%d", 68000);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68002_9[8]= { 0, 0, 0, 0, 0, 1, 9, 162};
+ if (strncmp(buf, b_68002_9, 8) == 0) {
+ printf("%d", 68002);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68002_10[8]= { 162, 9, 1, 0, 0, 0, 0, 0};
+ if (strncmp(buf, b_68002_10, 8) == 0) {
+ printf("%d", 68002);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68003_11[8]= { 0, 0, 0, 0, 0, 1, 9, 163};
+ if (strncmp(buf, b_68003_11, 8) == 0) {
+ printf("%d", 68003);
+ exit(0);
+ }
+ }
+ {
+ unsigned char b_68003_12[8]= { 163, 9, 1, 0, 0, 0, 0, 0};
+ if (strncmp(buf, b_68003_12, 8) == 0) {
+ printf("%d", 68003);
+ exit(0);
+ }
+ }
+ printf("0"); /* print an invalid format number */
+ exit (-1); /* not found, exit with error code */
+}
Added: trunk/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c
===================================================================
--- trunk/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c (rev 0)
+++ trunk/src/plugins/ADPCMCodecPlugin/ADPCMCodecPlugin.c 2012-09-22 00:45:09 UTC (rev 2617)
@@ -0,0 +1,802 @@
+/* Automatically generated from Squeak on 30 July 2012 4:52:28 pm
+ by VMMaker 4.9.8
+ */
+
+#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"
+
+
+
+/*** Proxy Functions ***/
+#define stackValue(i) (interpreterProxy->stackValue(i))
+#define stackIntegerValue(i) (interpreterProxy->stackIntegerValue(i))
+#define successFlag (!interpreterProxy->failed())
+#define success(bool) (interpreterProxy->success(bool))
+#define arrayValueOf(oop) (interpreterProxy->arrayValueOf(oop))
+#define checkedIntegerValueOf(oop) (interpreterProxy->checkedIntegerValueOf(oop))
+#define fetchArrayofObject(idx,oop) (interpreterProxy->fetchArrayofObject(idx,oop))
+#define fetchFloatofObject(idx,oop) (interpreterProxy->fetchFloatofObject(idx,oop))
+#define fetchIntegerofObject(idx,oop) (interpreterProxy->fetchIntegerofObject(idx,oop))
+#define floatValueOf(oop) (interpreterProxy->floatValueOf(oop))
+#define pop(n) (interpreterProxy->pop(n))
+#define pushInteger(n) (interpreterProxy->pushInteger(n))
+#define sizeOfSTArrayFromCPrimitive(cPtr) (interpreterProxy->sizeOfSTArrayFromCPrimitive(cPtr))
+#define storeIntegerofObjectwithValue(idx,oop,value) (interpreterProxy->storeIntegerofObjectwithValue(idx,oop,value))
+#define primitiveFail() interpreterProxy->primitiveFail()
+/* allows accessing Strings in both C and Smalltalk */
+#define asciiValue(c) c
+
+
+/*** Constants ***/
+
+/*** Variables ***/
+
+#ifdef SQUEAK_BUILTIN_PLUGIN
+extern
+#endif
+struct VirtualMachine* interpreterProxy;
+static const char *moduleName =
+#ifdef SQUEAK_BUILTIN_PLUGIN
+ "ADPCMCodecPlugin 30 July 2012 (i)"
+#else
+ "ADPCMCodecPlugin 30 July 2012 (e)"
+#endif
+;
+
+/*** Function Prototypes ***/
+#pragma export on
+EXPORT(const char*) getModuleName(void);
+#pragma export off
+static sqInt halt(void);
+#pragma export on
+EXPORT(sqInt) primitiveDecodeMono(void);
+EXPORT(sqInt) primitiveDecodeStereo(void);
+EXPORT(sqInt) primitiveEncodeMono(void);
+EXPORT(sqInt) primitiveEncodeStereo(void);
+EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter);
+#pragma export off
+
+
+/* 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;
+}
+
+static sqInt halt(void) {
+ ;
+}
+
+EXPORT(sqInt) primitiveDecodeMono(void) {
+ sqInt rcvr;
+ sqInt count;
+ sqInt bit;
+ sqInt delta;
+ sqInt i;
+ sqInt predictedDelta;
+ sqInt step;
+ sqInt remaining;
+ sqInt result;
+ sqInt shift;
+ sqInt remaining1;
+ sqInt result1;
+ sqInt shift1;
+ sqInt remaining2;
+ sqInt result2;
+ sqInt shift2;
+ sqInt predicted;
+ sqInt index;
+ sqInt deltaSignMask;
+ sqInt deltaValueMask;
+ sqInt deltaValueHighBit;
+ sqInt frameSizeMask;
+ sqInt currentByte;
+ sqInt bitPosition;
+ sqInt byteIndex;
+ unsigned char *encodedBytes;
+ short int *samples;
+ sqInt sampleIndex;
+ sqInt bitsPerSample;
+ short int *stepSizeTable;
+ short int *indexTable;
+
+ rcvr = stackValue(1);
+ count = stackIntegerValue(0);
+ predicted = fetchIntegerofObject(0, rcvr);
+ index = fetchIntegerofObject(1, rcvr);
+ deltaSignMask = fetchIntegerofObject(2, rcvr);
+ deltaValueMask = fetchIntegerofObject(3, rcvr);
+ deltaValueHighBit = fetchIntegerofObject(4, rcvr);
+ frameSizeMask = fetchIntegerofObject(5, rcvr);
+ currentByte = fetchIntegerofObject(6, rcvr);
+ bitPosition = fetchIntegerofObject(7, rcvr);
+ byteIndex = fetchIntegerofObject(8, rcvr);
+ encodedBytes = fetchArrayofObject(9, rcvr);
+ encodedBytes -= 1;
+ samples = fetchArrayofObject(10, rcvr);
+ samples -= 1;
+ sampleIndex = fetchIntegerofObject(12, rcvr);
+ bitsPerSample = fetchIntegerofObject(13, rcvr);
+ stepSizeTable = fetchArrayofObject(14, rcvr);
+ stepSizeTable -= 1;
+ indexTable = fetchArrayofObject(15, rcvr);
+ indexTable -= 1;
+ if (!(successFlag)) {
+ return null;
+ }
+ for (i = 1; i <= count; i += 1) {
+ if ((i & frameSizeMask) == 1) {
+ /* begin nextBits: */
+ result = 0;
+ remaining = 16;
+ while(1) {
+ shift = remaining - bitPosition;
+ result += ((shift < 0) ? ((usqInt) currentByte >> -shift) : ((usqInt) currentByte << shift));
+ if (shift > 0) {
+ remaining -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ predicted = result;
+ goto l1;
+ }
+ }
+ l1: /* end nextBits: */;
+ if (predicted > 32767) {
+ predicted -= 65536;
+ }
+ /* begin nextBits: */
+ result1 = 0;
+ remaining1 = 6;
+ while(1) {
+ shift1 = remaining1 - bitPosition;
+ result1 += ((shift1 < 0) ? ((usqInt) currentByte >> -shift1) : ((usqInt) currentByte << shift1));
+ if (shift1 > 0) {
+ remaining1 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining1;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ index = result1;
+ goto l2;
+ }
+ }
+ l2: /* end nextBits: */;
+ samples[(sampleIndex += 1)] = predicted;
+ } else {
+ /* begin nextBits: */
+ result2 = 0;
+ remaining2 = bitsPerSample;
+ while(1) {
+ shift2 = remaining2 - bitPosition;
+ result2 += ((shift2 < 0) ? ((usqInt) currentByte >> -shift2) : ((usqInt) currentByte << shift2));
+ if (shift2 > 0) {
+ remaining2 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining2;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ delta = result2;
+ goto l3;
+ }
+ }
+ l3: /* end nextBits: */;
+ step = stepSizeTable[index + 1];
+ predictedDelta = 0;
+ bit = deltaValueHighBit;
+ while (bit > 0) {
+ if ((delta & bit) > 0) {
+ predictedDelta += step;
+ }
+ step = ((usqInt) step >> 1);
+ bit = ((usqInt) bit >> 1);
+ }
+ predictedDelta += step;
+ if ((delta & deltaSignMask) > 0) {
+ predicted -= predictedDelta;
+ } else {
+ predicted += predictedDelta;
+ }
+ if (predicted > 32767) {
+ predicted = 32767;
+ } else {
+ if (predicted < -32768) {
+ predicted = -32768;
+ }
+ }
+ index += indexTable[(delta & deltaValueMask) + 1];
+ if (index < 0) {
+ index = 0;
+ } else {
+ if (index > 88) {
+ index = 88;
+ }
+ }
+ samples[(sampleIndex += 1)] = predicted;
+ }
+ }
+ if (!(successFlag)) {
+ return null;
+ }
+ storeIntegerofObjectwithValue(0, rcvr, predicted);
+ storeIntegerofObjectwithValue(1, rcvr, index);
+ storeIntegerofObjectwithValue(6, rcvr, currentByte);
+ storeIntegerofObjectwithValue(7, rcvr, bitPosition);
+ storeIntegerofObjectwithValue(8, rcvr, byteIndex);
+ storeIntegerofObjectwithValue(12, rcvr, sampleIndex);
+ pop(1);
+}
+
+EXPORT(sqInt) primitiveDecodeStereo(void) {
+ sqInt rcvr;
+ sqInt count;
+ sqInt bit;
+ sqInt deltaLeft;
+ sqInt deltaRight;
+ sqInt i;
+ sqInt indexLeft;
+ sqInt indexRight;
+ sqInt predictedDeltaLeft;
+ sqInt predictedDeltaRight;
+ sqInt predictedLeft;
+ sqInt predictedRight;
+ sqInt stepLeft;
+ sqInt stepRight;
+ sqInt remaining;
+ sqInt result;
+ sqInt shift;
+ sqInt remaining1;
+ sqInt result1;
+ sqInt shift1;
+ sqInt remaining2;
+ sqInt result2;
+ sqInt shift2;
+ sqInt remaining3;
+ sqInt result3;
+ sqInt shift3;
+ sqInt remaining4;
+ sqInt result4;
+ sqInt shift4;
+ sqInt remaining5;
+ sqInt result5;
+ sqInt shift5;
+ short int *predicted;
+ short int *index;
+ sqInt deltaSignMask;
+ sqInt deltaValueMask;
+ sqInt deltaValueHighBit;
+ sqInt frameSizeMask;
+ sqInt currentByte;
+ sqInt bitPosition;
+ sqInt byteIndex;
+ unsigned char *encodedBytes;
+ short int *samples;
+ short int *rightSamples;
+ sqInt sampleIndex;
+ sqInt bitsPerSample;
+ short int *stepSizeTable;
+ short int *indexTable;
+
+ rcvr = stackValue(1);
+ count = stackIntegerValue(0);
+ predicted = fetchArrayofObject(0, rcvr);
+ predicted -= 1;
+ index = fetchArrayofObject(1, rcvr);
+ index -= 1;
+ deltaSignMask = fetchIntegerofObject(2, rcvr);
+ deltaValueMask = fetchIntegerofObject(3, rcvr);
+ deltaValueHighBit = fetchIntegerofObject(4, rcvr);
+ frameSizeMask = fetchIntegerofObject(5, rcvr);
+ currentByte = fetchIntegerofObject(6, rcvr);
+ bitPosition = fetchIntegerofObject(7, rcvr);
+ byteIndex = fetchIntegerofObject(8, rcvr);
+ encodedBytes = fetchArrayofObject(9, rcvr);
+ encodedBytes -= 1;
+ samples = fetchArrayofObject(10, rcvr);
+ samples -= 1;
+ rightSamples = fetchArrayofObject(11, rcvr);
+ rightSamples -= 1;
+ sampleIndex = fetchIntegerofObject(12, rcvr);
+ bitsPerSample = fetchIntegerofObject(13, rcvr);
+ stepSizeTable = fetchArrayofObject(14, rcvr);
+ stepSizeTable -= 1;
+ indexTable = fetchArrayofObject(15, rcvr);
+ indexTable -= 1;
+ if (!(successFlag)) {
+ return null;
+ }
+
+ /* make local copies of decoder state variables */
+
+ predictedLeft = predicted[1];
+ predictedRight = predicted[2];
+ indexLeft = index[1];
+ indexRight = index[2];
+ for (i = 1; i <= count; i += 1) {
+ if ((i & frameSizeMask) == 1) {
+ /* begin nextBits: */
+ result = 0;
+ remaining = 16;
+ while(1) {
+ shift = remaining - bitPosition;
+ result += ((shift < 0) ? ((usqInt) currentByte >> -shift) : ((usqInt) currentByte << shift));
+ if (shift > 0) {
+ remaining -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ predictedLeft = result;
+ goto l1;
+ }
+ }
+ l1: /* end nextBits: */;
+ /* begin nextBits: */
+ result1 = 0;
+ remaining1 = 6;
+ while(1) {
+ shift1 = remaining1 - bitPosition;
+ result1 += ((shift1 < 0) ? ((usqInt) currentByte >> -shift1) : ((usqInt) currentByte << shift1));
+ if (shift1 > 0) {
+ remaining1 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining1;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ indexLeft = result1;
+ goto l2;
+ }
+ }
+ l2: /* end nextBits: */;
+ /* begin nextBits: */
+ result2 = 0;
+ remaining2 = 16;
+ while(1) {
+ shift2 = remaining2 - bitPosition;
+ result2 += ((shift2 < 0) ? ((usqInt) currentByte >> -shift2) : ((usqInt) currentByte << shift2));
+ if (shift2 > 0) {
+ remaining2 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining2;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ predictedRight = result2;
+ goto l3;
+ }
+ }
+ l3: /* end nextBits: */;
+ /* begin nextBits: */
+ result3 = 0;
+ remaining3 = 6;
+ while(1) {
+ shift3 = remaining3 - bitPosition;
+ result3 += ((shift3 < 0) ? ((usqInt) currentByte >> -shift3) : ((usqInt) currentByte << shift3));
+ if (shift3 > 0) {
+ remaining3 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining3;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ indexRight = result3;
+ goto l4;
+ }
+ }
+ l4: /* end nextBits: */;
+ if (predictedLeft > 32767) {
+ predictedLeft -= 65536;
+ }
+ if (predictedRight > 32767) {
+ predictedRight -= 65536;
+ }
+ samples[(sampleIndex += 1)] = predictedLeft;
+ rightSamples[sampleIndex] = predictedRight;
+ } else {
+ /* begin nextBits: */
+ result4 = 0;
+ remaining4 = bitsPerSample;
+ while(1) {
+ shift4 = remaining4 - bitPosition;
+ result4 += ((shift4 < 0) ? ((usqInt) currentByte >> -shift4) : ((usqInt) currentByte << shift4));
+ if (shift4 > 0) {
+ remaining4 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining4;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ deltaLeft = result4;
+ goto l5;
+ }
+ }
+ l5: /* end nextBits: */;
+ /* begin nextBits: */
+ result5 = 0;
+ remaining5 = bitsPerSample;
+ while(1) {
+ shift5 = remaining5 - bitPosition;
+ result5 += ((shift5 < 0) ? ((usqInt) currentByte >> -shift5) : ((usqInt) currentByte << shift5));
+ if (shift5 > 0) {
+ remaining5 -= bitPosition;
+ currentByte = encodedBytes[(byteIndex += 1)];
+ bitPosition = 8;
+ } else {
+ bitPosition -= remaining5;
+ currentByte = currentByte & ((((bitPosition - 8) < 0) ? ((usqInt) 255 >> -(bitPosition - 8)) : ((usqInt) 255 << (bitPosition - 8))));
+ deltaRight = result5;
+ goto l6;
+ }
+ }
+ l6: /* end nextBits: */;
+ stepLeft = stepSizeTable[indexLeft + 1];
+ stepRight = stepSizeTable[indexRight + 1];
+ predictedDeltaLeft = (predictedDeltaRight = 0);
+ bit = deltaValueHighBit;
+ while (bit > 0) {
+ if ((deltaLeft & bit) > 0) {
+ predictedDeltaLeft += stepLeft;
+ }
+ if ((deltaRight & bit) > 0) {
+ predictedDeltaRight += stepRight;
+ }
+ stepLeft = ((usqInt) stepLeft >> 1);
+ stepRight = ((usqInt) stepRight >> 1);
+ bit = ((usqInt) bit >> 1);
+ }
+ predictedDeltaLeft += stepLeft;
+ predictedDeltaRight += stepRight;
+ if ((deltaLeft & deltaSignMask) > 0) {
+ predictedLeft -= predictedDeltaLeft;
+ } else {
+ predictedLeft += predictedDeltaLeft;
+ }
+ if ((deltaRight & deltaSignMask) > 0) {
+ predictedRight -= predictedDeltaRight;
+ } else {
+ predictedRight += predictedDeltaRight;
+ }
+ if (predictedLeft > 32767) {
+ predictedLeft = 32767;
+ } else {
+ if (predictedLeft < -32768) {
+ predictedLeft = -32768;
+ }
+ }
+ if (predictedRight > 32767) {
+ predictedRight = 32767;
+ } else {
+ if (predictedRight < -32768) {
+ predictedRight = -32768;
+ }
+ }
+ indexLeft += indexTable[(deltaLeft & deltaValueMask) + 1];
+ if (indexLeft < 0) {
+ indexLeft = 0;
+ } else {
+ if (indexLeft > 88) {
+ indexLeft = 88;
+ }
+ }
+ indexRight += indexTable[(deltaRight & deltaValueMask) + 1];
+ if (indexRight < 0) {
+ indexRight = 0;
+ } else {
+ if (indexRight > 88) {
+ indexRight = 88;
+ }
+ }
+ samples[(sampleIndex += 1)] = predictedLeft;
+ rightSamples[sampleIndex] = predictedRight;
+ }
+ }
+ predicted[1] = predictedLeft;
+ predicted[2] = predictedRight;
+ index[1] = indexLeft;
+ index[2] = indexRight;
+ if (!(successFlag)) {
+ return null;
+ }
+ storeIntegerofObjectwithValue(6, rcvr, currentByte);
+ storeIntegerofObjectwithValue(7, rcvr, bitPosition);
+ storeIntegerofObjectwithValue(8, rcvr, byteIndex);
+ storeIntegerofObjectwithValue(12, rcvr, sampleIndex);
+ pop(1);
+}
+
+EXPORT(sqInt) primitiveEncodeMono(void) {
+ sqInt rcvr;
+ sqInt count;
+ sqInt bit;
+ sqInt delta;
+ sqInt diff;
+ sqInt i;
+ sqInt p;
+ sqInt predictedDelta;
+ sqInt sign;
+ sqInt step;
+ sqInt bestIndex;
+ sqInt diff1;
+ sqInt j;
+ sqInt bitsAvailable;
+ sqInt buf;
+ sqInt bufBits;
+ sqInt shift;
+ sqInt bitsAvailable1;
+ sqInt buf1;
+ sqInt bufBits1;
+ sqInt shift1;
+ sqInt bitsAvailable2;
+ sqInt buf2;
+ sqInt bufBits2;
+ sqInt shift2;
+ sqInt predicted;
+ sqInt index;
+ sqInt deltaSignMask;
+ sqInt deltaValueHighBit;
+ sqInt frameSizeMask;
+ sqInt currentByte;
+ sqInt bitPosition;
+ sqInt byteIndex;
+ unsigned char *encodedBytes;
+ short int *samples;
+ sqInt sampleIndex;
+ sqInt bitsPerSample;
+ short int *stepSizeTable;
+ short int *indexTable;
+
+ rcvr = stackValue(1);
+ count = stackIntegerValue(0);
+ predicted = fetchIntegerofObject(0, rcvr);
+ index = fetchIntegerofObject(1, rcvr);
+ deltaSignMask = fetchIntegerofObject(2, rcvr);
+ deltaValueHighBit = fetchIntegerofObject(4, rcvr);
+ frameSizeMask = fetchIntegerofObject(5, rcvr);
+ currentByte = fetchIntegerofObject(6, rcvr);
+ bitPosition = fetchIntegerofObject(7, rcvr);
+ byteIndex = fetchIntegerofObject(8, rcvr);
+ encodedBytes = fetchArrayofObject(9, rcvr);
+ encodedBytes -= 1;
+ samples = fetchArrayofObject(10, rcvr);
+ samples -= 1;
+ sampleIndex = fetchIntegerofObject(12, rcvr);
+ bitsPerSample = fetchIntegerofObject(13, rcvr);
+ stepSizeTable = fetchArrayofObject(14, rcvr);
+ stepSizeTable -= 1;
+ indexTable = fetchArrayofObject(15, rcvr);
+ indexTable -= 1;
+ if (!(successFlag)) {
+ return null;
+ }
+ step = stepSizeTable[1];
+ for (i = 1; i <= count; i += 1) {
+ if ((i & frameSizeMask) == 1) {
+ predicted = samples[(sampleIndex += 1)];
+ if (((p = predicted)) < 0) {
+ p += 65536;
+ }
+ /* begin nextBits:put: */
+ buf = p;
+ bufBits = 16;
+ while(1) {
+ bitsAvailable = 8 - bitPosition;
+ shift = bitsAvailable - bufBits;
+ currentByte += ((shift < 0) ? ((usqInt) buf >> -shift) : ((usqInt) buf << shift));
+ if (shift < 0) {
+ encodedBytes[(byteIndex += 1)] = currentByte;
+ bitPosition = 0;
+ currentByte = 0;
+ buf = buf & (((((0 - shift) < 0) ? ((usqInt) 1 >> -(0 - shift)) : ((usqInt) 1 << (0 - shift)))) - 1);
+ bufBits -= bitsAvailable;
+ } else {
+ bitPosition += bufBits;
+ goto l1;
+ }
+ }
+ l1: /* end nextBits:put: */;
+ if (i < count) {
+ /* begin indexForDeltaFrom:to: */
+ diff1 = (samples[sampleIndex + 1]) - predicted;
+ if (diff1 < 0) {
+ diff1 = 0 - diff1;
+ }
+ bestIndex = 63;
+ for (j = 1; j <= 62; j += 1) {
+ if (bestIndex == 63) {
+ if ((stepSizeTable[j]) >= diff1) {
+ bestIndex = j;
+ }
+ }
+ }
+ index = bestIndex;
+ }
+ /* begin nextBits:put: */
+ buf1 = index;
+ bufBits1 = 6;
+ while(1) {
+ bitsAvailable1 = 8 - bitPosition;
+ shift1 = bitsAvailable1 - bufBits1;
+ currentByte += ((shift1 < 0) ? ((usqInt) buf1 >> -shift1) : ((usqInt) buf1 << shift1));
+ if (shift1 < 0) {
+ encodedBytes[(byteIndex += 1)] = currentByte;
+ bitPosition = 0;
+ currentByte = 0;
+ buf1 = buf1 & (((((0 - shift1) < 0) ? ((usqInt) 1 >> -(0 - shift1)) : ((usqInt) 1 << (0 - shift1)))) - 1);
+ bufBits1 -= bitsAvailable1;
+ } else {
+ bitPosition += bufBits1;
+ goto l2;
+ }
+ }
+ l2: /* end nextBits:put: */;
+ } else {
+
+ /* compute sign and magnitude of difference from the predicted sample */
+
+ sign = 0;
+ diff = (samples[(sampleIndex += 1)]) - predicted;
+ if (diff < 0) {
+ sign = deltaSignMask;
+ diff = 0 - diff;
+ }
+ delta = 0;
+ predictedDelta = 0;
+ bit = deltaValueHighBit;
+ while (bit > 0) {
+ if (diff >= step) {
+ delta += bit;
+ predictedDelta += step;
+ diff -= step;
+ }
+ step = ((usqInt) step >> 1);
+ bit = ((usqInt) bit >> 1);
+ }
+
+ /* compute and clamp new prediction */
+
+ predictedDelta += step;
+ if (sign > 0) {
+ predicted -= predictedDelta;
+ } else {
+ predicted += predictedDelta;
+ }
+ if (predicted > 32767) {
+ predicted = 32767;
+ } else {
+ if (predicted < -32768) {
+ predicted = -32768;
+ }
+ }
+ index += indexTable[delta + 1];
+ if (index < 0) {
+ index = 0;
+ } else {
+ if (index > 88) {
+ index = 88;
+ }
+ }
+
+ /* output encoded, signed delta */
+
+ step = stepSizeTable[index + 1];
+ /* begin nextBits:put: */
+ buf2 = sign | delta;
+ bufBits2 = bitsPerSample;
+ while(1) {
+ bitsAvailable2 = 8 - bitPosition;
+ shift2 = bitsAvailable2 - bufBits2;
+ currentByte += ((shift2 < 0) ? ((usqInt) buf2 >> -shift2) : ((usqInt) buf2 << shift2));
+ if (shift2 < 0) {
+ encodedBytes[(byteIndex += 1)] = currentByte;
+ bitPosition = 0;
+ currentByte = 0;
+ buf2 = buf2 & (((((0 - shift2) < 0) ? ((usqInt) 1 >> -(0 - shift2)) : ((usqInt) 1 << (0 - shift2)))) - 1);
+ bufBits2 -= bitsAvailable2;
+ } else {
+ bitPosition += bufBits2;
+ goto l3;
+ }
+ }
+ l3: /* end nextBits:put: */;
+ }
+ }
+ if (bitPosition > 0) {
+ encodedBytes[(byteIndex += 1)] = currentByte;
+ }
+ if (!(successFlag)) {
+ return null;
+ }
+ storeIntegerofObjectwithValue(0, rcvr, predicted);
+ storeIntegerofObjectwithValue(1, rcvr, index);
+ storeIntegerofObjectwithValue(6, rcvr, currentByte);
+ storeIntegerofObjectwithValue(7, rcvr, bitPosition);
+ storeIntegerofObjectwithValue(8, rcvr, byteIndex);
+ storeIntegerofObjectwithValue(12, rcvr, sampleIndex);
+ pop(1);
+}
+
+
+/* not yet implemented */
+
+EXPORT(sqInt) primitiveEncodeStereo(void) {
+ sqInt rcvr;
+ sqInt count;
+
+ rcvr = stackValue(1);
+ count = stackIntegerValue(0);
+ if (!(successFlag)) {
+ return null;
+ }
+ success(0);
+ if (!(successFlag)) {
+ return null;
+ }
+ pop(1);
+}
+
+
+/* Note: This is coded so that is can be run from Squeak. */
+
+EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter) {
+ sqInt ok;
+
+ interpreterProxy = anInterpreter;
+ ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
+ if (ok == 0) {
+ return 0;
+ }
+ ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
+ return ok;
+}
+
+
+#ifdef SQUEAK_BUILTIN_PLUGIN
+
+
+void* ADPCMCodecPlugin_exports[][3] = {
+ {"ADPCMCodecPlugin", "primitiveDecodeStereo", (void*)primitiveDecodeStereo},
+ {"ADPCMCodecPlugin", "setInterpreter", (void*)setInterpreter},
+ {"ADPCMCodecPlugin", "primitiveEncodeStereo", (void*)primitiveEncodeStereo},
+ {"ADPCMCodecPlugin", "primitiveEncodeMono", (void*)primitiveEncodeMono},
+ {"ADPCMCodecPlugin", "primitiveDecodeMono", (void*)primitiveDecodeMono},
+ {"ADPCMCodecPlugin", "getModuleName", (void*)getModuleName},
+ {NULL, NULL, NULL}
+};
+
+
+#endif /* ifdef SQ_BUILTIN_PLUGIN */
+
Added: trunk/src/plugins/AioPlugin/AioPlugin.c
===================================================================
--- trunk/src/plugins/AioPlugin/AioPlugin.c (rev 0)
+++ trunk/src/plugins/AioPlugin/AioPlugin.c 2012-09-22 00:45:09 UTC (rev 2617)
@@ -0,0 +1,483 @@
+/* Automatically generated from Squeak on 30 July 2012 4:53:07 pm
+ by VMMaker 4.9.8
+ */
+
+#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 <unistd.h>
+#define FILEHANDLETYPE FILE * /* the type of low level stream to be used in a struct SQFile */
+#include "FilePlugin.h"
+#include "SocketPlugin.h"
+#include "config.h"
+#define SESSIONIDENTIFIERTYPE int
+#include "sqaio.h"
+
+#include "sqMemoryAccess.h"
+
+
+/*** Constants ***/
+
+/*** Function Prototypes ***/
+static void aioForwardwithDataandFlags(int fd, void *data, int flags);
+static FILEHANDLETYPE fileHandleFrom(sqInt sqFileStructByteArray);
+static sqInt fileRecordSize(void);
+#pragma export on
+EXPORT(const char*) getModuleName(void);
+#pragma export off
+static sqInt halt(void);
+#pragma export on
+EXPORT(sqInt) initialiseModule(void);
+#pragma export off
+static sqInt isNonNullSQFile(sqInt objectPointer);
+static sqInt isNullSQSocket(sqInt objectPointer);
+#pragma export on
+EXPORT(sqInt) moduleUnloaded(char *aModuleName);
+EXPORT(sqInt) primitiveAioDisable(void);
+EXPORT(sqInt) primitiveAioEnable(void);
+EXPORT(sqInt) primitiveAioHandle(void);
+EXPORT(sqInt) primitiveAioSuspend(void);
+EXPORT(sqInt) primitiveModuleName(void);
+EXPORT(sqInt) primitiveOSFileHandle(void);
+EXPORT(sqInt) primitiveOSSocketHandle(void);
+EXPORT(sqInt) primitiveVersionString(void);
+#pragma export off
+static SESSIONIDENTIFIERTYPE sessionIdentifierFromSqFile(SQFile *sqFile);
+#pragma export on
+EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter);
+EXPORT(sqInt) shutdownModule(void);
+#pragma export off
+static int socketDescriptorFrom(sqInt sqSocketOop);
+static sqInt socketRecordSize(void);
+static sqInt stringFromCString(const char *aCString);
+static char * versionString(void);
+/*** Variables ***/
+
+#ifdef SQUEAK_BUILTIN_PLUGIN
+extern
+#endif
+struct VirtualMachine* interpreterProxy;
+static const char *moduleName =
+#ifdef SQUEAK_BUILTIN_PLUGIN
+ "AioPlugin 30 July 2012 (i)"
+#else
+ "AioPlugin 30 July 2012 (e)"
+#endif
+;
+
+
+
+/* This function is called to signal a Smalltalk Semaphore when an asynchronous event is
+ detected. When translated to C, the name of this method is aioForwardwithDataandFlags.
+ The event handler is set up by #primitiveAioHandle. */
+
+static void aioForwardwithDataandFlags(int fd, void *data, int flags) {
+ int *pfd;
+ sqInt semaIndex;
+
+ pfd = data;
+ semaIndex = *pfd;
+ interpreterProxy->signalSemaphoreWithIndex(semaIndex);
+}
+
+
+/* Answer a file handle from a SQFile structure. On most platforms, this
+ will be a (FILE *). On Win32, it is a HANDLE. */
+
+static FILEHANDLETYPE fileHandleFrom(sqInt sqFileStructByteArray) {
+ SQFile *sqFile;
+
+ sqFile = interpreterProxy->arrayValueOf(sqFileStructByteArray);
+ return sqFile->file;
+}
+
+
+/* Answer the size of a SQFile data structure in bytes. */
+
+static sqInt fileRecordSize(void) {
+ return sizeof(SQFile);
+}
+
+
+/* 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;
+}
+
+static sqInt halt(void) {
+ ;
+}
+
+EXPORT(sqInt) initialiseModule(void) {
+ return 1;
+}
+
+
+/* Check for the common failure mode of a SQFile record with all zeros. */
+
+static sqInt isNonNullSQFile(sqInt objectPointer) {
+ sqInt idx;
+ unsigned char *sqFileBytes;
+
+ sqFileBytes = interpreterProxy->arrayValueOf(objectPointer);
+ idx = 0;
+ while (idx < (fileRecordSize())) {
+ if ((sqFileBytes[idx]) != 0) {
+ return 1;
+ }
+ idx += 1;
+ }
+ return 0;
+}
+
+
+/* Check for the common failure mode of a SQSocket record with all zeros. */
+
+static sqInt isNullSQSocket(sqInt objectPointer) {
+ sqInt idx;
+ unsigned char *sqSocketBytes;
+
+ sqSocketBytes = interpreterProxy->arrayValueOf(objectPointer);
+ idx = 0;
+ while (idx < (socketRecordSize())) {
+ if ((sqSocketBytes[idx]) != 0) {
+ return 0;
+ }
+ idx += 1;
+ }
+ return 1;
+}
+
+
+/* The module with the given name was just unloaded.
+ Make sure we have no dangling references. */
+
+EXPORT(sqInt) moduleUnloaded(char *aModuleName) {
+}
+
+
+/* Definitively disable asynchronous event notification for a descriptor. The
+ parameter is an OS level integer file descriptor. */
+
+EXPORT(sqInt) primitiveAioDisable(void) {
+ sqInt fd;
+
+ if ((interpreterProxy->nilObject()) == (interpreterProxy->stackValue(0))) {
+ return interpreterProxy->primitiveFail();
+ }
+ fd = interpreterProxy->stackIntegerValue(0);
+ if (fd < 0) {
+ return interpreterProxy->primitiveFail();
+ }
+ aioDisable(fd);
+ interpreterProxy->pop(2);
+ interpreterProxy->pushInteger(fd);
+}
+
+
+/* Enable asynchronous notification for a descriptor. The first parameter is an OS
+ level integer file descriptor. The second parameter is the index of a Semaphore to
+ be notified, and the third parameter is a flag indicating that descriptor represents
+ an external object and should not be closed on termination of aio handling. Answer
+ the semaphore index. */
+
+EXPORT(sqInt) primitiveAioEnable(void) {
+ static int eventSemaphoreIndices[FD_SETSIZE];
+ sqInt externalObject;
+ sqInt fd;
+ sqInt flags;
+ sqInt semaIndex;
+
+ if ((interpreterProxy->nilObject()) == (interpreterProxy->stackValue(2))) {
+ return interpreterProxy->primitiveFail();
+ }
+ fd = interpreterProxy->stackIntegerValue(2);
+ if (fd < 0) {
+ return interpreterProxy->primitiveFail();
+ }
+ semaIndex = interpreterProxy->stackIntegerValue(1);
+ eventSemaphoreIndices[semaIndex] = semaIndex;
+ externalObject = interpreterProxy->stackObjectValue(0);
+ if (externalObject == (interpreterProxy->trueObject())) {
+ flags = AIO_EXT;
+ } else {
+ flags = 0;
+ }
+ aioEnable(fd, &(eventSemaphoreIndices[semaIndex]), flags);
+ interpreterProxy->pop(4);
+ interpreterProxy->pushInteger(semaIndex);
+}
+
+
+/* Handle asynchronous event notification for a descriptor. The first parameter is
+ an OS level integer file descriptor. The remaining three parameters are Boolean
+ flags representing the types of events for which notification is being requested:
+ handle exceptions, handle for read, and handle for write.
+ Flags are defined in the aio.h source as:
+ AIO_X (1<<0) handle for exceptions
+ AIO_R (1<<1) handle for read
+ AIO_W (1<<2) handle for write */
+
+EXPORT(sqInt) primitiveAioHandle(void) {
+ sqInt exceptionWatch;
+ sqInt fd;
+ sqInt flags;
+ sqInt readWatch;
+ sqInt writeWatch;
+
+ if ((interpreterProxy->nilObject()) == (interpreterProxy->stackValue(3))) {
+ return interpreterProxy->primitiveFail();
+ }
+ fd = interpreterProxy->stackIntegerValue(3);
+ if (fd < 0) {
+ return interpreterProxy->primitiveFail();
+ }
+ exceptionWatch = interpreterProxy->stackObjectValue(2);
+ readWatch = interpreterProxy->stackObjectValue(1);
+ writeWatch = interpreterProxy->stackObjectValue(0);
+ flags = 0;
+ if (exceptionWatch == (interpreterProxy->trueObject())) {
+ flags = flags | (AIO_X);
+ }
+ if (readWatch == (interpreterProxy->trueObject())) {
+ flags = flags | (AIO_R);
+ }
+ if (writeWatch == (interpreterProxy->trueObject())) {
+ flags = flags | (AIO_W);
+ }
+ aioHandle(fd, aioForwardwithDataandFlags, flags);
+ interpreterProxy->pop(5);
+ interpreterProxy->pushInteger(flags);
+}
+
+
+/* Temporarily suspend asynchronous event notification for a descriptor. The first
+ parameter is an OS level integer file descriptor. The remaining three parameters
+ are Boolean flags representing the types of events for which notification is being
+ requested: handle exceptions, handle for read, and handle for write.
+ Flags are defined in the aio.h source as:
+ AIO_X (1<<0) handle for exceptions
+ AIO_R (1<<1) handle for read
+ AIO_W (1<<2) handle for write */
+
+EXPORT(sqInt) primitiveAioSuspend(void) {
+ sqInt exceptionWatch;
+ sqInt fd;
+ sqInt flags;
+ sqInt readWatch;
+ sqInt writeWatch;
+
+ if ((interpreterProxy->nilObject()) == (interpreterProxy->stackValue(3))) {
+ return interpreterProxy->primitiveFail();
+ }
+ fd = interpreterProxy->stackIntegerValue(3);
+ if (fd < 0) {
+ return interpreterProxy->primitiveFail();
+ }
+ exceptionWatch = interpreterProxy->stackObjectValue(2);
+ readWatch = interpreterProxy->stackObjectValue(1);
+ writeWatch = interpreterProxy->stackObjectValue(0);
+ flags = 0;
+ if (exceptionWatch == (interpreterProxy->trueObject())) {
+ flags = flags | (AIO_X);
+ }
+ if (readWatch == (interpreterProxy->trueObject())) {
+ flags = flags | (AIO_R);
+ }
+ if (writeWatch == (interpreterProxy->trueObject())) {
+ flags = flags | (AIO_W);
+ }
+ aioSuspend(fd, flags);
+ interpreterProxy->pop(5);
+ interpreterProxy->pushInteger(flags);
+}
+
+
+/* Answer a string containing the module name string for this plugin. */
+
+EXPORT(sqInt) primitiveModuleName(void) {
+ interpreterProxy->popthenPush(1, stringFromCString(moduleName));
+}
+
+
+/* Take a struct SQFile from the stack, and answer the value of its Unix file number. */
+
+EXPORT(sqInt) primitiveOSFileHandle(void) {
+ sqInt fileNo;
+ sqInt sqFileOop;
+
+ sqFileOop = interpreterProxy->stackValue(0);
+ if (!((((interpreterProxy->isBytes(sqFileOop)) && ((interpreterProxy->byteSizeOf(sqFileOop)) == (fileRecordSize()))) && ((interpreterProxy->getThisSessionID()) == (sessionIdentifierFromSqFile(interpreterProxy->arrayValueOf(sqFileOop))))) && (isNonNullSQFile(sqFileOop)))) {
+ return interpreterProxy->primitiveFail();
+ }
+ /* begin fileDescriptorFrom: */
+ if (!((((interpreterProxy->isBytes(sqFileOop)) && ((interpreterProxy->byteSizeOf(sqFileOop)) == (fileRecordSize()))) && ((interpreterProxy->getThisSessionID()) == (sessionIdentifierFromSqFile(interpreterProxy->arrayValueOf(sqFileOop))))) && (isNonNullSQFile(sqFileOop)))) {
+ fileNo = -1;
+ goto l1;
+ }
+ fileNo = fileno(fileHandleFrom(sqFileOop));
+l1: /* end fileDescriptorFrom: */;
+ interpreterProxy->pop(2);
+ interpreterProxy->pushInteger(fileNo);
+}
+
+
+/* Take a struct SQSocket from the stack, and answer the value of its Unix file number. */
+
+EXPORT(sqInt) primitiveOSSocketHandle(void) {
+ sqInt fileNo;
+ sqInt sqSocketOop;
+
+ sqSocketOop = interpreterProxy->stackValue(0);
+ if (!(((interpreterProxy->isBytes(sqSocketOop)) && ((interpreterProxy->byteSizeOf(sqSocketOop)) == (socketRecordSize()))) && (!(isNullSQSocket(sqSocketOop))))) {
+ return interpreterProxy->primitiveFail();
+ }
+ fileNo = socketDescriptorFrom(sqSocketOop);
+ if (fileNo < 0) {
+ return interpreterProxy->primitiveFail();
+ }
+ interpreterProxy->pop(2);
+ interpreterProxy->pushInteger(fileNo);
+}
+
+
+/* Answer a string containing the version string for this plugin. */
+
+EXPORT(sqInt) primitiveVersionString(void) {
+ interpreterProxy->popthenPush(1, stringFromCString(versionString()));
+}
+
+
+/* Answer the session identifier from a SQFile structure. For a valid file
+ reference, this identifier will match the session identifier supplied by
+ the interpreter. */
+
+static SESSIONIDENTIFIERTYPE sessionIdentifierFromSqFile(SQFile *sqFile) {
+ return sqFile->sessionID;
+}
+
+
+/* Note: This is coded so that is can be run from Squeak. */
+
+EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter) {
+ sqInt ok;
+
+ interpreterProxy = anInterpreter;
+ ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
+ if (ok == 0) {
+ return 0;
+ }
+ ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
+ return ok;
+}
+
+EXPORT(sqInt) shutdownModule(void) {
+}
+
+
+/* Answer the OS file descriptor, an integer value, from a SQSocket data structure,
+ or answer -1 if unable to obtain the file descriptor (probably due to receiving
+ an incorrect type of object as aFileHandle).
+
+ Warning: The first element of privateSocketStruct happens to be the Unix file
+ number of the socket. See sqUnixSocket.c for the definition. This method takes
+ advantage of this, and will break if anyone ever redefines the data structure. */
+
+static int socketDescriptorFrom(sqInt sqSocketOop) {
+ void *privateSocketStruct;
+ SQSocket *sqSocket;
+
+ sqSocket = interpreterProxy->arrayValueOf(sqSocketOop);
+ privateSocketStruct = sqSocket->privateSocketPtr;
+ if (privateSocketStruct == 0) {
+ return -1;
+ }
+ return * (int *) privateSocketStruct;
+}
+
+
+/* Answer the size of a SQSocket data structure in bytes. */
+
+static sqInt socketRecordSize(void) {
+ return sizeof(SQSocket);
+}
+
+
+/* Answer a new String copied from a null-terminated C string.
+ Caution: This may invoke the garbage collector. */
+
+static sqInt stringFromCString(const char *aCString) {
+ sqInt len;
+ sqInt newString;
+
+ len = strlen(aCString);
+ newString = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classString(), len);
+ strncpy(interpreterProxy->arrayValueOf(newString), aCString, len);
+ return newString;
+}
+
+
+/* Answer a string containing the version string for this plugin. Handle MNU
+ errors, which can occur if class InterpreterPlugin has been removed from
+ the system.
+
+ Important: When this method is changed, the class side method must also be
+ changed to match. */
+/* 2.0 supports 64bit code base */
+
+static char * versionString(void) {
+ static char version[]= "2.2.6";
+
+ return version;
+}
+
+
+#ifdef SQUEAK_BUILTIN_PLUGIN
+
+
+void* AioPlugin_exports[][3] = {
+ {"AioPlugin", "getModuleName", (void*)getModuleName},
+ {"AioPlugin", "primitiveOSSocketHandle", (void*)primitiveOSSocketHandle},
+ {"AioPlugin", "primitiveOSFileHandle", (void*)primitiveOSFileHandle},
+ {"AioPlugin", "primitiveAioHandle", (void*)primitiveAioHandle},
+ {"AioPlugin", "primitiveAioEnable", (void*)primitiveAioEnable},
+ {"AioPlugin", "primitiveVersionString", (void*)primitiveVersionString},
+ {"AioPlugin", "setInterpreter", (void*)setInterpreter},
+ {"AioPlugin", "primitiveModuleName", (void*)primitiveModuleName},
+ {"AioPlugin", "moduleUnloaded", (void*)moduleUnloaded},
+ {"AioPlugin", "primitiveAioSuspend", (void*)primitiveAioSuspend},
+ {"AioPlugin", "shutdownModule", (void*)shutdownModule},
+ {"AioPlugin", "initialiseModule", (void*)initialiseModule},
+ {"AioPlugin", "primitiveAioDisable", (void*)primitiveAioDisable},
+ {NULL, NULL, NULL}
+};
+
+
+#endif /* ifdef SQ_BUILTIN_PLUGIN */
+
Added: trunk/src/plugins/AsynchFilePlugin/AsynchFilePlugin.c
===================================================================
--- trunk/src/plugins/AsynchFilePlugin/AsynchFilePlugin.c (rev 0)
+++ trunk/src/plugins/AsynchFilePlugin/AsynchFilePlugin.c 2012-09-22 00:45:09 UTC (rev 2617)
@@ -0,0 +1,356 @@
+/* Automatically generated from Squeak on 30 July 2012 4:52:29 pm
+ by VMMaker 4.9.8
+ */
+
+#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 "AsynchFilePlugin.h"
+
+#include "sqMemoryAccess.h"
+
+
+/*** Constants ***/
+
+/*** Function Prototypes ***/
+static AsyncFile * asyncFileValueOf(sqInt oop);
+#pragma export on
+EXPORT(const char*) getModuleName(void);
+#pragma export off
+static sqInt halt(void);
+#pragma export on
+EXPORT(sqInt) initialiseModule(void);
+EXPORT(sqInt) moduleUnloaded(char *aModuleName);
+EXPORT(sqInt) primitiveAsyncFileClose(void);
+EXPORT(sqInt) primitiveAsyncFileOpen(void);
+EXPORT(sqInt) primitiveAsyncFileReadResult(void);
+EXPORT(sqInt) primitiveAsyncFileReadStart(void);
+EXPORT(sqInt) primitiveAsyncFileWriteResult(void);
+EXPORT(sqInt) primitiveAsyncFileWriteStart(void);
+EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter);
+EXPORT(sqInt) shutdownModule(void);
+#pragma export off
+/*** Variables ***/
+
+#ifdef SQUEAK_BUILTIN_PLUGIN
+extern
+#endif
+struct VirtualMachine* interpreterProxy;
+static const char *moduleName =
+#ifdef SQUEAK_BUILTIN_PLUGIN
+ "AsynchFilePlugin 30 July 2012 (i)"
+#else
+ "AsynchFilePlugin 30 July 2012 (e)"
+#endif
+;
+static void * sCOAFfn;
+
+
+
+/* Return a pointer to the first byte of the async file record within the given Smalltalk bytes object, or nil if oop is not an async file record. */
+
+static AsyncFile * asyncFileValueOf(sqInt oop) {
+ interpreterProxy->success((!((oop & 1))) && ((interpreterProxy->isBytes(oop)) && ((interpreterProxy->slotSizeOf(oop)) == (sizeof(AsyncFile)))));
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ return (AsyncFile *) (oop + 4);
+}
+
+
+/* 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;
+}
+
+static sqInt halt(void) {
+ ;
+}
+
+
+/* Initialise the module */
+
+EXPORT(sqInt) initialiseModule(void) {
+ sCOAFfn = interpreterProxy->ioLoadFunctionFrom("secCanOpenAsyncFileOfSizeWritable", "SecurityPlugin");
+ return asyncFileInit();
+}
+
+
+/* The module with the given name was just unloaded.
+ Make sure we have no dangling references. */
+
+EXPORT(sqInt) moduleUnloaded(char *aModuleName) {
+ if ((strcmp(aModuleName, "SecurityPlugin")) == 0) {
+
+ /* The security plugin just shut down. How odd. Zero the function pointer we have into it */
+
+ sCOAFfn = 0;
+ }
+}
+
+EXPORT(sqInt) primitiveAsyncFileClose(void) {
+ AsyncFile *f;
+ sqInt fh;
+
+ fh = interpreterProxy->stackValue(0);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ f = asyncFileValueOf(fh);
+ asyncFileClose(f);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(1);
+ return null;
+}
+
+EXPORT(sqInt) primitiveAsyncFileOpen(void) {
+ sqInt fOop;
+ AsyncFile *f;
+ sqInt fileNameSize;
+ sqInt okToOpen;
+ char *fileName;
+ sqInt writeFlag;
+ sqInt semaIndex;
+
+ interpreterProxy->success(interpreterProxy->isBytes(interpreterProxy->stackValue(2)));
+ fileName = ((char *) (interpreterProxy->firstIndexableField(interpreterProxy->stackValue(2))));
+ writeFlag = interpreterProxy->booleanValueOf(interpreterProxy->stackValue(1));
+ semaIndex = interpreterProxy->stackIntegerValue(0);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+
+ /* If the security plugin can be loaded, use it to check for permission.
+ If not, assume it's ok */
+
+ fileNameSize = interpreterProxy->slotSizeOf(oopForPointer(fileName) - BASE_HEADER_SIZE);
+ if (sCOAFfn != 0) {
+ okToOpen = ((sqInt (*) (char *, sqInt, sqInt)) sCOAFfn)(fileName, fileNameSize, writeFlag);
+ if (!(okToOpen)) {
+ interpreterProxy->primitiveFail();
+ return null;
+ }
+ }
+ fOop = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classByteArray(), sizeof(AsyncFile));
+ f = asyncFileValueOf(fOop);
+ if (!(interpreterProxy->failed())) {
+ asyncFileOpen(f, fileName, fileNameSize, writeFlag, semaIndex);
+ }
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->popthenPush(4, fOop);
+ return null;
+}
+
+EXPORT(sqInt) primitiveAsyncFileReadResult(void) {
+ sqInt startIndex;
+ sqInt r;
+ sqInt count;
+ char *bufferPtr;
+ AsyncFile *f;
+ sqInt bufferSize;
+ sqInt fhandle;
+ sqInt buffer;
+ sqInt start;
+ sqInt num;
+ sqInt _return_value;
+
+ fhandle = interpreterProxy->stackValue(3);
+ buffer = interpreterProxy->stackValue(2);
+ start = interpreterProxy->stackIntegerValue(1);
+ num = interpreterProxy->stackIntegerValue(0);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ f = asyncFileValueOf(fhandle);
+ count = num;
+ startIndex = start;
+
+ /* in bytes or words */
+
+ bufferSize = interpreterProxy->slotSizeOf(buffer);
+ if (interpreterProxy->isWords(buffer)) {
+
+ /* covert word counts to byte counts */
+
+ count = count * 4;
+ startIndex = ((startIndex - 1) * 4) + 1;
+ bufferSize = bufferSize * 4;
+ }
+ interpreterProxy->success((startIndex >= 1) && (((startIndex + count) - 1) <= bufferSize));
+ bufferPtr = (((pointerForOop(buffer)) + (BASE_HEADER_SIZE)) + startIndex) - 1;
+ if (!(interpreterProxy->failed())) {
+ r = asyncFileReadResult(f, bufferPtr, count);
+ }
+ _return_value = interpreterProxy->integerObjectOf(r);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->popthenPush(5, _return_value);
+ return null;
+}
+
+EXPORT(sqInt) primitiveAsyncFileReadStart(void) {
+ AsyncFile *f;
+ sqInt fHandle;
+ sqInt fPosition;
+ sqInt count;
+
+ fHandle = interpreterProxy->stackValue(2);
+ fPosition = interpreterProxy->stackIntegerValue(1);
+ count = interpreterProxy->stackIntegerValue(0);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ f = asyncFileValueOf(fHandle);
+ asyncFileReadStart(f, fPosition, count);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->pop(3);
+ return null;
+}
+
+EXPORT(sqInt) primitiveAsyncFileWriteResult(void) {
+ sqInt r;
+ AsyncFile *f;
+ sqInt fHandle;
+ sqInt _return_value;
+
+ fHandle = interpreterProxy->stackValue(0);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ f = asyncFileValueOf(fHandle);
+ r = asyncFileWriteResult(f);
+ _return_value = interpreterProxy->integerObjectOf(r);
+ if (interpreterProxy->failed()) {
+ return null;
+ }
+ interpreterProxy->popthenPush(2, _return_value);
+ return null;
+}
+
+EXPORT(sqInt) primitiveAsyncFileWriteStart(void) {
+ sqInt startIndex;
+ sqInt count;
+ char *bufferPtr;
+ AsyncFile *f;
+ sqInt bufferSize;
+ sqInt fHandle;
+ sqInt fPosition;
+ sqInt buffer;
+ sqInt start;
+ sqInt num;
+
+ fHandle = interpreterProxy->stackValue(4);
+ fPosition = interpreterProxy->stackIntegerValue(3);
+ buffer = interpreterProxy->stackValue(2);
@@ Diff output truncated at 50000 characters. @@
More information about the Vm-dev
mailing list