Search in sources :

Example 1 with StringMemory

use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.

the class BCMathFunctions method bcdiv.

public static Memory bcdiv(Environment env, Memory left, Memory right, int scale) {
    BigDecimal bd1 = toBigDecimal(left);
    BigDecimal bd2 = toBigDecimal(right);
    if (bd2.compareTo(BigDecimal.ZERO) == 0) {
        return Memory.NULL;
    }
    BigDecimal result;
    if (scale > 0)
        result = bd1.divide(bd2, scale + 2, RoundingMode.DOWN);
    else
        result = bd1.divide(bd2, 2, RoundingMode.DOWN);
    result = result.setScale(scale, RoundingMode.DOWN);
    return new StringMemory(result.toPlainString());
}
Also used : StringMemory(php.runtime.memory.StringMemory) BigDecimal(java.math.BigDecimal)

Example 2 with StringMemory

use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.

the class DateFunctions method microtime.

public static Memory microtime(boolean getAsFloat) {
    double now = System.currentTimeMillis() / 1000.0;
    int s = (int) now;
    return getAsFloat ? new DoubleMemory(now) : new StringMemory((Math.round((now - s) * 1000) / 1000) + " " + s);
}
Also used : StringMemory(php.runtime.memory.StringMemory) DoubleMemory(php.runtime.memory.DoubleMemory)

Example 3 with StringMemory

use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.

the class ReflectionFunction method setFunctionEntity.

public void setFunctionEntity(FunctionEntity functionEntity) {
    this.functionEntity = functionEntity;
    getProperties().put("name", new StringMemory(functionEntity.getName()));
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Example 4 with StringMemory

use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.

the class ReflectionMethod method setEntity.

public void setEntity(MethodEntity entity) {
    this.methodEntity = entity;
    getProperties().put("name", new StringMemory(entity.getName()));
    getProperties().put("class", new StringMemory(entity.getClazz().getName()));
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Example 5 with StringMemory

use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.

the class ObjectInvokeHelper method invokeParentMethod.

public static Memory invokeParentMethod(Memory object, String methodName, String methodLowerName, Environment env, TraceInfo trace, Memory[] args) throws Throwable {
    Memory[] passed = null;
    boolean doublePop = false;
    if (object.isNull()) {
        ClassEntity parent = env.__getParentClass(trace);
        return InvokeHelper.callStatic(env, trace, parent.getLowerName(), methodLowerName, parent.getName(), methodName, args, null, 0);
    }
    IObject iObject = ((ObjectMemory) object).value;
    ClassEntity childClazz = iObject.getReflection();
    ClassEntity clazz = env.getLastClassOnStack().getParent();
    MethodEntity method;
    if (clazz == null) {
        env.error(trace, "Cannot access parent:: when current class scope has no parent");
        return Memory.NULL;
    }
    if (methodName == null) {
        method = childClazz.methodMagicInvoke != null ? childClazz.methodMagicInvoke : clazz.methodMagicInvoke;
    } else {
        method = clazz.findMethod(methodLowerName);
        if (method == null && ((method = childClazz.methodMagicCall != null ? childClazz.methodMagicCall : clazz.methodMagicCall) != null)) {
            passed = new Memory[] { new StringMemory(methodName), ArrayMemory.of(args) };
            doublePop = true;
        }
    }
    String className = clazz.getName();
    if (method == null) {
        if (methodName == null)
            methodName = "__invoke";
        env.error(trace, ErrorType.E_ERROR, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(className + "::" + methodName));
        return Memory.NULL;
    }
    InvokeHelper.checkAccess(env, trace, method);
    if (passed == null) {
        passed = InvokeHelper.makeArguments(env, args, method.getParameters(), className, methodName, trace);
    }
    Memory result = method.getImmutableResult();
    if (result != null)
        return result;
    try {
        if (trace != null) {
            env.pushCall(trace, iObject, args, methodName, method.getClazz().getName(), className);
            if (doublePop)
                env.pushCall(trace, iObject, passed, method.getName(), method.getClazz().getName(), className);
        }
        result = method.invokeDynamic(iObject, env, passed);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new CriticalException("Unable to call parent:: method " + className + "::" + methodName + "(), error = " + e.getMessage());
    } finally {
        if (trace != null) {
            env.popCall();
            if (doublePop)
                env.popCall();
        }
    }
    return result;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) MethodEntity(php.runtime.reflection.MethodEntity) StringMemory(php.runtime.memory.StringMemory) CriticalException(php.runtime.exceptions.CriticalException)

Aggregations

StringMemory (php.runtime.memory.StringMemory)47 ArrayMemory (php.runtime.memory.ArrayMemory)14 Memory (php.runtime.Memory)11 ObjectMemory (php.runtime.memory.ObjectMemory)8 ReferenceMemory (php.runtime.memory.ReferenceMemory)7 BigDecimal (java.math.BigDecimal)5 Invoker (php.runtime.invoke.Invoker)4 ClassEntity (php.runtime.reflection.ClassEntity)4 TraceInfo (php.runtime.env.TraceInfo)3 IObject (php.runtime.lang.IObject)3 LongMemory (php.runtime.memory.LongMemory)3 StringWriter (java.io.StringWriter)2 ComponentProperties (org.develnext.jphp.swing.ComponentProperties)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 Signature (php.runtime.annotation.Reflection.Signature)2 CallStackItem (php.runtime.env.CallStackItem)2 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)2 CriticalException (php.runtime.exceptions.CriticalException)2 MethodEntity (php.runtime.reflection.MethodEntity)2 BigInteger (java.math.BigInteger)1