Quick Start
Welcome to a brief introduction to the Fortress programming language, this guide will help you setup a Fortress programming environment under your operating system of choice (at the moment Fortress runs on top of the Java Virtual Machine) and walk you through the creation and compilation of a HelloWorld example. Once you have a running environment you can make the learning process much smoother by experimenting with the example code presented in the tutorials.
Installation
General installation steps (The reference interpreter for the Fortress language requires Java 1.5 (or better) to run and Ant 1.6.5 (or better) to build.). First steps get the JDK, get fortress directly from svn (subversion) or use zipped source. Checkout the latest source code using subversion:
svn checkout https://projectfortress.sun.com/svn/Community/trunk PFC
Follow the instructions in file PFC/README.txt for setting up your environment and running Fortress programs. In order to run the "fortress" script from an arbitrary directory, you need to put the directory PFC/bin on your path and to set the environment variable FORTRESS_HOME.
Example: HelloWorld.fss
component HelloWorld
export Executable
run(args:String...):() = do
println("Hello, world!" )
end
end
Notice there is no main() method. similar to java threads run() method, here run(args:String...):() is the entry point to a component.
Instruction for MS Windows
1. Create a Fortress directory to contain your Fortress code and the main project.
2. Use the subversion command shown above to checkout the entire project. You can checkout the project from either a command-line tool, or use one of the Subversion GUI clients such as TortoiseSVN.
3. Make sure you have installed Apache Ant.
4. Define the following three environment variables. If you need help editing the environment variables, check the Microsoft support site.
- FORTRESS_HOME - the path to the Fortress directory you have just created.
- ANT_HOME - the path to your ant install.
- JAVA_HOME - the path to your Java JDK install.
5. Check your %PATH% environment variable. Make sure that %ANT_HOME%\bin, %JAVA_HOME%\bin, and %FORTRESS_HOME%\bin are all present in your path.
6. Open up a command-line prompt (Go to "Run" and then type in "cmd" and hit OK). Change directory to the fortress\ProjectFortress? directory. Run the command "ant". You will see a list of options that the build file accepts. Each option executes a different portion of the build process. In order to compile the interpreter, run "ant compile" in the fortress directory.
7. Run the command "fortress.bat hello.fss".
K:\mastri\fortress\ProjectFortress>fortress.bat hello.fss K:\mastri\fortress\ProjectFortress>java -cp "build;third_party/junit/junit.jar;t hird_party/xtc/xtc.jar;third_party/jsr166y/jsr166y.jar;third_party/plt/plt.jar" com.sun.fortress.interpreter.drivers.fs hello.fss Parsing hello.fss: 10716 milliseconds ... ... ... Hello, World! Program execution: 53896 milliseconds K:\mastri\fortress\ProjectFortress>
Instruction for Linux
I followed these steps to checkout and build the Fortress project.
1. I created a Fortress directory to contain my Fortress code and the main project.
2. Use the subversion command shown above to checkout the entire project. A new directory named PFC is created under the current directory.
3. Use cd PFC/ProjectFortress to move to the primary directory.
4. Use ./ant to run a default compile on the entire source.
The default ant installation on some Linux systems fail with the ant script delivered with Fortress; 64 bit Fedora-7 for example. Although there are complicated ways to avoid the issues, simply using ant rather than ./ant works as expected. Most problems while compiling the code are related to missing jar files, incorrect classpath, or missing optional ant tasks. For example, if only the JRE is installed rather than the SDK, tools.jar will be missing.
The Fortress build.xml file uses the depend optional ant task. If the depend task is not available, the first part of the error message is similar to
BUILD FAILED .../PFC/ProjectFortress/build.xml:259: Could not create task or type of type: depend.
The command "yum install ant-nodeps" installed the depend task problem. The command "sudo apt-get install ant-optional" worked on Ubuntu 7.10. Different distributions will obviously require different dependencies to be installed.
Commands that can be used to compile, clean, and test Fortress are:
ant clean ant compile ant test
Use "ant clean" to start completely fresh with the Fortress build process. Although this is not usually required, it is a good idea when a build fails. Use "ant compile" to build the Fortress system. Use "ant test" to run the test programs and verify that the system is working. Use "./test" to load the JUnit GUI and run the Fortress tests.
Create the HelloWorld? program listed above.
Use ./fortress to run the program.
> ./fortress HelloWorld.fss Parsing HelloWorld.fss: 660 milliseconds Static checking: 54 milliseconds Read /andrew0/home/andy/Devsrc/Fortress/src_20070719/PFC/ProjectFortress/FortressLibrary.tfs: 466 milliseconds HelloWorld! finish runProgram Program execution: 1680 milliseconds
Instruction for Solaris
NOTE: These instructions are for SXDE (aka Nevada). They have been tested on SXDE build 84 available from http://www.opensolaris.org
$ mkdir ~/work $ cd ~/work $ svn checkout https://projectfortress.sun.com/svn/Community/trunk PFC $ cd PFC $ ant
For building tests, the bundled ant won't work as it's missing junit dependencies. The easiest way around it is to install ant from blastwave repository (http://www.blastwave.org).
To install blastwave package manager, use:
$ su # pkgadd -d http://www.blastwave.org/pkg_get.pkg
Then install ant and complete the tests using:
$ su # pkg-get -i ant # ^D $ /opt/csw/bin/ant test
Then run the HelloWorld.fss provided above:
$ cd bin $ ./fortress ~/HelloWorld.fss guessing FORTRESS_HOME=./.. HelloWorld!
Instruction for Mac OS X
Check out the repository as described above and follow the instructions in the README. Then run the HelloWorld.fss file defined above.
Macintosh-9:tmp ericeallen$ fortress HelloWorld.fss Hello, world! Macintosh-9:tmp ericeallen$
Fortress Basic Building Blocks
Standard Library
The standard libraries can currently be found in the directory Library in the root directory of the repository. The file FortressLibrary.fss contains most of the very basic traits, objects and operations including:
- Arrays (1-dimensional, 2-dimensional and 3-dimensional
- Vectors and Matrices
- Generators
- Basic operations on booleans, integers, reals and strings
- Basic output functions
Arrays
Arrays can be created as literals
x = [ 1 2 3]
or by calling one of the factory methods:
A = array[\ZZ32\](7)
Arrays have to be initialized before elements can be read from them.
A.fill(0)
Next Steps
- Read more about the language at The Fortress Language Specification
- See what is and is not yet implemented at ProjectStatus
- TODO(create tutorials and link them here)
