Ejemplo n.º 1
0
void fxBuildNumber(txMachine* the)
{
	mxPush(mxGlobal);

	mxPush(mxObjectPrototype);
	fxNewNumberInstance(the);
	fxNewHostFunction(the, fx_Number_toExponential, 1);
	fxQueueID(the, fxID(the, "toExponential"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toFixed, 1);
	fxQueueID(the, fxID(the, "toFixed"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toString, 0);
	fxQueueID(the, fxID(the, "toLocaleString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toPrecision, 1);
	fxQueueID(the, fxID(the, "toPrecision"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_toString, 1);
	fxQueueID(the, fxID(the, "toString"), XS_DONT_ENUM_FLAG);
	fxNewHostFunction(the, fx_Number_valueOf, 0);
	fxQueueID(the, fxID(the, "valueOf"), XS_DONT_ENUM_FLAG);
	
	fxAliasInstance(the, the->stack);
	mxNumberPrototype = *the->stack;
	fxNewHostConstructor(the, fx_Number, 1);
	mxPushNumber(C_DBL_MAX);
	fxQueueID(the, fxID(the, "MAX_VALUE"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(C_DBL_MIN);
	fxQueueID(the, fxID(the, "MIN_VALUE"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(C_NAN);
	fxQueueID(the, fxID(the, "NaN"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(-C_INFINITY);
	fxQueueID(the, fxID(the, "NEGATIVE_INFINITY"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	mxPushNumber(C_INFINITY);
	fxQueueID(the, fxID(the, "POSITIVE_INFINITY"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
	//fxAliasInstance(the, the->stack);
	the->stack->value.reference->next->next->next->flag |= XS_DONT_SET_FLAG;
	 *(--the->stack) = mxNumberPrototype;
	fxPutID(the, fxID(the, "constructor"), XS_DONT_ENUM_FLAG, XS_DONT_ENUM_FLAG);
	fxQueueID(the, fxID(the, "Number"), XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
		
	the->stack++;
}
Ejemplo n.º 2
0
void fxParseJSONValue(txMachine* the, txJSONParser* theParser)
{
	switch (theParser->token) {
	case XS_JSON_TOKEN_FALSE:
		mxPushBoolean(0);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_TRUE:
		mxPushBoolean(1);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_NULL:
		mxPushNull();
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_INTEGER:
		mxPushInteger(theParser->integer);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_NUMBER:
		mxPushNumber(theParser->number);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_STRING:
		mxPushString(theParser->string->value.string);
		fxGetNextJSONToken(the, theParser);
		break;
	case XS_JSON_TOKEN_LEFT_BRACE:
		fxParseJSONObject(the, theParser);
		break;
	case XS_JSON_TOKEN_LEFT_BRACKET:
		fxParseJSONArray(the, theParser);
		break;
	default:
		mxPushUndefined();
		mxSyntaxError("invalid value");
		break;
	}
}