示例#1
0
txSlot* fxNewHostObject(txMachine* the, txDestructor theDestructor)
{
	txSlot* anInstance;
	txSlot* aProperty;

	mxPushUndefined();

	anInstance = fxNewSlot(the);
	anInstance->flag = XS_VALUE_FLAG;
	anInstance->kind = XS_INSTANCE_KIND;
	anInstance->value.instance.garbage = C_NULL;
	anInstance->value.instance.prototype = mxObjectPrototype.value.reference;
	the->stack->value.reference = anInstance;
	the->stack->kind = XS_REFERENCE_KIND;

	aProperty = anInstance->next = fxNewSlot(the);
	aProperty->ID = XS_NO_ID;
	aProperty->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	aProperty->kind = XS_HOST_KIND;
	aProperty->value.host.data = C_NULL;
	aProperty->value.host.variant.destructor = theDestructor;
	
	if (the->frame && (mxFunction->kind == XS_REFERENCE_KIND)) {
		txSlot* slot = mxFunctionInstanceModule(mxFunction->value.reference);
		aProperty = aProperty->next = fxNewSlot(the);
		aProperty->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
		aProperty->kind = slot->kind;
		aProperty->value = slot->value;
	}
	return anInstance;
}
示例#2
0
txSlot* fxNewFunctionInstance(txMachine* the, txID name)
{
    txSlot* instance;
    txSlot* property;

    instance = fxNewObjectInstance(the);
    instance->flag |= XS_VALUE_FLAG;

    /* CODE */
    property = instance->next = fxNewSlot(the);
    property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
    property->kind = mxEmptyCode.kind;
    property->value.code = mxEmptyCode.value.code;

    /* CLOSURE */
    property = property->next = fxNewSlot(the);
    property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
    property->kind = XS_NULL_KIND;

    /* PROTOTYPE */
    property = property->next = fxNewSlot(the);
    property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG;
    property->kind = XS_NULL_KIND;

    /* HOME */
    property = property->next = fxNewSlot(the);
    property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
    property->kind = XS_NULL_KIND;

    /* INFO */
    property = property->next = fxNewSlot(the);
    property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
    property->kind = XS_INFO_KIND;
    property->value.info.length = -1;
    property->value.info.name = name;
#ifdef mxProfile
    property->value.info.profileID = the->profileID;
    the->profileID++;
#endif

    /* MODULE */
    property = property->next = fxNewSlot(the);
    property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
    if (the->frame && (mxFunction->kind == XS_REFERENCE_KIND) && (mxIsFunction(mxFunction->value.reference))) {
        txSlot* slot = mxFunctionInstanceModule(mxFunction->value.reference);
        property->kind = slot->kind;
        property->value = slot->value;
    }
    else
        property->kind = XS_NULL_KIND;

    return instance;
}
示例#3
0
txSlot* fxNewHostFunction(txMachine* the, txCallback theCallback, txInteger theLength, txInteger name)
{
	txSlot* instance;
	txSlot* property;

	mxPushUndefined();
	instance = fxNewSlot(the);
	instance->flag = XS_VALUE_FLAG;
	instance->kind = XS_INSTANCE_KIND;
	instance->value.instance.garbage = C_NULL;
	instance->value.instance.prototype = mxFunctionPrototype.value.reference;
	the->stack->value.reference = instance;
	the->stack->kind = XS_REFERENCE_KIND;

	/* CALLBACK */
	property = instance->next = fxNewSlot(the);
	property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	property->kind = XS_CALLBACK_KIND;
	property->value.callback.address = theCallback;
	property->value.callback.IDs = (txID*)the->code;

	/* CLOSURE */
	property = property->next = fxNewSlot(the);
	property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	property->kind = XS_NULL_KIND;

	/* HOME */
	property = property->next = fxNewSlot(the);
	property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	property->kind = XS_NULL_KIND;

	/* MODULE */
	property = property->next = fxNewSlot(the);
	property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	if (the->frame && (mxFunction->kind == XS_REFERENCE_KIND)) {
		txSlot* slot = mxFunctionInstanceModule(mxFunction->value.reference);
		property->kind = slot->kind;
		property->value = slot->value;
	}
	else
		property->kind = XS_NULL_KIND;

#ifdef mxProfile
	/* PROFILE */
	property = property->next = fxNewSlot(the);
	property->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	property->kind = XS_INTEGER_KIND;
	property->value.integer = the->profileID;
	the->profileID++;
#endif

	/* LENGTH */
	property = property->next = fxNewSlot(the);
	property->flag = XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	property->ID = mxID(_length);
	property->kind = XS_INTEGER_KIND;
	property->value.integer = theLength;

	/* NAME */
	property = property->next = fxNewSlot(the);
	property->flag = XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	property->ID = mxID(_name);
	property->kind = mxEmptyString.kind;
	property->value = mxEmptyString.value;
	if (name != XS_NO_ID)
		fxRenameFunction(the, property, name, "", C_NULL);
		
	return instance;
}