forked from dolphinsmalltalk/DolphinVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterprtProc.inl
124 lines (99 loc) · 3.42 KB
/
InterprtProc.inl
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
/******************************************************************************
File: InterprtProc.Inl
Description:
Inlines for the process related interpreter bodules (e.g. saving/restoring
process context, that sort of thing).
All these are private.
******************************************************************************/
#ifndef _IST_INTERPRT_H_
#error You'll need to include interprt.h
#endif
// Smalltalk classes
#include "STProcess.h"
#include "STMethod.h"
#include "STExternal.h"
inline StackFrame* Interpreter::activeFrame()
{
return m_registers.m_pActiveFrame;
}
inline ProcessOTE* Interpreter::activeProcessPointer()
{
return newProcessWaiting() ? m_oteNewProcess : scheduler()->m_activeProcess;
}
// Returns the active/new process
inline Process* Interpreter::activeProcess()
{
Process* activeProc = activeProcessPointer()->m_location;
_ASSERTE(activeProc->IsValid());
return activeProc;
}
// Always returns the active process, even if a new process is waiting
inline Process* Interpreter::actualActiveProcess()
{
return m_registers.activeProcess();
}
// Always returns the active process, even if a new process is waiting
inline ProcessOTE* Interpreter::actualActiveProcessPointer()
{
return m_registers.m_oteActiveProcess;
}
inline SchedulerOTE* Interpreter::schedulerPointer()
{
return Pointers.Scheduler;
}
inline ProcessorScheduler* Interpreter::scheduler()
{
return m_pProcessor;
}
inline BOOL Interpreter::newProcessWaiting()
{
return !m_oteNewProcess->isNil();
}
///////////////////////////////////////////////////////////////////////////////
inline void InterpreterRegisters::StoreSuspendedFrame()
{
ResizeProcess();
activeProcess()->SetSuspendedFrame(activeFrameOop());
}
inline void InterpreterRegisters::StoreIPInFrame()
{
// Are we storing down IP into correct frame, if not registers are corrupt
ASSERT(m_pMethod == m_pActiveFrame->m_method->m_location);
// Convert address to an offset
int offsetFromBeginningOfByteCodesObject = m_instructionPointer - ObjectMemory::ByteAddressOfObject(m_pMethod->m_byteCodes);
m_pActiveFrame->setInstructionPointer(offsetFromBeginningOfByteCodesObject);
}
inline void InterpreterRegisters::LoadIPFromFrame()
{
int offsetFromBeginningOfByteCodesObject = ObjectMemoryIntegerValueOf(m_pActiveFrame->m_ip);
//ASSERT(offsetFromBeginningOfByteCodesObject >= 0 && offsetFromBeginningOfByteCodesObject < 1024);
m_instructionPointer = ObjectMemory::ByteAddressOfObject(m_pMethod->m_byteCodes) + offsetFromBeginningOfByteCodesObject;
}
inline void InterpreterRegisters::StoreSPInFrame()
{
// Mask SP odd and store as SmallInteger
m_pActiveFrame->setStackPointer(m_stackPointer);
}
inline void InterpreterRegisters::LoadSPFromFrame()
{
// stackPointer is pointer to the top item on the stack (stack pointer increases
// as items are pushed on the stack).The stackPointer is incremented BEFORE
// a new item is pushed, and is a pointer directly into the current
// active process. It is stored down into contexts by setting the SmallInteger
// (odd) bit, as it will always be even (divisible by 4 actually)
m_stackPointer = m_pActiveFrame->stackPointer();
}
inline void InterpreterRegisters::StoreContextRegisters()
{
StoreIPInFrame();
StoreSPInFrame();
}
inline void InterpreterRegisters::PrepareToSuspendProcess()
{
StoreSuspendedFrame();
StoreContextRegisters();
}
inline BOOL Interpreter::SetWakeupEvent()
{
return ::SetEvent(Pointers.WakeupEvent->m_location->m_handle);
}