ssc/readme.md

82 lines
3.9 KiB
Markdown
Raw Normal View History

2015-12-07 15:27:47 +09:00
# ssc
2016-02-23 12:21:30 +09:00
![SunScript ST3 syntax preview](http://i.imgur.com/YHChKwd.png)
## Summary
2015-12-07 15:27:47 +09:00
_ssc_ is a work-in-progress compiler for SunScript.
It supports all of the byte-code functionality of Super Mario Sunshine's SPC interpreter.
The compiler can compile to the SPC binary format (.sb files) used by Super Mario Sunshine, allowing for completely new and custom scripts.
2015-12-07 15:27:47 +09:00
This program utilizes the [Grammatica](http://grammatica.percederberg.net/) library to generate an LL(k) parser using a grammar syntax file.
2015-12-07 15:27:47 +09:00
## Usage
2015-12-07 15:27:47 +09:00
To use _ssc_, create an instance of the `sunCompiler` class.
2015-12-19 09:52:38 +09:00
Use the `sunCompiler.Compile` method or any of its overloads to compile a script:
2015-12-07 15:27:47 +09:00
|Parameter|Description|
|---------|-----------|
|`name`|The name of the main script to compile. This is passed to the import resolver.|
|`output`|The output stream into which the compiled binary file will be written.|
2016-02-08 06:29:03 +09:00
|`binary`|The custom binary formatter to use for output. If not specified, the default SPC binary format will be used.|
|`resolver`|An instance of the import resolver to use. If not specified, `sunImportResolver.Default` will be used.|
2015-12-07 15:27:47 +09:00
2015-12-29 02:34:19 +09:00
_ssc_ by default resolves imports by loading files on disk (see [language.md](language.md) for more information).
2015-12-09 23:48:53 +09:00
To use a custom import resolver, create a new class inheriting from `sunImportResolver` and pass an instance of it to the `sunCompiler.Compile` method.
2015-12-07 15:27:47 +09:00
The result of compilation will be returned in a `sunCompilerResults` instance.
Use the various properties on this type to gather the information of the compilation:
2015-12-07 15:27:47 +09:00
|Property|Description|
|--------|-----------|
2015-12-29 02:34:19 +09:00
|`Success`|Whether the script was compiled successfully. If not, the `Error` property will be non-`null`.|
|`Error`|The fatal error which occured during compilation. If compilation was successful, this will be `null`.|
|`CompileTime`|The time it took to compile, measured as a `TimeSpan` instance.|
|`Data`|An array containing the data-table entries.|
|`Symbols`|An array containing the symbol-table entries.|
2015-12-07 15:27:47 +09:00
If the error is of the type `sunSourceException`, you can cast and retrieve the script name, line, and column of the error.
2015-12-07 15:27:47 +09:00
2015-12-13 08:04:49 +09:00
## Compiling
2016-02-13 12:53:32 +09:00
### Dependencies
There are several dependencies when building _ssc_.
All dependencies must be placed in the _lib-dir_ folder (see below), unless stated otherwise.
|Dependency|Notes|
|----------|-----|
|[arookas library](https://github.com/arookas/arookas)|Preferably, the library should be built in the same configuration as _ssc_ (e.g. debug, release).|
|[Grammatica 1.6](http://grammatica.percederberg.net/)|Already included in the repository.|
_**Note:** A Java runtime compatible with JDK 1.5 is required for generating the Grammatica parser classes during compilation.
For more information, see Grammatica's official [installation documentation](http://grammatica.percederberg.net/doc/release/install.html)._
### premake
This repository contains a [premake5](https://premake.github.io/) [configuration file](premake5.lua).
2015-12-13 08:04:49 +09:00
The script generates a solution with the following projects:
- **ssc**, the base _ssc_ API library
2016-01-10 10:08:37 +09:00
- **frontend**, a basic command-line frontend
2015-12-31 12:29:02 +09:00
- **sbdump**, a tool which dumps disassembly and other information on compiled SPC binaries
2015-12-13 08:04:49 +09:00
2016-02-13 12:53:32 +09:00
After setting up the dependencies, simply run the script through premake5 and build the resulting solution.
There are also options which are able to be configured via the premake5 command line:
2015-12-29 02:34:19 +09:00
|Option|Description|
|------|-----------|
2016-02-13 12:39:25 +09:00
|lib-dir|Sets the path to the dependencies. Defaults to the _lib/_ folder.|
2016-02-14 08:15:18 +09:00
|clean-functions|Compiles only used functions.|
|clean-symbols|Cleans symbol table of unused symbols.|
2015-12-13 08:04:49 +09:00
## Language
2015-12-07 15:27:47 +09:00
2015-12-13 08:13:27 +09:00
For more information on the SunScript language and its syntax, see [language.md](language.md).
## Extending the compiler
_ssc_ is designed to be extensible, allowing for custom output formats and import resolvers.
For more information on extending _ssc_, see [extensions.md](extensions.md).