本文整理汇总了C++中PolyWord::AsObjPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ PolyWord::AsObjPtr方法的具体用法?C++ PolyWord::AsObjPtr怎么用?C++ PolyWord::AsObjPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PolyWord
的用法示例。
在下文中一共展示了PolyWord::AsObjPtr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: poly_ffi
//.........这里部分代码省略.........
return Make_arbitrary_precision(taskData, constantTable[index]);
}
case 52: // Return an FFI type
{
unsigned index = get_C_unsigned(taskData, args->Word());
if (index >= sizeof(ffiTypeTable) / sizeof(ffiTypeTable[0]))
raise_exception_string(taskData, EXC_foreign, "Index out of range");
return toSysWord(taskData, ffiTypeTable[index]);
}
case 53: // Extract fields from ffi type.
{
ffi_type *ffit = *(ffi_type**)(args->WordP());
Handle sizeHandle = Make_arbitrary_precision(taskData, ffit->size);
Handle alignHandle = Make_arbitrary_precision(taskData, ffit->alignment);
Handle typeHandle = Make_arbitrary_precision(taskData, ffit->type);
Handle elemHandle = toSysWord(taskData, ffit->elements);
Handle resHandle = alloc_and_save(taskData, 4);
resHandle->WordP()->Set(0, sizeHandle->Word());
resHandle->WordP()->Set(1, alignHandle->Word());
resHandle->WordP()->Set(2, typeHandle->Word());
resHandle->WordP()->Set(3, elemHandle->Word());
return resHandle;
}
case 54: // Construct an ffi type.
{
// This is probably only used to create structs.
size_t size = getPolyUnsigned(taskData, args->WordP()->Get(0));
unsigned short align = get_C_ushort(taskData, args->WordP()->Get(1));
unsigned short type = get_C_ushort(taskData, args->WordP()->Get(2));
unsigned nElems = 0;
for (PolyWord p = args->WordP()->Get(3); !ML_Cons_Cell::IsNull(p); p = ((ML_Cons_Cell*)p.AsObjPtr())->t)
nElems++;
size_t space = sizeof(ffi_type);
// If we need the elements add space for the elements plus
// one extra for the zero terminator.
if (nElems != 0) space += (nElems+1) * sizeof(ffi_type *);
ffi_type *result = (ffi_type*)malloc(space);
// Raise an exception rather than returning zero.
if (result == 0) raise_syscall(taskData, "Insufficient memory", ENOMEM);
ffi_type **elem = 0;
if (nElems != 0) elem = (ffi_type **)(result+1);
memset(result, 0, sizeof(ffi_type)); // Zero it in case they add fields
result->size = size;
result->alignment = align;
result->type = type;
result->elements = elem;
if (elem != 0)
{
for (PolyWord p = args->WordP()->Get(3); !ML_Cons_Cell::IsNull(p); p = ((ML_Cons_Cell*)p.AsObjPtr())->t)
{
PolyWord e = ((ML_Cons_Cell*)p.AsObjPtr())->h;
*elem++ = *(ffi_type**)(e.AsAddress());
}
*elem = 0;
}
return toSysWord(taskData, result);
}
case 55: // Create a CIF. This contains all the types and some extra information.
// The result is in allocated memory followed immediately by the argument type vector.
{
ffi_abi abi = (ffi_abi)get_C_ushort(taskData, args->WordP()->Get(0));
ffi_type *rtype = *(ffi_type **)args->WordP()->Get(1).AsAddress();
示例2: AddObjectsToDepthVectors
// We use _OBJ_GC_MARK to detect when we have visited a cell but not yet
// computed the depth. We have to be careful that this bit is removed
// before we finish in the case that we run out of memory and throw an
// exception. PushToStack may throw the exception if the stack needs to
// grow.
POLYUNSIGNED ProcessAddToVector::AddObjectsToDepthVectors(PolyWord old)
{
// If this is a tagged integer or an IO pointer that's simply a constant.
if (old.IsTagged() || old == PolyWord::FromUnsigned(0))
return 0;
MemSpace *space = gMem.SpaceForAddress(old.AsAddress());
if (space == 0 || space->spaceType == ST_IO)
return 0;
PolyObject *obj = old.AsObjPtr();
POLYUNSIGNED L = obj->LengthWord();
if (OBJ_IS_DEPTH(L)) // tombstone contains genuine depth or 0.
return OBJ_GET_DEPTH(L);
if (obj->LengthWord() & _OBJ_GC_MARK)
return 0; // Marked but not yet scanned. Circular structure.
ASSERT (OBJ_IS_LENGTH(L));
if (obj->IsMutable())
{
// Mutable data in the local or permanent areas
if (! obj->IsByteObject())
{
// Add it to the vector so we will update any addresses it contains.
m_parent->AddToVector(0, L, old.AsObjPtr());
// and follow any addresses to try to merge those.
PushToStack(obj);
obj->SetLengthWord(L | _OBJ_GC_MARK); // To prevent rescan
}
return 0; // Level is zero
}
if (space->spaceType == ST_PERMANENT &&
((PermanentMemSpace*)space)->hierarchy == 0)
{
// Immutable data in the permanent area can't be merged
// because it's read only. We need to follow the addresses
// because they may point to mutable areas containing data
// that can be. A typical case is the root function pointing
// at the global name table containing new declarations.
Bitmap *bm = &((PermanentMemSpace*)space)->shareBitmap;
if (! bm->TestBit((PolyWord*)obj - space->bottom))
{
bm->SetBit((PolyWord*)obj - space->bottom);
if (! obj->IsByteObject())
PushToStack(obj);
}
return 0;
}
/* There's a problem sharing code objects if they have relative calls/jumps
in them to other code. The code of two functions may be identical (e.g.
they both call functions 100 bytes ahead) and so they will appear the
same but if the functions they jump to are different they are actually
different. For that reason we don't share code segments. DCJM 4/1/01 */
if (obj->IsCodeObject())
{
// We want to update addresses in the code segment.
m_parent->AddToVector(0, L, old.AsObjPtr());
PushToStack(obj);
obj->SetLengthWord(L | _OBJ_GC_MARK); // To prevent rescan
return 0;
}
// Byte objects always have depth 1 and can't contain addresses.
if (obj->IsByteObject())
{
m_parent->AddToVector (1, L, old.AsObjPtr());// add to vector at correct depth
obj->SetLengthWord(OBJ_SET_DEPTH(1));
return 1;
}
ASSERT(OBJ_IS_WORD_OBJECT(L)); // That leaves immutable data objects.
PushToStack(obj);
obj->SetLengthWord(L | _OBJ_GC_MARK); // To prevent rescan
return 0;
}