Search in sources :

Example 1 with Library

use of dyvilx.tools.compiler.library.Library in project Dyvil by Dyvil.

the class Package method resolvePackage.

public Package resolvePackage(String name) {
    final Package pack = this.subPackages.get(name);
    if (pack != null) {
        return pack;
    }
    String internal = this.internalName + name;
    for (Library library : rootPackage.compiler.config.libraries) {
        if (library.isSubPackage(internal)) {
            return this.createSubPackage(name);
        }
    }
    return null;
}
Also used : Library(dyvilx.tools.compiler.library.Library)

Example 2 with Library

use of dyvilx.tools.compiler.library.Library in project Dyvil by Dyvil.

the class LibraryCommand method execute.

@Override
public void execute(DyvilREPL repl, String argument) {
    if (argument == null) {
        repl.getErrorOutput().println(I18n.get("command.library.missing", this.getUsage()));
        return;
    }
    final File path = new File(argument);
    try {
        final Library library = Library.load(path);
        library.loadLibrary();
        repl.getCompiler().config.libraries.add(library);
        repl.getOutput().println(I18n.get("command.library.success", library));
    } catch (FileNotFoundException ex) {
        repl.getErrorOutput().println(ex);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Library(dyvilx.tools.compiler.library.Library) File(java.io.File)

Example 3 with Library

use of dyvilx.tools.compiler.library.Library in project Dyvil by Dyvil.

the class TestThread method getCommand.

public String[] getCommand() {
    final List<Library> libraries = this.compiler.config.libraries;
    StringBuilder classpath = new StringBuilder();
    classpath.append(this.compiler.config.getOutputDir());
    for (Library library : libraries) {
        classpath.append(':').append(library.getFile());
    }
    final List<String> command = new ArrayList<>();
    command.add("java");
    command.add("-cp");
    command.add(classpath.toString());
    command.add(this.compiler.config.getMainType());
    command.addAll(this.compiler.config.getMainArgs());
    return command.toArray(String.class);
}
Also used : ArrayList(dyvil.collection.mutable.ArrayList) Library(dyvilx.tools.compiler.library.Library)

Example 4 with Library

use of dyvilx.tools.compiler.library.Library in project Dyvil by Dyvil.

the class DyvilCompiler method loadLibraries.

public void loadLibraries() {
    final List<Library> libraries = this.config.libraries;
    // Make sure to add the dyvil and java libraries at the end
    libraries.add(Library.dyvilLibrary);
    libraries.add(Library.javaLibrary);
    final int libs = libraries.size();
    final long startTime = System.nanoTime();
    // Loads libraries
    for (Library library : libraries) {
        library.loadLibrary();
    }
    Package.initRoot(this);
    final long endTime = System.nanoTime();
    this.log(I18n.get("library.found", libs == 1 ? I18n.get("libraries.1") : I18n.get("libraries.n", libs), Util.toTime(endTime - startTime)));
}
Also used : Library(dyvilx.tools.compiler.library.Library)

Example 5 with Library

use of dyvilx.tools.compiler.library.Library in project Dyvil by Dyvil.

the class Package method loadClass.

public static IClass loadClass(String fileName, Name name, IClassConsumer consumer) {
    final DyvilCompiler compiler = rootPackage.compiler;
    for (Library library : compiler.config.libraries) {
        final InputStream inputStream = library.getInputStream(fileName);
        if (inputStream != null) {
            final ExternalClass externalClass = new ExternalClass(name);
            consumer.addClass(externalClass);
            return ClassReader.loadClass(compiler, externalClass, inputStream);
        }
    }
    return null;
}
Also used : InputStream(java.io.InputStream) DyvilCompiler(dyvilx.tools.compiler.DyvilCompiler) Library(dyvilx.tools.compiler.library.Library) ExternalClass(dyvilx.tools.compiler.ast.external.ExternalClass)

Aggregations

Library (dyvilx.tools.compiler.library.Library)5 ArrayList (dyvil.collection.mutable.ArrayList)1 DyvilCompiler (dyvilx.tools.compiler.DyvilCompiler)1 ExternalClass (dyvilx.tools.compiler.ast.external.ExternalClass)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1