Java Code Examples for jdk.nashorn.internal.codegen.types.Type#NUMBER

The following examples show how to use jdk.nashorn.internal.codegen.types.Type#NUMBER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeGeneratorLexicalContext.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static Type getTypeForSlotDescriptor(final char typeDesc) {
    // Recognizing both lowercase and uppercase as we're using both to signify symbol boundaries; see
    // MethodEmitter.markSymbolBoundariesInLvarTypesDescriptor().
    switch (typeDesc) {
        case 'I':
        case 'i':
            return Type.INT;
        case 'J':
        case 'j':
            return Type.LONG;
        case 'D':
        case 'd':
            return Type.NUMBER;
        case 'A':
        case 'a':
            return Type.OBJECT;
        case 'U':
        case 'u':
            return Type.UNKNOWN;
        default:
            throw new AssertionError();
    }
}
 
Example 2
Source File: CodeGeneratorLexicalContext.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static Type getTypeForSlotDescriptor(final char typeDesc) {
    // Recognizing both lowercase and uppercase as we're using both to signify symbol boundaries; see
    // MethodEmitter.markSymbolBoundariesInLvarTypesDescriptor().
    switch (typeDesc) {
        case 'I':
        case 'i':
            return Type.INT;
        case 'J':
        case 'j':
            return Type.LONG;
        case 'D':
        case 'd':
            return Type.NUMBER;
        case 'A':
        case 'a':
            return Type.OBJECT;
        case 'U':
        case 'u':
            return Type.UNKNOWN;
        default:
            throw new AssertionError();
    }
}
 
Example 3
Source File: OptimisticReturnFilters.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static int ensureInt(final double arg, final int programPoint) {
    if (JSType.isStrictlyRepresentableAsInt(arg)) {
        return (int)arg;
    }
    throw new UnwarrantedOptimismException(arg, programPoint, Type.NUMBER);
}
 
Example 4
Source File: OptimisticReturnFilters.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private static int ensureInt(final double arg, final int programPoint) {
    if (JSType.isStrictlyRepresentableAsInt(arg)) {
        return (int)arg;
    }
    throw new UnwarrantedOptimismException(arg, programPoint, Type.NUMBER);
}
 
Example 5
Source File: LiteralNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private boolean presetsMatchElementType() {
    if (elementType == Type.INT) {
        return presets instanceof int[];
    } else if (elementType == Type.LONG) {
        return presets instanceof long[];
    } else if (elementType == Type.NUMBER) {
        return presets instanceof double[];
    } else {
        return presets instanceof Object[];
    }
}
 
Example 6
Source File: LiteralNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean presetsMatchElementType() {
    if (elementType == Type.INT) {
        return presets instanceof int[];
    } else if (elementType == Type.NUMBER) {
        return presets instanceof double[];
    } else {
        return presets instanceof Object[];
    }
}
 
Example 7
Source File: LiteralNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean presetsMatchElementType() {
    if (elementType == Type.INT) {
        return presets instanceof int[];
    } else if (elementType == Type.NUMBER) {
        return presets instanceof double[];
    } else {
        return presets instanceof Object[];
    }
}
 
Example 8
Source File: BinaryNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the widest possible type for this operation. This is used for compile time
 * static type inference
 *
 * @return Type
 */
@Override
public Type getWidestOperationType() {
    switch (tokenType()) {
    case SHR:
    case ASSIGN_SHR:
        return Type.LONG;
    case ASSIGN_SAR:
    case ASSIGN_SHL:
    case BIT_AND:
    case BIT_OR:
    case BIT_XOR:
    case ASSIGN_BIT_AND:
    case ASSIGN_BIT_OR:
    case ASSIGN_BIT_XOR:
    case SAR:
    case SHL:
        return Type.INT;
    case DIV:
    case MOD:
    case MUL:
    case SUB:
    case ASSIGN_DIV:
    case ASSIGN_MOD:
    case ASSIGN_MUL:
    case ASSIGN_SUB:
        return Type.NUMBER;
    default:
        return Type.OBJECT;
    }
}
 
Example 9
Source File: BinaryNode.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static Type undefinedToNumber(final Type type) {
    return type == Type.UNDEFINED ? Type.NUMBER : type;
}
 
Example 10
Source File: SharedScopeCall.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the method that implements the scope get or call.
 */
protected void generateScopeCall() {
    final ClassEmitter classEmitter = compileUnit.getClassEmitter();
    final EnumSet<ClassEmitter.Flag> methodFlags = EnumSet.of(ClassEmitter.Flag.STATIC);

    // This method expects two fixed parameters in addition to any parameters that may be
    // passed on to the function: A ScriptObject representing the caller's current scope object,
    // and an int specifying the distance to the target scope containing the symbol we want to
    // access, or -1 if this is not known at compile time (e.g. because of a "with" or "eval").

    final MethodEmitter method = classEmitter.method(methodFlags, methodName, getStaticSignature());
    method.begin();

    // Load correct scope by calling getProto() on the scope argument as often as specified
    // by the second argument.
    final Label parentLoopStart = new Label("parent_loop_start");
    final Label parentLoopDone  = new Label("parent_loop_done");
    method.load(Type.OBJECT, 0);
    method.label(parentLoopStart);
    method.load(Type.INT, 1);
    method.iinc(1, -1);
    method.ifle(parentLoopDone);
    method.invoke(ScriptObject.GET_PROTO);
    method._goto(parentLoopStart);
    method.label(parentLoopDone);

    method.dynamicGet(valueType, symbol.getName(), flags, isCall);

    // If this is a get we're done, otherwise call the value as function.
    if (isCall) {
        method.convert(Type.OBJECT);
        // ScriptFunction will see CALLSITE_SCOPE and will bind scope accordingly.
        method.loadNull();
        int slot = 2;
        for (final Type type : paramTypes) {
            method.load(type, slot++);
            if (type == Type.NUMBER || type == Type.LONG) {
                slot++;
            }
        }
        method.dynamicCall(returnType, 2 + paramTypes.length, flags);
    }

    method._return(returnType);
    method.end();
}
 
Example 11
Source File: UnaryNode.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getWidestOperationType() {
    return isAssignment() ? Type.NUMBER : Type.OBJECT;
}
 
Example 12
Source File: BinaryNode.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static Type undefinedToNumber(final Type type) {
    return type == Type.UNDEFINED ? Type.NUMBER : type;
}
 
Example 13
Source File: BinaryNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static Type undefinedToNumber(final Type type) {
    return type == Type.UNDEFINED ? Type.NUMBER : type;
}
 
Example 14
Source File: UnaryNode.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getWidestOperationType() {
    return isAssignment() ? Type.NUMBER : Type.OBJECT;
}
 
Example 15
Source File: UnwarrantedOptimismException.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create an {@code UnwarrantedOptimismException} with the given return value and program point, narrowing
 * the type to {@code number} if the value is a float or a long that can be represented as double.
 *
 * @param returnValue the return value
 * @param programPoint the program point
 * @return the exception
 */
public static UnwarrantedOptimismException createNarrowest(final Object returnValue, final int programPoint) {
    if (returnValue instanceof Float
            || (returnValue instanceof Long && JSType.isRepresentableAsDouble((Long) returnValue))) {
        return new UnwarrantedOptimismException(((Number) returnValue).doubleValue(), programPoint, Type.NUMBER);
    }
    return new UnwarrantedOptimismException(returnValue, programPoint);
}
 
Example 16
Source File: UnwarrantedOptimismException.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create an {@code UnwarrantedOptimismException} with the given return value and program point, narrowing
 * the type to {@code number} if the value is a float or a long that can be represented as double.
 *
 * @param returnValue the return value
 * @param programPoint the program point
 * @return the exception
 */
public static UnwarrantedOptimismException createNarrowest(final Object returnValue, final int programPoint) {
    if (returnValue instanceof Float
            || (returnValue instanceof Long && JSType.isRepresentableAsDouble((Long) returnValue))) {
        return new UnwarrantedOptimismException(((Number) returnValue).doubleValue(), programPoint, Type.NUMBER);
    }
    return new UnwarrantedOptimismException(returnValue, programPoint);
}
 
Example 17
Source File: UnwarrantedOptimismException.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create an {@code UnwarrantedOptimismException} with the given return value and program point, narrowing
 * the type to {@code number} if the value is a float or a long that can be represented as double.
 *
 * @param returnValue the return value
 * @param programPoint the program point
 * @return the exception
 */
public static UnwarrantedOptimismException createNarrowest(final Object returnValue, final int programPoint) {
    if (returnValue instanceof Float
            || (returnValue instanceof Long && JSType.isRepresentableAsDouble((Long) returnValue))) {
        return new UnwarrantedOptimismException(((Number) returnValue).doubleValue(), programPoint, Type.NUMBER);
    }
    return new UnwarrantedOptimismException(returnValue, programPoint);
}
 
Example 18
Source File: UnwarrantedOptimismException.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create an {@code UnwarrantedOptimismException} with the given return value and program point, narrowing
 * the type to {@code number} if the value is a float or a long that can be represented as double.
 *
 * @param returnValue the return value
 * @param programPoint the program point
 * @return the exception
 */
public static UnwarrantedOptimismException createNarrowest(final Object returnValue, final int programPoint) {
    if (returnValue instanceof Float
            || (returnValue instanceof Long && JSType.isRepresentableAsDouble((Long) returnValue))) {
        return new UnwarrantedOptimismException(((Number) returnValue).doubleValue(), programPoint, Type.NUMBER);
    }
    return new UnwarrantedOptimismException(returnValue, programPoint);
}
 
Example 19
Source File: Attr.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the type that arithmetic ops should use. Until we have implemented better type
 * analysis (range based) or overflow checks that are fast enough for int arithmetic,
 * this is the number type
 * @return the arithetic type
 */
private static Type arithType() {
    return Compiler.shouldUseIntegerArithmetic() ? Type.INT : Type.NUMBER;
}
 
Example 20
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the type that arithmetic ops should use. Until we have implemented better type
 * analysis (range based) or overflow checks that are fast enough for int arithmetic,
 * this is the number type
 * @return the arithetic type
 */
private static Type arithType() {
    return Compiler.shouldUseIntegerArithmetic() ? Type.INT : Type.NUMBER;
}