11/****************************************************************************
2- * PROJECT: Common include
2+ * PROJECT: Common include for BackToTheFuture/Squeak/Cog/OpenSmalltalk VM
33* FILE: sq.h
4- * CONTENT:
5- *
6- * AUTHOR:
7- * ADDRESS:
8- * EMAIL:
9- * RCSID: $Id: sq.h 1283 2005-12-31 00:51:12Z rowledge $
104*
5+ * See comments associated with STACKVM, COGVM, SPURVM, COGMTVM,
6+ * below for an overview of various VM flavours & features.
117*/
128
139#ifndef _SQ_H
3531# define IMAGE_DIALECT_NAME "Newspeak"
3632# define DEFAULT_IMAGE_NAME "newspeak.image"
3733# define IMAGE_ENV_NAME "NEWSPEAK_IMAGE"
34+ # elif CuisVM
35+ # define IMAGE_DIALECT_NAME "CuisVM"
36+ # define DEFAULT_IMAGE_NAME "CuisVM.image"
37+ # define IMAGE_ENV_NAME "CUIS_IMAGE"
3838# elif PharoVM
3939# define IMAGE_DIALECT_NAME "Pharo"
4040# define DEFAULT_IMAGE_NAME "Pharo.image"
6565 can be redefined in sqPlatformSpecific.h if desired. These default
6666 versions are defined in terms of the ANSI Standard C libraries.
6767*/
68- #define sqImageFile FILE *
69- #define sqImageFileClose (f ) fclose(f)
70- #define sqImageFileOpen (fileName , mode ) fopen(fileName, mode)
71- #define sqImageFilePosition (f ) ftell(f)
72- #define sqImageFileRead (ptr , sz , count , f ) fread(ptr, sz, count, f)
73- #define sqImageFileSeek (f , pos ) fseek(f, pos, SEEK_SET)
74- #define sqImageFileSeekEnd (f , pos ) fseek(f, pos, SEEK_END)
75- #define sqImageFileWrite (ptr , sz , count , f ) fwrite(ptr, sz, count, f)
76- #define sqImageFileStartLocation (fileRef , fileName , size ) 0
68+ #define sqImageFile FILE *
69+ #define sqImageFileClose (f ) fclose(f)
70+ #define sqImageFileOpen (fileName , mode ) fopen(fileName, mode)
71+ #define sqImageFilePosition (f ) ftell(f)
72+ #define sqImageFileRead (ptr , sz , count , f ) fread(ptr, sz, count, f)
73+ #define sqImageFileSeek (f , pos ) fseek(f, pos, SEEK_SET)
74+ #define sqImageFileSeekEnd (f , pos ) fseek(f, pos, SEEK_END)
75+ #define sqImageFileWrite (ptr , sz , count , f ) fwrite(ptr, sz, count, f)
76+ #define sqImageFileStartLocation (f , fileName ,sz ) 0
7777
7878/* Platform-dependent macros for handling object memory. */
7979
80+ #if SPURVM
81+ /* Spur is an improved object representation/garbage collector/heap manager that
82+ * replaces the original BttF "V3" Memory Manager (so called because Spur came
83+ * after Squeak V3). Spur offers considerable performance improvements but is
84+ * not backwards-compatible with V3, and requires different internal plumbing.
85+ * Unlike the V3 memory manager, Spur manages old space heap memory in segments,
86+ * and is able to release memry back to the OS when the heap shrinks.
87+ */
88+
89+ /* Allocate a region of memory of al least sz bytes, at or above minAddr.
90+ * If the attempt fails, answer null. If the attempt succeeds, answer the
91+ * start of the region and assign its size through asp.
92+ */
93+ extern void * sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto (sqInt sz , void * minAddr , sqInt * asp );
94+ extern void sqDeallocateMemorySegmentAtOfSize (void * addr , sqInt sz );
95+
96+ #else /* SPURVM */
97+
8098/* Note: The grow/shrink macros assume that the object memory can be extended
8199 continuously at its prior end. The garbage collector cannot deal with
82100 'holes' in the object memory so the support code needs to reserve the
88106 actually allocate.
89107 The default implementation assumes a fixed size memory allocated at startup.
90108*/
91- #define sqAllocateMemory (minHeapSize , desiredHeapSize ) malloc(desiredHeapSize)
92- #define sqGrowMemoryBy (oldLimit , delta ) oldLimit
93- #define sqShrinkMemoryBy (oldLimit , delta ) oldLimit
94- #define sqMemoryExtraBytesLeft (includingSwap ) 0
95-
96- #if SPURVM
97- /* Allocate a region of memory of al least sz bytes, at or above minAddr.
98- * If the attempt fails, answer null. If the attempt succeeds, answer the
99- * start of the region and assign its size through asp.
100- */
101- extern void * sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto (sqInt sz , void * minAddr , sqInt * asp );
102- extern void sqDeallocateMemorySegmentAtOfSize (void * addr , sqInt sz );
109+ # define sqAllocateMemory (minHeapSize , desiredHeapSize ) malloc(desiredHeapSize)
110+ # define sqGrowMemoryBy (oldLimit , delta ) oldLimit
111+ # define sqShrinkMemoryBy (oldLimit , delta ) oldLimit
112+ # define sqMemoryExtraBytesLeft (includingSwap ) 0
103113#endif /* SPURVM */
114+
104115#if COGVM
116+ /* Cog is a JIT extension for the VM. It still relies on the Interpreter (called
117+ * the CoInterpreter because it sits alongside the "Cogit") for primitives,
118+ * for executing methods the frst time, and to fall back on in exceptional
119+ * circumstances. COGVM implies STACKVM. See STACKVM below.
120+ */
105121extern void sqMakeMemoryExecutableFromToCodeToDataDelta (usqInt , usqInt , sqInt * );
106122extern void sqMakeMemoryNotExecutableFromTo (usqInt , usqInt );
107123#endif
@@ -169,6 +185,22 @@ long ioMicroMSecs(void);
169185#define MillisecondClockMask 0x1FFFFFFF
170186
171187#if STACKVM
188+ /* STACKVM is a replacement for the original BttF Interpreter VM which
189+ * interpreted code using Context objects as described in Smalltalk-80: the
190+ * Language and its Implementation. STACKVM retains the image-level "illusion"
191+ * of Contexts but maps the most recently active Contexts to stack frames. This
192+ * provides both faster interpretation and enables the COGVM Cogit. The scheme
193+ * is similar to that described in Deutsch & Schiffman's classic Efficient
194+ * Implementation of the Smalltalk-80 Language, but is a third generation
195+ * implementation, providing (and indeed depending on) pure closures, and using
196+ * a LISP-style indirection vector for modifyable closed-over variables to break
197+ * dependencies between stack frames.
198+ * See e.g. www.mirandabanda.org/cogblog/2008/06/07/closures-part-i/
199+ *
200+ * Since all OpenSmalltalk VMs are at least STACKVMs, STACKVM is synonymous
201+ * with OpenSmalltalk-VM and Cog VM.
202+ */
203+ /* Time API, Cog uses 64-bit microseconds fron 1901 as much as possible */
172204extern void forceInterruptCheckFromHeartbeat (void );
173205unsigned long long ioUTCMicrosecondsNow (void );
174206unsigned long long ioUTCMicroseconds (void );
@@ -327,6 +359,16 @@ unsigned long ioHeartbeatFrequency(int);
327359#endif /* STACKVM */
328360
329361#if COGMTVM
362+ /* COGMTVM is a yet-to-be-released "multi-threaded" VM in the style of Python,
363+ * where any thread can own the VM, but only one thread can be running the VM
364+ * at any one time. Unlike Python's Global Interpreter Lock, this VM uses a
365+ * lock-free algorithm, based on David Simmons' design as realised in the AOS
366+ * and S# VMs. Thread switches occur on FFI calls that take long enough for
367+ * the VM to notice (and may take place at other times, but FFI calls are the
368+ * key points). Hence any call any be potentially non-blocking, and thread-
369+ * switch is cheap, simple and efficient. The heartbeat defined above is
370+ * extended to spot blocking FFI calls. See CoInterpreterMT in VMMaker.oscog.
371+ */
330372#define THRLOGSZ 256
331373extern int thrlogidx ;
332374extern char * thrlog [];
@@ -411,7 +453,8 @@ sqInt ioMousePoint(void);
411453sqInt ioPeekKeystroke (void );
412454/* Note: In an event driven architecture, ioProcessEvents is obsolete.
413455 It can be implemented as a no-op since the image will check for
414- events in regular intervals. */
456+ events at regular intervals.
457+ */
415458sqInt ioProcessEvents (void );
416459
417460
@@ -435,134 +478,133 @@ sqInt ioProcessEvents(void);
435478/* Keypress state for keyboard events. */
436479#define EventKeyChar 0
437480#define EventKeyDown 1
438- #define EventKeyUp 2
481+ #define EventKeyUp 2
439482
440483/* Button definitions. */
441484#define RedButtonBit 4
442485#define YellowButtonBit 2
443486#define BlueButtonBit 1
444487
445488/* Modifier definitions. */
446- #define ShiftKeyBit 1
447- #define CtrlKeyBit 2
489+ #define ShiftKeyBit 1
490+ #define CtrlKeyBit 2
448491#define OptionKeyBit 4
449492#define CommandKeyBit 8
450493
451494/* generic input event */
452- typedef struct sqInputEvent
453- {
454- sqIntptr_t type ; /* type of event; either one of EventTypeXXX */
495+ typedef struct sqInputEvent {
496+ sqIntptr_t type ; /* type of event; either one of EventTypeXXX */
455497 usqIntptr_t timeStamp ; /* time stamp */
456- /* the interpretation of the following fields depend on the type of the event */
498+ /* the interpretation of the following fields depend on the event type */
457499 sqIntptr_t unused1 ;
458500 sqIntptr_t unused2 ;
459501 sqIntptr_t unused3 ;
460502 sqIntptr_t unused4 ;
461503 sqIntptr_t unused5 ;
462- sqIntptr_t windowIndex ; /* SmallInteger used in image to identify a host window structure */
504+ sqIntptr_t windowIndex ; /* SmallInteger used in image to identify a host window structure */
463505} sqInputEvent ;
464506
465507/* mouse input event */
466- typedef struct sqMouseEvent
467- {
468- sqIntptr_t type ; /* EventTypeMouse */
508+ typedef struct sqMouseEvent {
509+ sqIntptr_t type ; /* EventTypeMouse */
469510 usqIntptr_t timeStamp ; /* time stamp */
470- sqIntptr_t x ; /* mouse position x */
471- sqIntptr_t y ; /* mouse position y */
472- sqIntptr_t buttons ; /* combination of xxxButtonBit */
473- sqIntptr_t modifiers ; /* combination of xxxKeyBit */
474- sqIntptr_t nrClicks ; /* number of clicks in button downs - was reserved1 */
475- sqIntptr_t windowIndex ; /* host window structure */
511+ sqIntptr_t x ; /* mouse position x */
512+ sqIntptr_t y ; /* mouse position y */
513+ sqIntptr_t buttons ; /* combination of xxxButtonBit */
514+ sqIntptr_t modifiers ; /* combination of xxxKeyBit */
515+ sqIntptr_t nrClicks ; /* number of clicks in button downs - was reserved1 */
516+ sqIntptr_t windowIndex ; /* host window structure */
476517} sqMouseEvent ;
477518
478519/* keyboard input event */
479- typedef struct sqKeyboardEvent
480- {
481- sqIntptr_t type ; /* EventTypeKeyboard */
520+ typedef struct sqKeyboardEvent {
521+ sqIntptr_t type ; /* EventTypeKeyboard */
482522 usqIntptr_t timeStamp ; /* time stamp */
483- sqIntptr_t charCode ; /* character code in Mac Roman encoding */
484- sqIntptr_t pressCode ; /* press code; any of EventKeyXXX */
485- sqIntptr_t modifiers ; /* combination of xxxKeyBit */
486- sqIntptr_t utf32Code ; /* UTF-32 unicode value */
487- sqIntptr_t reserved1 ; /* reserved for future use */
488- sqIntptr_t windowIndex ; /* host window structure */
523+ sqIntptr_t charCode ; /* character code in Mac Roman encoding */
524+ sqIntptr_t pressCode ; /* press code; any of EventKeyXXX */
525+ sqIntptr_t modifiers ; /* combination of xxxKeyBit */
526+ sqIntptr_t utf32Code ; /* UTF-32 unicode value */
527+ sqIntptr_t reserved1 ; /* reserved for future use */
528+ sqIntptr_t windowIndex ; /* host window structure */
489529} sqKeyboardEvent ;
490530
491531/* drop files event */
492- typedef struct sqDragDropFilesEvent
493- {
494- sqIntptr_t type ; /* EventTypeDropFiles */
532+ typedef struct sqDragDropFilesEvent {
533+ sqIntptr_t type ; /* EventTypeDropFiles */
495534 usqIntptr_t timeStamp ; /* time stamp */
496- sqIntptr_t dragType ; /* one of DragXXX (see below) */
497- sqIntptr_t x ; /* mouse position x */
498- sqIntptr_t y ; /* mouse position y */
499- sqIntptr_t modifiers ; /* combination of xxxKeyBit */
500- sqIntptr_t numFiles ; /* number of files in transaction */
501- sqIntptr_t windowIndex ; /* host window structure */
535+ sqIntptr_t dragType ; /* one of DragXXX (see below) */
536+ sqIntptr_t x ; /* mouse position x */
537+ sqIntptr_t y ; /* mouse position y */
538+ sqIntptr_t modifiers ; /* combination of xxxKeyBit */
539+ sqIntptr_t numFiles ; /* number of files in transaction */
540+ sqIntptr_t windowIndex ; /* host window structure */
502541} sqDragDropFilesEvent ;
503542
504- #define SQDragEnter 1 /* drag operation from OS entered Squeak window */
505- #define SQDragMove 2 /* drag operation from OS moved within Squeak window */
506- #define SQDragLeave 3 /* drag operation from OS left Squeak window */
507- #define SQDragDrop 4 /* drag operation dropped contents onto Squeak. */
543+ #define SQDragEnter 1 /* OS drag operation entered Squeak window */
544+ #define SQDragMove 2 /* OS drag operation moved within Squeak window */
545+ #define SQDragLeave 3 /* OS drag operation left Squeak window */
546+ #define SQDragDrop 4 /* OS drag operation dropped contents onto Squeak. */
508547#define SQDragRequest 5 /* data request from other app. */
509548
510549/* menu event */
511- typedef struct sqMenuEvent
512- {
513- sqIntptr_t type ; /* type of event; EventTypeMenu */
550+ typedef struct sqMenuEvent {
551+ sqIntptr_t type ; /* type of event; EventTypeMenu */
514552 usqIntptr_t timeStamp ; /* time stamp */
515- /* the interpretation of the following fields depend on the type of the event */
516- sqIntptr_t menu ; /* platform-dependent to indicate which menu was picked */
517- sqIntptr_t menuItem ; /* given a menu having 1 to N items this maps to the menu item number */
518- sqIntptr_t reserved1 ; /* reserved for future use */
519- sqIntptr_t reserved2 ; /* reserved for future use */
520- sqIntptr_t reserved3 ; /* reserved for future use */
521- sqIntptr_t windowIndex ; /* host window structure */
553+ /* the interpretation of the following fields depend on the event type */
554+ sqIntptr_t menu ; /* platform-dependent to indicate which menu was picked */
555+ sqIntptr_t menuItem ; /* given a menu having 1 to N items this maps to the menu item number */
556+ sqIntptr_t reserved1 ; /* reserved for future use */
557+ sqIntptr_t reserved2 ; /* reserved for future use */
558+ sqIntptr_t reserved3 ; /* reserved for future use */
559+ sqIntptr_t windowIndex ; /* host window structure */
522560} sqMenuEvent ;
523561
524562/* window action event */
525- typedef struct sqWindowEvent
526- {
527- sqIntptr_t type ; /* type of event; EventTypeWindow */
563+ typedef struct sqWindowEvent {
564+ sqIntptr_t type ; /* type of event; EventTypeWindow */
528565 usqIntptr_t timeStamp ; /* time stamp */
529- /* the interpretation of the following fields depend on the type of the event */
530- sqIntptr_t action ; /* one of WindowEventXXX (see below) */
531- sqIntptr_t value1 ; /* used for rectangle edges */
532- sqIntptr_t value2 ; /* used for rectangle edges */
533- sqIntptr_t value3 ; /* used for rectangle edges */
534- sqIntptr_t value4 ; /* used for rectangle edges */
535- sqIntptr_t windowIndex ; /* host window structure */
566+ /* the interpretation of the following fields depend on the event type */
567+ sqIntptr_t action ; /* one of WindowEventXXX (see below) */
568+ sqIntptr_t value1 ; /* used for rectangle edges (left) */
569+ sqIntptr_t value2 ; /* used for rectangle edges (top) */
570+ sqIntptr_t value3 ; /* used for rectangle edges (right) */
571+ sqIntptr_t value4 ; /* used for rectangle edges (bottom) */
572+ sqIntptr_t windowIndex ; /* host window structure */
536573} sqWindowEvent ;
537574
538- #define WindowEventMetricChange 1 /* size or position of window changed - value1-4 are left/top/right/bottom values */
539- #define WindowEventClose 2 /* window close icon pressed */
540- #define WindowEventIconise 3 /* window iconised or hidden etc */
541- #define WindowEventActivated 4 /* window made active - some platforms only - do not rely upon this */
542- #define WindowEventPaint 5 /* window area (in value1-4) needs updating. Some platforms do not need to send this, do not rely on it in image */
543- #define WindowEventStinks 6 /* this window stinks (just to see if people read this stuff) */
544-
545- typedef struct sqComplexEvent
546- {
547- sqIntptr_t type ; /* type of event; EventTypeComplex */
575+ #define WindowEventMetricChange 1 /* size or position of window changed
576+ * value1-4 are left/top/right/bottom
577+ */
578+ #define WindowEventClose 2 /* window close icon pressed */
579+ #define WindowEventIconise 3 /* window iconised or hidden etc */
580+ #define WindowEventActivated 4 /* window made active - some platforms only
581+ * do not rely upon this */
582+ #define WindowEventPaint 5 /* window area (in value1-4) needs updating.
583+ * Some platforms do not need to send this,
584+ * do not rely on it in image */
585+ #define WindowEventChangeScreen 6 /* window moved to new screen.
586+ * rect args are dimensions of new screen */
587+
588+ typedef struct sqComplexEvent {
589+ sqIntptr_t type ; /* type of event; EventTypeComplex */
548590 usqIntptr_t timeStamp ; /* time stamp */
549- /* the interpretation of the following fields depend on the type of the event */
550- sqIntptr_t action ; /* one of ComplexEventXXX (see below) */
551- sqIntptr_t objectPointer ; /* used to point to object */
591+ /* the interpretation of the following fields depend on the event type */
592+ sqIntptr_t action ; /* one of ComplexEventXXX (see below) */
593+ sqIntptr_t objectPointer ; /* used to point to object */
552594 sqIntptr_t unused1 ;
553595 sqIntptr_t unused2 ;
554596 sqIntptr_t unused3 ;
555- sqIntptr_t windowIndex ; /* host window structure */
597+ sqIntptr_t windowIndex ; /* host window structure */
556598} sqComplexEvent ;
557599
558- #define ComplexEventTypeTouchsDown 1
559- #define ComplexEventTypeTouchsUp 2
560- #define ComplexEventTypeTouchsMoved 3
561- #define ComplexEventTypeTouchsStationary 4
562- #define ComplexEventTypeTouchsCancelled 5
600+ #define ComplexEventTypeTouchsDown 1
601+ #define ComplexEventTypeTouchsUp 2
602+ #define ComplexEventTypeTouchsMoved 3
603+ #define ComplexEventTypeTouchsStationary 4
604+ #define ComplexEventTypeTouchsCancelled 5
563605#define ComplexEventTypeAccelerationData 6
564- #define ComplexEventTypeLocationData 7
565- #define ComplexEventTypeApplicationData 8
606+ #define ComplexEventTypeLocationData 7
607+ #define ComplexEventTypeApplicationData 8
566608
567609
568610/* Set an asynchronous input semaphore index for events. */
@@ -607,18 +649,6 @@ sqInt clipboardReadIntoAt(sqInt count, sqInt byteArrayIndex, sqInt startIndex);
607649sqInt clipboardWriteFromAt (sqInt count , sqInt byteArrayIndex , sqInt startIndex );
608650
609651
610- /* Interpreter entry points needed by compiled primitives. */
611- void * arrayValueOf (sqInt arrayOop );
612- sqInt checkedIntegerValueOf (sqInt intOop );
613- void * fetchArrayofObject (sqInt fieldIndex , sqInt objectPointer );
614- double fetchFloatofObject (sqInt fieldIndex , sqInt objectPointer );
615- sqInt fetchIntegerofObject (sqInt fieldIndex , sqInt objectPointer );
616- double floatValueOf (sqInt floatOop );
617- sqInt pop (sqInt nItems );
618- sqInt pushInteger (sqInt integerValue );
619- sqInt sizeOfSTArrayFromCPrimitive (void * cPtr );
620- sqInt storeIntegerofObjectwithValue (sqInt fieldIndex , sqInt objectPointer , sqInt integerValue );
621-
622652/* System attributes. */
623653sqInt attributeSize (sqInt indexNumber );
624654sqInt getAttributeIntoLength (sqInt indexNumber , sqInt byteArrayIndex , sqInt length );
0 commit comments