Search in sources :

Example 66 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class SimpleExpressionTest method testAssignDiv.

@Test
public void testAssignDiv() {
    Memory memory = run("$x = 10; $x /= 2; return $x", false);
    Assert.assertEquals(5, memory.toLong());
}
Also used : Memory(php.runtime.Memory) Test(org.junit.Test)

Example 67 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class SimpleExpressionTest method testAssignMod.

@Test
public void testAssignMod() {
    Memory memory = run("$x = 10; $x %= 3; return $x", false);
    Assert.assertEquals(1, memory.toLong());
}
Also used : Memory(php.runtime.Memory) Test(org.junit.Test)

Example 68 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class SimpleExpressionTest method testOr.

@Test
public void testOr() {
    Memory memory = runDynamic("$x || true");
    Assert.assertEquals(true, memory.toBoolean());
    memory = runDynamic("$x or true");
    Assert.assertEquals(true, memory.toBoolean());
}
Also used : Memory(php.runtime.Memory) Test(org.junit.Test)

Example 69 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class SimpleExpressionTest method testBug119.

@Test
public void testBug119() {
    Memory r = runDynamic("$val = 3; $t = '2'; return '1' . $t . (int)$val;", false);
    Assert.assertEquals("123", r.toString());
}
Also used : Memory(php.runtime.Memory) Test(org.junit.Test)

Example 70 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class SPLFunctions method iterator_apply.

public static long iterator_apply(Environment env, TraceInfo trace, Memory object, Memory callback, Memory args) throws Throwable {
    if (expectingImplement(env, trace, 1, object, Traversable.class)) {
        Invoker invoker = expectingCallback(env, trace, 2, callback);
        if (invoker == null)
            return 0;
        if (args != null && !expecting(env, trace, 3, args, Memory.Type.ARRAY)) {
            return 0;
        }
        ForeachIterator iterator = object.getNewIterator(env, false, false);
        Memory[] values = args == null ? null : args.toValue(ArrayMemory.class).values(true);
        int i = 0;
        while (iterator.next()) {
            if (!invoker.call(values).toBoolean())
                break;
            i++;
        }
        return i;
    } else
        return 0;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory)

Aggregations

Memory (php.runtime.Memory)346 Test (org.junit.Test)124 ArrayMemory (php.runtime.memory.ArrayMemory)122 ObjectMemory (php.runtime.memory.ObjectMemory)75 LongMemory (php.runtime.memory.LongMemory)58 StringMemory (php.runtime.memory.StringMemory)58 ForeachIterator (php.runtime.lang.ForeachIterator)47 ReferenceMemory (php.runtime.memory.ReferenceMemory)40 KeyValueMemory (php.runtime.memory.KeyValueMemory)25 Invoker (php.runtime.invoke.Invoker)21 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)21 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)21 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)21 Environment (php.runtime.env.Environment)20 IObject (php.runtime.lang.IObject)19 UndefinedMemory (php.runtime.memory.helper.UndefinedMemory)16 ClassEntity (php.runtime.reflection.ClassEntity)16 TraceInfo (php.runtime.env.TraceInfo)12 File (java.io.File)7 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)7