Search in sources :

Example 16 with StringMemory

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

the class InfoFunctions method get_defined_functions.

public static Memory get_defined_functions(Environment env) {
    ArrayMemory array = new ArrayMemory();
    ArrayMemory item = (ArrayMemory) array.refOfIndex("internal").assign(new ArrayMemory());
    for (FunctionEntity entity : env.getFunctions()) {
        if (entity.isInternal())
            item.add(new StringMemory(entity.getName()));
    }
    item = (ArrayMemory) array.refOfIndex("user").assign(new ArrayMemory());
    for (FunctionEntity entity : env.getLoadedFunctions().values()) {
        if (!entity.isInternal())
            item.add(new StringMemory(entity.getName()));
    }
    return array.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) FunctionEntity(php.runtime.reflection.FunctionEntity) StringMemory(php.runtime.memory.StringMemory)

Example 17 with StringMemory

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

the class InfoFunctions method var_export.

public static Memory var_export(Environment env, TraceInfo trace, @Runtime.Reference Memory value, boolean returned) {
    StringWriter writer = new StringWriter();
    VarExport printer = new VarExport(env, writer);
    printer.print(value);
    if (printer.isRecursionExists()) {
        env.warning(trace, "var_export does not handle circular references");
    }
    if (returned) {
        return new StringMemory(writer.toString());
    } else {
        env.echo(writer.toString());
        return Memory.TRUE;
    }
}
Also used : StringWriter(java.io.StringWriter) VarExport(php.runtime.memory.output.VarExport) StringMemory(php.runtime.memory.StringMemory)

Example 18 with StringMemory

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

the class LangFunctions method get_parent_class.

public static Memory get_parent_class(Environment env) {
    CallStackItem item = env.peekCall(0);
    if (item.clazz != null) {
        if (item.classEntity == null)
            item.classEntity = env.fetchClass(item.clazz, false);
        if (item.classEntity == null)
            return Memory.FALSE;
        else {
            MethodEntity method = item.classEntity.findMethod(item.function);
            if (method == null)
                return Memory.FALSE;
            ClassEntity parent = method.getClazz().getParent();
            return parent == null ? Memory.FALSE : new StringMemory(parent.getName());
        }
    }
    return Memory.FALSE;
}
Also used : CallStackItem(php.runtime.env.CallStackItem) StringMemory(php.runtime.memory.StringMemory)

Example 19 with StringMemory

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

the class FileObject method exception.

protected void exception(Environment env, String message, Object... args) {
    WrapIOException exception = new WrapIOException(env, env.fetchClass("php\\io\\IOException"));
    exception.__construct(env, new StringMemory(String.format(message, args)));
    env.__throwException(exception);
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Example 20 with StringMemory

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

the class FileObject method find.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory find(final Environment env, Memory... args) {
    if (args[0].isNull()) {
        return ArrayMemory.ofStrings(file.list()).toConstant();
    } else {
        final Invoker invoker = Invoker.valueOf(env, null, args[0]);
        if (invoker == null) {
            exception(env, "Invalid filter value, must be callable");
            return Memory.NULL;
        }
        final TraceInfo trace = env.trace();
        invoker.setTrace(trace);
        String[] result = file.list(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                FileObject o = new FileObject(env, __class__, dir);
                Memory[] args = new Memory[] { new ObjectMemory(o), new StringMemory(name) };
                return invoker.callNoThrow(args).toBoolean();
            }
        });
        return ArrayMemory.ofStrings(result);
    }
}
Also used : Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) TraceInfo(php.runtime.env.TraceInfo)

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