txSlot* fxToInstance(txMachine* the, txSlot* theSlot) { txSlot* anInstance = C_NULL; switch (theSlot->kind) { case XS_UNDEFINED_KIND: mxTypeError("cannot coerce undefined to object"); break; case XS_NULL_KIND: mxTypeError("cannot coerce null to object"); break; case XS_BOOLEAN_KIND: mxPush(mxBooleanPrototype); anInstance = fxNewBooleanInstance(the); anInstance->next->value.boolean = theSlot->value.boolean; mxPullSlot(theSlot); break; case XS_INTEGER_KIND: mxPush(mxNumberPrototype); anInstance = fxNewNumberInstance(the); anInstance->next->value.number = theSlot->value.integer; mxPullSlot(theSlot); break; case XS_NUMBER_KIND: mxPush(mxNumberPrototype); anInstance = fxNewNumberInstance(the); anInstance->next->value.number = theSlot->value.number; mxPullSlot(theSlot); break; case XS_STRING_KIND: case XS_STRING_X_KIND: mxPush(mxStringPrototype); anInstance = fxNewStringInstance(the); anInstance->next->value.string = theSlot->value.string; anInstance->next->next->next->value.integer = fxUnicodeLength(theSlot->value.string); mxPullSlot(theSlot); break; case XS_SYMBOL_KIND: mxPush(mxSymbolPrototype); anInstance = fxNewSymbolInstance(the); anInstance->next->value.ID = theSlot->value.ID; mxPullSlot(theSlot); break; case XS_REFERENCE_KIND: anInstance = theSlot->value.reference; break; default: mxTypeError("cannot coerce to instance"); break; } return anInstance; }
void fxBuildBoolean(txMachine* the) { static const txHostFunctionBuilder gx_Boolean_prototype_builders[] = { { fx_Boolean_prototype_toString, 0, _toString }, { fx_Boolean_prototype_valueOf, 0, _valueOf }, { C_NULL, 0, 0 }, }; const txHostFunctionBuilder* builder; txSlot* slot; mxPush(mxObjectPrototype); slot = fxLastProperty(the, fxNewBooleanInstance(the)); for (builder = gx_Boolean_prototype_builders; builder->callback; builder++) slot = fxNextHostFunctionProperty(the, slot, builder->callback, builder->length, mxID(builder->id), XS_DONT_ENUM_FLAG); mxBooleanPrototype = *the->stack; fxNewHostConstructorGlobal(the, fx_Boolean, 1, mxID(_Boolean), XS_DONT_ENUM_FLAG); the->stack++; }
void fxBuildBoolean(txMachine* the) { mxPush(mxGlobal); mxPush(mxObjectPrototype); fxNewBooleanInstance(the); fxNewHostFunction(the, fx_Boolean_toString, 0); fxQueueID(the, fxID(the, "toLocaleString"), XS_DONT_ENUM_FLAG); fxNewHostFunction(the, fx_Boolean_toString, 0); fxQueueID(the, fxID(the, "toString"), XS_DONT_ENUM_FLAG); fxNewHostFunction(the, fx_Boolean_valueOf, 0); fxQueueID(the, fxID(the, "valueOf"), XS_DONT_ENUM_FLAG); fxAliasInstance(the, the->stack); mxBooleanPrototype = *the->stack; fxNewHostConstructor(the, fx_Boolean, 1); //fxAliasInstance(the, the->stack); the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG; *(--the->stack) = mxBooleanPrototype; fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG); fxQueueID(the, fxID(the, "Boolean"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); the->stack++; }
void fxNewInstanceOf(txMachine* the) { txSlot* aParent; if (the->stack->kind == XS_NULL_KIND) { txSlot* instance = fxNewSlot(the); instance->kind = XS_INSTANCE_KIND; instance->value.instance.garbage = C_NULL; instance->value.instance.prototype = C_NULL; the->stack->value.reference = instance; the->stack->kind = XS_REFERENCE_KIND; } else { fxToInstance(the, the->stack); aParent = fxGetInstance(the, the->stack); if (aParent->flag & XS_VALUE_FLAG) { switch (aParent->next->kind) { case XS_CALLBACK_KIND: case XS_CODE_KIND: fxNewFunctionInstance(the, XS_NO_ID); break; case XS_ARRAY_KIND: fxNewArrayInstance(the); break; case XS_STRING_KIND: case XS_STRING_X_KIND: fxNewStringInstance(the); break; case XS_BOOLEAN_KIND: fxNewBooleanInstance(the); break; case XS_NUMBER_KIND: fxNewNumberInstance(the); break; case XS_DATE_KIND: fxNewDateInstance(the); break; case XS_REGEXP_KIND: fxNewRegExpInstance(the); break; case XS_SYMBOL_KIND: fxNewSymbolInstance(the); break; case XS_HOST_KIND: fxNewHostInstance(the); break; case XS_PROMISE_KIND: fxNewPromiseInstance(the); break; case XS_PROXY_KIND: fxNewProxyInstance(the); break; case XS_MAP_KIND: fxNewMapInstance(the); break; case XS_SET_KIND: fxNewSetInstance(the); break; case XS_WEAK_MAP_KIND: fxNewWeakMapInstance(the); break; case XS_WEAK_SET_KIND: fxNewWeakSetInstance(the); break; case XS_ARRAY_BUFFER_KIND: fxNewArrayBufferInstance(the); break; case XS_DATA_VIEW_KIND: fxNewDataViewInstance(the); break; case XS_TYPED_ARRAY_KIND: fxNewTypedArrayInstance(the, aParent->next->value.typedArray); break; case XS_STACK_KIND: fxNewGeneratorInstance(the); break; default: mxSyntaxError("C: xsNewInstanceOf: invalid prototype"); break; } } else fxNewObjectInstance(the); } }