Search in sources :

Example 6 with Immutable

use of php.runtime.annotation.Runtime.Immutable in project jphp by jphp-compiler.

the class JsonFunctions method json_encode.

@Immutable
public static String json_encode(Memory memory, int options) {
    GsonBuilder builder;
    if (options != 0) {
        MemorySerializer serializer = new MemorySerializer();
        builder = JsonExtension.createGsonBuilder(serializer);
        if ((options & JsonConstants.JSON_PRETTY_PRINT) == JsonConstants.JSON_PRETTY_PRINT) {
            builder.setPrettyPrinting();
        }
        if ((options & JsonConstants.JSON_HEX_TAG) != JsonConstants.JSON_HEX_TAG) {
            builder.disableHtmlEscaping();
        }
        if ((options & JsonConstants.JSON_FORCE_OBJECT) == JsonConstants.JSON_FORCE_OBJECT) {
            serializer.setForceObject(true);
        }
        if ((options & JsonConstants.JSON_NUMERIC_CHECK) == JsonConstants.JSON_NUMERIC_CHECK) {
            serializer.setNumericCheck(true);
        }
    } else {
        builder = JsonExtension.DEFAULT_GSON_BUILDER;
    }
    Gson gson = builder.create();
    return gson.toJson(memory);
}
Also used : MemorySerializer(org.develnext.jphp.json.gson.MemorySerializer) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Immutable(php.runtime.annotation.Runtime.Immutable)

Example 7 with Immutable

use of php.runtime.annotation.Runtime.Immutable in project jphp by jphp-compiler.

the class MathFunctions method pow.

@Immutable
public static Memory pow(Memory base, Memory exp) {
    Memory realBase = base.toNumeric();
    Memory realExp = exp.toNumeric();
    if (realBase.type == Memory.Type.INT && realExp.type == Memory.Type.INT) {
        double result = Math.pow(realBase.toLong(), realExp.toLong());
        if (result > Long.MAX_VALUE) {
            return DoubleMemory.valueOf(result);
        }
        return LongMemory.valueOf((long) result);
    } else {
        return new DoubleMemory(Math.pow(base.toDouble(), exp.toDouble()));
    }
}
Also used : DoubleMemory(php.runtime.memory.DoubleMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) DoubleMemory(php.runtime.memory.DoubleMemory) Immutable(php.runtime.annotation.Runtime.Immutable)

Aggregations

Immutable (php.runtime.annotation.Runtime.Immutable)7 Memory (php.runtime.Memory)3 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 CRC32 (java.util.zip.CRC32)1 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 DoubleMemory (php.runtime.memory.DoubleMemory)1 LongMemory (php.runtime.memory.LongMemory)1