forked from dolphinsmalltalk/DolphinVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemPrim.cpp
55 lines (41 loc) · 1.64 KB
/
MemPrim.cpp
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
/******************************************************************************
File: MemPrim.cpp
Description:
Implementation of the Interpreter class' primitive methods for instantiating
new objects
******************************************************************************/
#include "Ist.h"
#ifndef _DEBUG
#pragma optimize("s", on)
#pragma auto_inline(off)
#endif
#pragma code_seg(MEM_SEG)
#include "ObjMem.h"
#include "Interprt.h"
#include "InterprtPrim.inl"
// Smalltalk classes
#include "STBehavior.h"
///////////////////////////////////////////////////////////////////////////////
// Storage Management Primitives
// Answer a new process with an initial stack size specified by the first argument, and a maximum
// stack size specified by the second argument.
BOOL __fastcall Interpreter::primitiveNewVirtual()
{
Oop argPointer = stackTop();
if (!ObjectMemoryIsIntegerObject(argPointer))
return primitiveFailure(0); // Arg not a SmallInteger
MWORD maxSize = ObjectMemoryIntegerValueOf(argPointer);
argPointer = stackValue(1);
if (!ObjectMemoryIsIntegerObject(argPointer))
return primitiveFailure(1); // Arg not a SmallInteger
MWORD initialSize = ObjectMemoryIntegerValueOf(argPointer);
BehaviorOTE* receiverClass = reinterpret_cast<BehaviorOTE*>(stackValue(2));
Behavior* behavior = receiverClass->m_location;
if (!behavior->isIndexable())
return primitiveFailure(2);
// We'll not fail now, args are correct types
pop(2);
unsigned fixedFields = behavior->fixedFields();
VirtualOTE* newObject = ObjectMemory::newVirtualObject(receiverClass, initialSize+fixedFields, maxSize+fixedFields);
return replaceStackTopWithNew(newObject);
}