root/trunk/README.txt @ 3803

Revision 3803, 24.6 KB (checked in by EricAllen, 6 months ago)

Lifted method for checking existence of static parameters into general type environments.
Fixed client sites.

RevLine 
[1913]1PROJECT FORTRESS SUBVERSION REPOSITORY
2--------------------------------------
3
4This README exists in the top-level directory of the Fortress project.
5Information about Fortress can be found at the following web site:
6
7    http://projectfortress.sun.com
8
9If you have Subversion installed, you can check out the Fortress
10repository by going to the directory in which you want to check it out
11and issuing the following command:
12
13    svn checkout https://projectfortress.sun.com/svn/Community/trunk PFC
14
15(The name "PFC" merely specifies the name of the directory you want
16to check the code into.  Feel free to substitute another directory
17name if you prefer.)
18
19You'll now have a subdirectory named 'PFC'.  Go into that
20directory and you'll see several subdirectories:
21
22Fortify: The Fortify tool for converting Fortress code into LaTeX,
23both interactively and in batch mode.  Scripts are provided for
24conveniently producing rendered Fortress code in LaTeX documents,
25for producing PDF "doc" files from Fortress source code, etc.  See
26Fortify/fortify-doc.txt for more information.
27
28ProjectFortress: The Fortress interpreter.  You'll need to build the
29interpreter by following the instructions below for setting up your
30environment in order to have a complete Fortress installation.
31
32Emacs: A directory holding the Emacs Lisp file fortress-mode.el,
33which defines a Fortress mode for Emacs.  To use this file, load
34it from your .emacs file with the following command:
35
36    (load (concat (getenv "FORTRESS_HOME")
37                  "/Emacs/fortress-mode.el"))
38    (push '("\\.fs[si]$" . fortress-mode) auto-mode-alist)
39
40If you wish to use the Fortify package to format Fortress source code
41into LaTeX, you should also add the following to your .emacs (for more
42information about fortify, see Fortify/fortify-doc.txt):
43
44    (load (concat (getenv "FORTRESS_HOME")
45                  "/Fortify/fortify.el"))
46
47Vim: A directory containing vim script files for syntax highlighting.
48To enable syntax highlighting for fortress code copy the sub-directories
49under Vim/ to your ~/.vim directory.
50  $ mkdir ~/.vim
[3322]51  $ cp -a Vim/ftdetect Vim/syntax Vim/ftplugin ~/.vim/.
[1913]52If your cp command does not accept the -a option then use -r
[3322]53  $ cp -r Vim/ftdetect Vim/syntax Vim/ftplugin ~/.vim/.
[1913]54
55You should also add the following line to your ~/.vimrc file
56  au BufNewFile,BufRead *.fsi,*.fss set ft=fortress
57
58SpecData: Machine-readable files used by the Fortress Language
59Specification (e.g., a list of all reserved words).  Editors and other
60tools may also benefit from using these files.  Moreover, all examples
61included in the language specification are included in the directory
62SpecData/examples.
63
64Specification: A directory containing a PDF of the Fortress Language
65Specification, Version 1.0.
66
67Library: The home for all of the Fortress standard libraries.
68
69bin: Shell scripts for our various projects.  These are bash scripts;
70you will need an installation of Bash on your system to run them.  To
71make these scripts "auto-homing", script "forfoobar" begins with the
72line
73    FORTRESS_HOME=`${0%forfoobar}fortress_home`
74This replaces 'forfoobar' in whatever was used to invoke the script
75with 'fortress_home', runs that command, and assigns its output to
76FORTRESS_HOME for the remainder of the scripts.  'fortress_home'
77determines the location of fortress_home if it is not otherwise
78specified.  This command can also be used in your own build files;
[3711]79for example, if you include the fortify macros in a LaTeX file
[1913]80    \input{$FORTRESS_HOME/Fortify/fortify-macros}
81you might precede the latex command with
82    FORTRESS_HOME="`fortress_home`"
83It is also possible to set FORTRESS_HOME in your environment, but
84if you have multiple versions of Fortress installed this can cause
85confusion and build problems.
86
87You will also see the following files:
88
89ant: A small bash script used for invoking the build.xml with
90specific Ant options.  (This script defers to the script with the
91same name in directory ProjectFortress.)
92
93build.xml: The interpreter build script, written in Ant.  (This
94script defers to the script with the same name in the directory
95ProjectFortress.)
96
97fortress.properties: This file defines several environment variables
98used by the internals of the Fortress interpreter.  (Normally, there is
99no reason to override the settings in this file.)
100
101
102SETTING UP YOUR ENVIRONMENT
103---------------------------
104
105We assume you are using an operating system with a Unix-style shell
106(for example, Solaris, Linux, Mac OS X, or Cygwin on Windows).  You
107will need to have access to the following:
108
[3373]109* J2SDK 1.6 or later.  See http://java.sun.com/javase/downloads/index.jsp
[1913]110* Ant 1.6.5 or later.  See http://ant.apache.org/bindownload.cgi
111* Bash version 2.5 or later, installed at /bin/bash.
112  See http://www.gnu.org/software/bash/
113
114Assume FORTRESS_HOME points to the PFC directory you checked out.  On
115Unix-like systems this should be a matter of using export or setenv.  If
116you are using Cygwin, one user reports success with the following
117command line for setting FORTRESS_HOME:
118  export FORTRESS_HOME=`cygpath -am cygwin/path/to/fortress/install/directory`
119e.g.:
120  export FORTRESS_HOME=`cygpath -am ${HOME}/tools/fortress`
121
122
123In your shell startup script, add $FORTRESS_HOME/bin to your path.
124The shell scripts in this directory are Bash scripts.  To run them,
125you must have Bash accessible in /bin/bash.
126
127Make sure the following environment variables are set in your startup
128script:
129
130    JAVA_HOME
131    ANT_HOME
132
133(Although our scripts are sometimes able to guess the locations of
134JAVA_HOME and ANT_HOME, it is preferred that you set them manually.)
135
136Once all of these environment variables are set, build the interpreter
137by going to the directory FORTRESS_HOME and typing the command:
138
[3566]139    ./ant clean compile
[1913]140
141If that doesn't work, there's a bug in the interpreter; please issue a
142bug report.
143
144Once you have built the interpreter, you can call it from any directory,
145on any Fortress file, simply by typing one of the following commands at a
146command line:
147
[3464]148    fortress [walk] [-test] [-debug interpreter] somefile.fss arg...
[1913]149    fortress help
150
[3386]151The first time you run a Fortress program, the static checker is
152called on the given file and the results are stored in a cache
153directory (by default this cache is kept in default_repository/caches
154in the root of your Fortress distribution).  No user-visible object
[3711]155file is generated.  A file with suffix .fsi should contain a single API
[3386]156definition.  The name of the API should match the name of the file.
157Similarly, a file with the suffix .fss should contain a single
158component definition.  The name of the component should match the name
159of the file.
[1913]160
[3464]161A command of the form "fortress walk somefile.fss" checks whether a
[3386]162cached and up to date result of compiling the given file exists.  If
163so, it runs the cached file.  Otherwise, it processes the given file
164and runs the result.  This command can be abbreviated as "fortress
165somefile.fss".  If the optional flag -test is given, all test
166functions defined in the given file are run instead.  If the optional
[3464]167flag "-debug interpreter" is given, stack traces from the underlying
168interpreter are displayed when errors are signaled.
[1913]169
170If all else fails, look at the script bin/fortress to see if your system
171has peculiarities (for example cygwin requires ; separators in the
172classpath).
173
174
175USING ECLIPSE
176-------------
[1972]177There exists a .project file in the directory ${FORTRESS_HOME}.
178Import this project into Eclipse.
179
[2044]180There exists a file called ${FORTRESS_HOME}/DOTCLASSPATH in
[2639]181the repository. Copy this file to ${FORTRESS_HOME}/.classpath.
[1972]182If you are using the Java 5.0 jdk under Windows or Linux, you will need
[1913]183to add an entry to ${JAVA_HOME}/lib/tools.jar to the classpath.
184
[2410]185Setting up Eclipse to follow the Fortress project coding style
186conventions is a two-step process. The following instructions are
187known to work on Eclipse 3.4, and should work on Eclipse 3.3 as well.
188These will change preferences for all your Eclipse projects.
[3803]189Open up Eclipse Preferences to start configuring your global
[2410]190settings. First select General --> Editors --> Text Editors
191and make sure the checkbox is enabled for "Insert spaces for tabs".
192Second select Java --> Code Style --> Formatter and click on the "Edit..."
193button. Change the Tab policy to "Spaces only" and give the profile a new
194name (recommended name: "Spaces only").  Click "OK" and you are finished.
[1913]195
196DEMO PROGRAMS
197-------------
198
199The directory ProjectFortress/demos/ contains some demonstration Fortress
200programs.  Among them are:
201
202buffons.fss: Buffon's needle.  Estimates pi using a Monte Carlo
203simulation.
204
205lutx.fss: Naive dense LU decomposition.  Demonstrates how to define
206new subclasses of Array2.
207
208conjGrad.fss: Conjugate gradient, including the snapshot from the NAS
209CG benchmark that you've seen in many Fortress talks.  Uses the Sparse
210library for sparse matrices and vectors.
211
212sudoku.fss: Solve a simple sudoku by elimination.  Includes a
213tree-based set implementation.
214
215aStar.fss: Generic A* search, accompanied by a specific instance for
216solving sudoku that cannot be solved by elimination alone.
217
218Lambda.fss: A simple interpreter for the lambda calculus that permits
219top-level binding and reduces to both WNHF and NF.  If you're curious
220how to parse text using the Fortress libraries, you should look here
221(it's presently far more painful than we'd like).
222
223
224TEST PROGRAMS
225-------------
226
227The directory ProjectFortress/tests/ contains some Fortress programs
228to test the interpreter.  Test programs that are supposed to fail
229(for example, storing a String into a ZZ32-typed mutable) have names
230that are prefixed with XXX.
231
232The directory ProjectFortress/static_tests/ contains some Fortress
233programs to test the static end.  Test programs that are supposed to
234fail have names that are prefixed with XXX.  Test programs that are
[3711]235supposed to pass static disambiguation then fail have names that
[1913]236are prefixed with DXX.
237
[2044]238The directory ProjectFortress/parser_tests/ contains some Fortress
239programs to test the parser.  Test programs that are supposed to
240fail to be parsed have names that are prefixed with XXX.
[1913]241
242The directory ProjectFortress/not_passing_yet/ contains some Fortress
243programs that should pass, but do not.  For example, if we had a test
244file containing an error that should be detected, but it isn't, that
245would be contained in ProjectFortress/not_passing_yet with a name
[2044]246prefixed with XXX.  Test programs in this directory should pass
247the parser.
[1913]248
249
250COMPONENTS
251----------
252
253Fortress currently lacks a full-blown component system.  All the code
254in your Fortress program should reside in API and component file pairs.
255If you take a look at the Fortress programs in ProjectFortress/tests/,
256ProjectFortress/demos/, or SpecData/examples, you'll see that they have
257the same overall structure:
258
259
260component MyComponent
261  exports Executable
262
263  ...  Your program here ...
264
[3546]265  run():() = ...
[1913]266
267end
268
269
270LANGUAGE FEATURES THAT ARE IMPLEMENTED
271--------------------------------------
272
273* Object and trait declarations, including polymorphic traits.
274  Constructor invocations must *always* provide the static arguments
275  explicitly.
276
277* Overloaded functions and ordinary methods.  Top-level overloaded
278  functions can be polymorphic.  Nested functions and methods must be
279  monomorphic.
280
281* Polymorphic top-level functions and methods, so long as the methods
282  are not overloaded.
283
284* Checking and inference of argument types to functions, methods, and
285  operators.  These checks use the dynamic types of the arguments.
286  Return types are NOT checked.  Inference of static parameters is not
287  complete yet; it is often necessary to provide static arguments
288  explicitly.  It is *always* necessary to do so in a constructor call
289  and in any situation where a static parameter occurs only in the result
290  and not in the arguments to a function.  For example, you must always
291  provide the array element type E and size n when invoking the
292  factory array1[\E,n\]().
293
294* Arrays of up to three dimensions.  Note that there isn't yet a
295  single overarching Array type.  For more details on the array types
296  and operations defined see below.  In particular, note that array
297  comprehensions are not yet implemented; the array types provide
298  functions to work around this lack.  Another caveat: due to a bug we
299  haven't fully understood, some (but not all) uses of the compact
300  notation T[n,m] for an array type cause the interpreter to fail.
301  Desugaring the code by hand to e.g. Array2[\T,0,n,0,m\] works around
302  this bug.
303
304* Array aggregates except singleton arrays.
305
306* Parallel tupling and argument evaluation.
307
308* Parallel for loops over simple ranges such as 0#n.
309
310* Sequential for loops over simple ranges.  The functional method seq()
311  and the equivalent function sequential() can be used to turn any
312  Generator into a SequentialGenerator.
313
314* While loops, typecase, if, etc.  Note that for parametric types
315  typecase isn't nearly as useful as you might think, since it cannot
316  bind type variables; we are working to address this shortcoming.
317
318* The "atomic" construct uses code based on the DSTM2 library.  Nested
319  transactions are flattened.  We use their obstruction free algorithm
320  with a simple lowest-thread-wins contention manager.  Reduction
321  variables in for loops are not yet implemented, so perform an
322  explicit atomic update or just use a reduction expression instead.
323
324* throw and catch expressions.
325
326* Generators.
327
328* at expressions.
329
330* spawn
331
332* also (multiple parallel blocks)
333
334
335LANGUAGE FEATURES THAT ARE NOT IMPLEMENTED
336------------------------------------------
337
338* Numerals with radix specifiers (which implies that some numerals may be
339  recognized as identifiers)
340
341* Unicode names
342
343* Dimensions and units
344
345* Static arguments: nat (using minus), int, bool, dimension, and unit
346
347* Modifiers
348
349* Keyword arguments
350
351* Where clauses
352
353* Coercion
354
355* Constraint solving for nat parameters
356
357* Reduction variables
358
359* Distributions
360
361* Any of the types which classify operator properties
362
363* Any of the bits and storage types
364
365* Non-RR64 floats
366
367* Integers other than ZZ32 and ZZ64
368
369* Use of ZZ64 for indexing (the JVM uses 32-bit indices)
370
371
372CHANGES SINCE FORTRESS LANGUAGE SPECIFICATION v.1.0 BETA
373--------------------------------------------------------
374
[3711]375* Fortress 1.0 is the first  release of the Fortress language
376interpreter is the first to be released in tandem with the language
377specification, available as open source and online at:
[1913]378
379    http://projectfortress.sun.com
380
381Each example in the specification is automatically generated from
382a corresponding working Fortress program which is run by every test run
383of the interpreter.
384
385* To synchronize the specification with the implementation, it was
386necessary to temporarily drop the following features from the specification:
387
388 - Static checks (including static overloading checks)
389 - Static type inference
390 - Qualified names (including aliases of imported APIs)
391 - Getters and setters
392 - Array comprehensions
393 - Keyword parameters and keyword expressions
394 - Most modifiers
395 - Dimensions and units
396 - Type aliases
397 - Where clauses
398 - Coercions
399 - Distributions
400 - Parallel nested transactions
401 - Abstract function declarations
402 - Tests and properties
403 - Syntactic abstraction
404
405* Libraries have significantly changed.
406
407* Syntax and semantics of the following features have changed:
408 - Tuple and functional arguments
409 - Operator rules: associativity, precedence, fixity, and juxtaposition
410 - Operator declaration
411 - Extremum expression
412 - Import statement
413 - Multiple variable declaration
414 - Typecase expression
415
416* The following features have been added to the language:
417 - "native" modifier
418 - Operator associativity
419 - Explicit static arguments to big operator applications
420
421* The following features have been eliminated from the language:
422 - Identifier parameters
423 - Explicit self parameters of dotted methods
424 - Empty extends clauses
425 - Local operator declarations
426 - Shorthands for Set, List, and Map types
427 - Tuple type encompassing all tuple types
428
429* Significantly more examples have been added.
430
431
432THE DEFAULT LIBRARIES
433---------------------
434
435The components ProjectFortress/LibraryBuiltin/FortressBuiltin.fsi,
436ProjectFortress/LibraryBiltin/NativeSimpleTypes.fss and
437Library/FortressLibrary.fss are imported implicitly whenever any
438Fortress program is run.
439
440
441BUILT-IN TYPES
442--------------
443
444There are a bunch of types that are defined internally by the Fortress
445interpreter.  With the exception of Any, these cannot be overridden.
446The built-in types are found in
447ProjectFortress/LibraryBuiltin/FortressBuiltin.fsi and
448NativeSimpleTypes.fsi; documentation for the released version of these
449libraries can be found in the accompanying specification release.
450Most built-in types do not have any methods.  Note that the types
451found in FortressBuiltin do not have methods.
452
453Tuple and arrow types are always built in, and cannot be overridden in
454any way.
455
456Note that there isn't (yet) a trait Object!  Eventually user-written
457trait and object declarations will extend Object by default; right now,
458they instead extend Any by default.  We plan to migrate to a new
459infrastructure for primitive objects (based on the one used for
460Boolean in NativeSimpleTypes) at which point we will remedy this
461situation.
462
463Meanwhile, operations on the primitive types in FortressBuiltin can be
464found in Library/FortressLibrary.fsi; again these primitive are
465documented in the specification as well.  Note in particular that in
466the absence of coercion, you may occasionally need to make use of widen
467and narrow to convert between ZZ32 and ZZ64.
468
469
470LIBRARY HIGH POINTS
471-------------------
472
473Your best guide to library functionality is the library code itself;
474this can be found in Library/ and in ProjectFortress/LibraryBuiltin.
475The APIs for these libraries can also be found in the language
476specification (note, though, that if you downloaded the latest version
477of the Fortress implementation then the two may differ).  This section
478provides an overview of things you may not immediately realize are
479there.
480
481Juxtaposition of strings means string append.  You may also
482find the BIG STRING operation (that concatenates strings) useful.
483
484Several functions attempt to convert data of type Any to a string.
485These include print(), println(), assert(), and juxtaposition of Any
486with a string.  Right now, the FortressBuiltin types are printed using
487internal magic, and object types are printed using the toString
488method.  The consequence of this is that you will see a runtime error
489if you attempt to print an object without first defining a toString
490method.
491
492In the absence of array comprehensions, there are several ways to
493create and initialize an array (in these examples a 1-D array, but the
4942- and 3-D arrays work the same way):
495
496The simplest is to use an aggregate expression (this seems to fail at
497top level in your program, which is a known bug):
498    z : ZZ32[3] = [1 2 3]
499
500If you know the size statically (it is a static parameter to your
501function, or is fixed at compile time):
502
503    a : T[size] = array1[\T,size\]()  (* lower bound 0 *)
504    a[i] := f(i),  i <- a.bounds()
505
506or:
507    a : T[size] = array1[\T,size\](initialValue)
508
509or:
510    a : T[size] = array1[\T,size\](fn (index:ZZ32) => ...)
511
512If you are computing the size at run time:
513    a = array[\T\](size)
514    a[i] := f(i),  i <- a.bounds()
515
516or:
517    a = array[\T\](size).fill(initialValue)
518
519or:
520    a = array[\T\](size).fill(fn (index:ZZ32) => ...)
521
522At the moment, to create a non-0-indexed array you need to create a
523correctly-sized 0-indexed array as described above, then use the
524shift(newlower) method to shift the lower index.  Thus, to create an
525nxn 1-indexed array you can do something like this:
526
527    a = array2[\T,n,n\]().shift(1,1)
528
529The replicate[\T\]() method on arrays is a little unintuitive at
530first.  It creates a fresh array whose element type is T but whose
531bounds are the same as the bounds of the array being replicated.  When
532data distribution is fully implemented, it should respect that as well.
533It is a bit like saying array[\T\](a.bounds().upper()) for 0-indexed
534arrays but is slightly more graceful and deals well with non-0-indexed
535arrays.
536
537You can convert any array to use 0 indexing simply by indexing it with
538an empty range:
539    a[:] or a[#]  ==>  a, only 0-indexed.
540
541Any operation that yields a subarray of an underlying array shares
542structure.  If you want a fresh copy of the data, use the copy() method.
543
544To assign the contents of array a to array b, you can use:
545
546    a.assign(b)
547
548if a is freshly allocated.  The following should work all the time:
549
550    a[:] := b[:]
551
552Right now type-level ranges don't really exist, so if you want to
553operate on subarrays with statically type-checked bounds, you'll need
554to work with the subarray method:
555
556    subarray[\nat b, nat s, nat o\]():Array1[\T, b, s\]
557
558This returns a structure-sharing subarray with base b and size s
559starting from offset o in the current array.
560
561The special factory functions vector and matrix are restricted to numeric
562argument types and static dimensionality:
563
564    x' : ZZ64[1000] = vector[\ZZ64,1000\](17)
565
566At the moment, any Array1 or Array2 whose element type extends Number
567is considered to be a valid vector or matrix respectively (this will
568eventually be accomplished by coercion, and vectors will be a distinct
569type).  Note that the t() method on matrices is transposition, and
570will eventually be replaced by opr ()^T.
571
572
573GENERATORS, REDUCTIONS, and COMPREHENSIONS
574------------------------------------------
575
576Defining new generators is discussed in detail in the Fortress
577language specification, but if you're trying it yourself for the first
578time, you may find it instructive to browse the source code of the libraries.
579
580
581DEFINING NEW PRIMITIVE FUNCTIONS
582--------------------------------
583
584It is relatively easy to add new primitive functions to Fortress.  To
585do this, you simply invoke the builtinPrimitive function with the name
586of a loadable Java class which extends glue.NativeApp.  Useful
587subclasses are NativeFn1 and NativeFn2, and any of the classes in
588glue.prim (particularly the classes in glue.prim.Util).  Here's a
589sample native binding, which defines the floor operator which returns
590an integer:
591
592    opr |\a:RR64/|:ZZ64 = builtinPrimitive("glue.prim.Float$IFloor")
593
594You should *not* mention the type parameter to builtinPrimitive when
595invoking it; doing so will confuse the interpreter.  Note also that
596the interpreter requires that you declare appropriate argument and
597return types for your native functions as shown above.  If you give an
598incorrect type declaration on the Fortress side, you'll get
599non-user-friendly error messages when the Java code is run.
600
601
602DEFINING NEW PRIMITIVE CLASSES
603------------------------------
604
605To define a new primitive class, you will need to write a native
606component.  Examples of these can be found in Library; anything that
607starts with "native component" is a native component.  Here's the
608first few lines of File.fss:
609
610native component File
611import FileSupport.{...}
612export File
613
[3179]614private language="java"
615private package="com.sun.fortress.interpreter.glue.prim"
[1913]616
[2826]617object FileReadStream(filename:String)
[1913]618        extends { ReadStream, FileStream}
619    getter fileName():String =
620      builtinPrimitive(
621        "com.sun.fortress.interpreter.glue.prim.FileReadStream$fileName")
622    ....
623
624
625Note that we import a non-native component that defines traits
626mentioned in the extends clause.  The first two bindings must be
627language and package in that order; right now only language="java" is
628supported, and the package is where the backing class will be found.
629In com.sun.fortress.interpreter.glue.prim.FileReadStream defines the
630corresponding backing data type.  Note that FileReadStream extends
631Constructor, and defines an inner class that extends FOrdinaryObject
632that represents the actual values that get passed around at run time.
633
634The methods must extend NativeMethod, but are otherwise referenced
635using builtinPrimitive just as for top-level functions.
636
637A native class can contain a mix of native and non-native method
638code.  Note, however, that the namespace in which a native object is
639defined is slightly odd from the perspective of library name
640visibility.  For this reason, some primitive classes extend a parent
641trait (defined in a non-native component) that contains most of their
642non-native functionality and that has full access to the libraries.
643For example, FileStream provides a number of generator definitions
644that are inherited by FileReadStream.
Note: See TracBrowser for help on using the browser.