Search in sources :

Example 26 with StringMemory

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

the class Launcher method readConfig.

protected void readConfig() {
    this.config = new Properties();
    this.compileScope.configuration = new HashMap<>();
    String externalConfig = System.getProperty("jphp.config");
    if (externalConfig != null) {
        try {
            FileInputStream inStream = new FileInputStream(externalConfig);
            config.load(inStream);
            inStream.close();
            for (String name : config.stringPropertyNames()) {
                compileScope.configuration.put(name, new StringMemory(config.getProperty(name)));
            }
        } catch (IOException e) {
            throw new LaunchException("Unable to load the config -Djphp.config=" + externalConfig);
        }
    }
    InputStream resource;
    resource = getResource(pathToConf);
    if (resource != null) {
        try {
            config.load(resource);
            for (String name : config.stringPropertyNames()) {
                compileScope.configuration.put(name, new StringMemory(config.getProperty(name)));
            }
            isDebug = Startup.isDebug();
            compileScope.setDebugMode(isDebug);
            compileScope.setLangMode(LangMode.valueOf(getConfigValue("env.langMode", LangMode.MODERN.name()).toString().toUpperCase()));
        } catch (IOException e) {
            throw new LaunchException(e.getMessage());
        }
    }
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Example 27 with StringMemory

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

the class Launcher method run.

public void run(boolean mustBootstrap, boolean disableExtensions) throws Throwable {
    readConfig();
    if (!disableExtensions) {
        initExtensions();
    }
    if (isDebug()) {
        if (compileScope.getTickHandler() == null) {
            throw new LaunchException("Cannot find a debugger, please add the jphp-debugger dependency");
        }
    }
    if (Startup.isShowInitDelay()) {
        long t = System.currentTimeMillis() - startTime;
        Startup.trace("Startup time = " + t + "ms");
    }
    String file = config.getProperty("bootstrap.file", "JPHP-INF/.bootstrap.php");
    String classLoader = config.getProperty("env.classLoader", ReflectionUtils.getClassName(WrapClassLoader.WrapLauncherClassLoader.class));
    if (classLoader != null && !(classLoader.isEmpty())) {
        ClassEntity classLoaderEntity = environment.fetchClass(classLoader);
        if (classLoaderEntity == null) {
            throw new LaunchException("Class loader class is not found: " + classLoader);
        }
        WrapClassLoader loader = classLoaderEntity.newObject(environment, TraceInfo.UNKNOWN, true);
        environment.invokeMethod(loader, "register", Memory.TRUE);
    }
    if (file != null && !file.isEmpty()) {
        try {
            ModuleEntity bootstrap = loadFrom(file);
            if (bootstrap == null) {
                throw new IOException();
            }
            beforeIncludeBootstrap();
            if (new StringMemory(config.getProperty("bootstrap.showBytecode", "")).toBoolean()) {
                ModuleOpcodePrinter moduleOpcodePrinter = new ModuleOpcodePrinter(bootstrap);
                System.out.println(moduleOpcodePrinter.toString());
            }
            initModule(bootstrap);
            ArrayMemory argv = ArrayMemory.ofStrings(this.args);
            argv.unshift(Memory.NULL);
            environment.getGlobals().put("argv", argv);
            environment.getGlobals().put("argc", LongMemory.valueOf(argv.size()));
            environment.pushCall(new CallStackItem(new TraceInfo(bootstrap.getName(), -1, -1)));
            try {
                bootstrap.includeNoThrow(environment);
            } finally {
                afterIncludeBootstrap();
                environment.popCall();
                compileScope.triggerProgramShutdown(environment);
                if (StringMemory.valueOf(config.getProperty("env.doFinal", "1")).toBoolean()) {
                    environment.doFinal();
                }
            }
        } catch (IOException e) {
            throw new LaunchException("Cannot find '" + file + "' resource for `bootstrap.file` option");
        }
    } else if (mustBootstrap)
        throw new LaunchException("Please set value of the `bootstrap.file` option in the launcher.conf file");
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) WrapClassLoader(php.runtime.ext.core.classes.WrapClassLoader) ModuleEntity(php.runtime.reflection.ModuleEntity) ModuleOpcodePrinter(org.develnext.jphp.core.opcode.ModuleOpcodePrinter) ArrayMemory(php.runtime.memory.ArrayMemory) StringMemory(php.runtime.memory.StringMemory)

Example 28 with StringMemory

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

the class ReflectionClass method setEntity.

public ReflectionClass setEntity(ClassEntity entity) {
    this.entity = entity;
    getProperties().put("name", new StringMemory(entity.getName()));
    return this;
}
Also used : StringMemory(php.runtime.memory.StringMemory)

Example 29 with StringMemory

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

the class ReflectionExtension method setExtension.

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

Example 30 with StringMemory

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

the class FileObject method findFiles.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory findFiles(final Environment env, Memory... args) {
    File[] result;
    if (args[0].isNull()) {
        result = file.listFiles();
    } 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);
        result = file.listFiles(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();
            }
        });
    }
    ArrayMemory arr = new ArrayMemory();
    if (result != null) {
        for (File e : result) {
            arr.add(new ObjectMemory(new FileObject(env, __class__, e)));
        }
    }
    return arr.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) 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