Skip to content
mwatts15 edited this page Nov 15, 2012 · 1 revision

Packages

Rationale

Packages are for defining types, symbols and functions that are not needed for basic crono functionality that are still a good idea to provide. Things like extended math operations, file I/O, network I/O, random number generation, etc; all these things would be better suited to being loaded individually by the loader since they aren't needed by all programs.

Implementation

Currently packages are implemented using the java reflection packages. All packages are java classes that inherit from the CronoPackage class. This abstract class has only three methods:

  1. Function[] functions()
  2. SymbolPair[] symbols()
  3. TypeId[] types() Each package must implement each method, though they can return null for any/all of them to indicate that the package does not export symbols of that type.

When crono first starts, it creates an instance of a URLClassLoader to use when loading packages. This URLClassLoader is pointed at the package subdirectory and any other directories specified in command line options (todo). When a package is to be loaded, the load method gets the class from that ClassLoader, attempts to create an instance of it, then calls the functions given above to get the types exported by the package and puts them into the environment.

Using packages from Crono

To use a package from crono, the class files for the package should be in the ./packages subdirectory. Then, in a crono program the user would include a line:

(load "package")

Where the string "package" would be the name of the package without any extension. The load function searches for the file given by the string and attempts to load it depending on the file name; if the file has an extension it first attempts to load it as a crono program, then a package if that fails. If the file has no extension it does the reverse; package first, crono source second.

Current Packages

Math.java: Addition of functions that wrap around all major java.lang.Math functions, as well as the symbols m_pi and m_e.

Future Packages

IO.java: Addition of a File type, as well as methods to read and write to/from files.

Random.java Addition of random number functions and types.

Complex.java Complex math types and functions.

Thread.java Wrapper types for threads and threading. Give a thread a lambda to execute, dispatch and wait on threads.

Clone this wiki locally