Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 52a37fb77746ef557a2ec666070d732e > files > 32

bigloo-doc-3.2b-3.fc12.i686.rpm

<!-- 95% W3C COMPLIANT, 95% CSS FREE, RAW HTML -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title>BiglooA ``practical Scheme compiler''User manual for version 3.2bJune 2009</title>
 <style type="text/css">
  <!--
  pre { font-family: monospace }
  tt { font-family: monospace }
  code { font-family: monospace }
  p.flushright { text-align: right }
  p.flushleft { text-align: left }
  span.sc { font-variant: small-caps }
  span.sf { font-family: sans-serif }
  span.skribetitle { font-family: sans-serif; font-weight: bolder; font-size: x-large; }
  span.refscreen { }
  span.refprint { display: none; }
  -->
 </style>
</head>

<body class="chapter" bgcolor="#ffffff">
<table width="100%" class="skribetitle" cellspacing="0" cellpadding="0"><tbody>
<tr><td align="center" bgcolor="#8381de"><div class="skribetitle"><strong><big><big><big>26. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- The Java interface</big></big></big></strong></div><center>
</center>
</td></tr></tbody></table>
<table cellpadding="3" cellspacing="0" width="100%" class="skribe-margins"><tr>
<td align="left" valign="top" class="skribe-left-margin" width="20%" bgcolor="#dedeff"><div class="skribe-left-margin">
<br/><center id='center30570'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30560" align="center" colspan="1"><font color="#ffffff"><strong id='bold30558'
>main page</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30567" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc30563" align="left" valign="top" colspan="1"><strong id='bold30562'
>top:</strong></td><td id="tc30564" align="right" valign="top" colspan="1"><a href="bigloo.html#Bigloo-A-``practical-Scheme-compiler''-User-manual-for-version-3.2b-June-2009" class="inbound">Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009</a></td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center30580'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30574" align="center" colspan="1"><font color="#ffffff"><strong id='bold30572'
>The Java interface</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30577" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left">26.1</td><td colspan="4" width="100%"><a href="bigloo-27.html#Compiling-with-the-JVM-back-end">Compiling with the JVM back-end</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.1.1</td><td colspan="3" width="100%"><a href="bigloo-27.html#Compiler-JVM-options">Compiler JVM options</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.1.2</td><td colspan="3" width="100%"><a href="bigloo-27.html#Compiling-multi-modules-applications">Compiling multi-modules applications</a></td></tr>
 <tr><td valign="top" align="left">26.2</td><td colspan="4" width="100%"><a href="bigloo-27.html#JVM-back-end-and-SRFI-0">JVM back-end and SRFI-0</a></td></tr>
 <tr><td valign="top" align="left">26.3</td><td colspan="4" width="100%"><a href="bigloo-27.html#Limitation-of-the-JVM-back-end">Limitation of the JVM back-end</a></td></tr>
 <tr><td valign="top" align="left">26.4</td><td colspan="4" width="100%"><a href="bigloo-27.html#Connecting-Scheme-and-Java-code">Connecting Scheme and Java code</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.1</td><td colspan="3" width="100%"><a href="bigloo-27.html#Automatic-Java-clauses-generation">Automatic Java clauses generation</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.2</td><td colspan="3" width="100%"><a href="bigloo-27.html#Declaring-Java-classes">Declaring Java classes</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.3</td><td colspan="3" width="100%"><a href="bigloo-27.html#Declaring-abstract-Java-classes">Declaring abstract Java classes</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.4</td><td colspan="3" width="100%"><a href="bigloo-27.html#Extending-Java-classes">Extending Java classes</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.5</td><td colspan="3" width="100%"><a href="bigloo-27.html#Declaring-Java-arrays">Declaring Java arrays</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.6</td><td colspan="3" width="100%"><a href="bigloo-27.html#Exporting-Scheme-variables">Exporting Scheme variables</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.7</td><td colspan="3" width="100%"><a href="bigloo-27.html#Bigloo-runtime-customization">Bigloo runtime customization</a></td></tr>
 <tr><td></td><td valign="top" align="left">26.4.8</td><td colspan="3" width="100%"><a href="bigloo-27.html#Bigloo-module-initialization">Bigloo module initialization</a></td></tr>
 <tr><td valign="top" align="left">26.5</td><td colspan="4" width="100%"><a href="bigloo-27.html#Performance-of-the-JVM-back-end">Performance of the JVM back-end</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center30590'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30584" align="center" colspan="1"><font color="#ffffff"><strong id='bold30582'
>Chapters</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30587" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-1.html#Acknowledgements">Acknowledgements</a></td></tr>
 <tr><td valign="top" align="left">1</td><td colspan="4" width="100%"><a href="bigloo-2.html#Table-of-contents">Table of contents</a></td></tr>
 <tr><td valign="top" align="left">2</td><td colspan="4" width="100%"><a href="bigloo-3.html#Overview-of-Bigloo">Overview of Bigloo</a></td></tr>
 <tr><td valign="top" align="left">3</td><td colspan="4" width="100%"><a href="bigloo-4.html#Modules">Modules</a></td></tr>
 <tr><td valign="top" align="left">4</td><td colspan="4" width="100%"><a href="bigloo-5.html#Core-Language">Core Language</a></td></tr>
 <tr><td valign="top" align="left">5</td><td colspan="4" width="100%"><a href="bigloo-6.html#DSSSL-support">DSSSL support</a></td></tr>
 <tr><td valign="top" align="left">6</td><td colspan="4" width="100%"><a href="bigloo-7.html#Standard-Library">Standard Library</a></td></tr>
 <tr><td valign="top" align="left">7</td><td colspan="4" width="100%"><a href="bigloo-8.html#Pattern-Matching">Pattern Matching</a></td></tr>
 <tr><td valign="top" align="left">8</td><td colspan="4" width="100%"><a href="bigloo-9.html#Fast-search">Fast search</a></td></tr>
 <tr><td valign="top" align="left">9</td><td colspan="4" width="100%"><a href="bigloo-10.html#Structures-and-Records">Structures and Records</a></td></tr>
 <tr><td valign="top" align="left">10</td><td colspan="4" width="100%"><a href="bigloo-11.html#Object-System">Object System</a></td></tr>
 <tr><td valign="top" align="left">11</td><td colspan="4" width="100%"><a href="bigloo-12.html#Regular-parsing">Regular parsing</a></td></tr>
 <tr><td valign="top" align="left">12</td><td colspan="4" width="100%"><a href="bigloo-13.html#Lalr(1)-parsing">Lalr(1) parsing</a></td></tr>
 <tr><td valign="top" align="left">13</td><td colspan="4" width="100%"><a href="bigloo-14.html#Posix-Regular-Expressions">Posix Regular Expressions</a></td></tr>
 <tr><td valign="top" align="left">14</td><td colspan="4" width="100%"><a href="bigloo-15.html#Command-Line-Parsing">Command Line Parsing</a></td></tr>
 <tr><td valign="top" align="left">15</td><td colspan="4" width="100%"><a href="bigloo-16.html#Cryptography">Cryptography</a></td></tr>
 <tr><td valign="top" align="left">16</td><td colspan="4" width="100%"><a href="bigloo-17.html#Errors-Assertions-and-Traces">Errors, Assertions, and Traces</a></td></tr>
 <tr><td valign="top" align="left">17</td><td colspan="4" width="100%"><a href="bigloo-18.html#Threads">Threads</a></td></tr>
 <tr><td valign="top" align="left">18</td><td colspan="4" width="100%"><a href="bigloo-19.html#Database-library">Database library</a></td></tr>
 <tr><td valign="top" align="left">19</td><td colspan="4" width="100%"><a href="bigloo-20.html#Multimedia-library">Multimedia library</a></td></tr>
 <tr><td valign="top" align="left">20</td><td colspan="4" width="100%"><a href="bigloo-21.html#Mail-library">Mail library</a></td></tr>
 <tr><td valign="top" align="left">21</td><td colspan="4" width="100%"><a href="bigloo-22.html#Eval-and-code-interpretation">Eval and code interpretation</a></td></tr>
 <tr><td valign="top" align="left">22</td><td colspan="4" width="100%"><a href="bigloo-23.html#Macro-expansion">Macro expansion</a></td></tr>
 <tr><td valign="top" align="left">23</td><td colspan="4" width="100%"><a href="bigloo-24.html#Parameters">Parameters</a></td></tr>
 <tr><td valign="top" align="left">24</td><td colspan="4" width="100%"><a href="bigloo-25.html#Explicit-typing">Explicit typing</a></td></tr>
 <tr><td valign="top" align="left">25</td><td colspan="4" width="100%"><a href="bigloo-26.html#The-C-interface">The C interface</a></td></tr>
 <tr><td valign="top" align="left">26</td><td colspan="4" width="100%"><a href="bigloo-27.html#The-Java-interface">The Java interface</a></td></tr>
 <tr><td valign="top" align="left">27</td><td colspan="4" width="100%"><a href="bigloo-28.html#Bigloo-Libraries">Bigloo Libraries</a></td></tr>
 <tr><td valign="top" align="left">28</td><td colspan="4" width="100%"><a href="bigloo-29.html#Extending-the-Runtime-System">Extending the Runtime System</a></td></tr>
 <tr><td valign="top" align="left">29</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFIs">SRFIs</a></td></tr>
 <tr><td valign="top" align="left">30</td><td colspan="4" width="100%"><a href="bigloo-31.html#Compiler-description">Compiler description</a></td></tr>
 <tr><td valign="top" align="left">31</td><td colspan="4" width="100%"><a href="bigloo-32.html#User-Extensions">User Extensions</a></td></tr>
 <tr><td valign="top" align="left">32</td><td colspan="4" width="100%"><a href="bigloo-33.html#Bigloo-Development-Environment">Bigloo Development Environment</a></td></tr>
 <tr><td valign="top" align="left">33</td><td colspan="4" width="100%"><a href="bigloo-34.html#Global-Index">Global Index</a></td></tr>
 <tr><td valign="top" align="left">34</td><td colspan="4" width="100%"><a href="bigloo-35.html#Library-Index">Library Index</a></td></tr>
 <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-36.html#Bibliography">Bibliography</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
</div></td>
<td align="left" valign="top" class="skribe-body"><div class="skribe-body">
<a name="Java-Interface" class="mark"></a><a name="g24121" class="mark"></a>
When the Bigloo is configured for a JVM back-end support, the compiler is
able to produce Java class file instead of C files. In order to produce 
JVM class files, use the <code id='code24123'
>-jvm</code> compiler option. Example:<br/><br/><center id='center24128'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog24126'
>$ cat &gt; foo.scm
(module foo (main main))
(define (main argv)
   (print &quot;Hello world: &quot; argv))
$ bigloo -jvm foo.scm
$ a.out
  -| Hello world: (a.out)<br/><br/>
</pre>
</td></tr>
</tbody></table></center>



<!-- Compiling with the JVM back-end -->
<a name="Compiling-with-the-JVM-back-end"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">26.1 Compiling with the JVM back-end</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Compiling-with-the-JVM-back-end" class="mark"></a><a name="g24129" class="mark"></a>
<!-- Compiler JVM options -->
<a name="Compiler-JVM-options"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.1.1 Compiler JVM options</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="g24131" class="mark"></a>
All the compiler options that control the compilation (optimization options,
debugging options, etc.), can be used in conjunction with the <code id='code24133'
>-jvm</code> option.
However, the <code id='code24134'
>-jvm</code> option <em id='emph24135'
>MUST</em> be the first compiler option
on the command line.<br/><br/>In order to prevent the compiler to produce a script shell file to run
the program, it is required to use simultaneously the <code id='code24137'
>-jvm</code> and 
<code id='code24138'
>-c</code> options.<br/><br/></div>
<!-- Compiling multi-modules applications -->
<a name="Compiling-multi-modules-applications"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.1.2 Compiling multi-modules applications</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="g24140" class="mark"></a><a name="g24142" class="mark"></a>
In order to compile and link multi-modules applications, it is required
to specify the association between Scheme source modules and Java
qualified type names. This task is generally complex because of the
annoying mapping that exists from Java class names and the operating
file system names. In order to get rid of this problem, the Bigloo
standard distribution contains a tool, <code id='code24144'
>jfile</code>, that automatically
produces Bigloo Module/Java classes association files. The default name
for such a table is <code id='code24145'
>.jfile</code>. When compiling a module, Bigloo checks
if a <code id='code24146'
>.jfile</code> exists in the current directory, if it exists, the
file is read. The compilation option <code id='code24147'
>-jfile</code> may be used to
specify an alternative jfile name. Example:<br/><br/><center id='center24151'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog24149'
>$ cat &gt; foo.scm
(module foo (export (foo))) (define (foo) 'foo)
$ cat &gt; bar.scm
(module bar (export (bar))) (define (bar) 'bar)
$ cat &gt; hux.scm
(module hux (export (hux))) (define (hux) 'hux)
$ cat &gt; main.scm
(module main (main main) (import foo bar hux)
(define (main argv)
   (print (foo))
   (print (bar))
   (print (fhux)))
$ afile *.scm &gt; .afile
$ jfile *.scm &gt; .jfile
$ bigloo -jvm -c foo.scm
$ bigloo -jvm -c bar.scm
$ bigloo -jvm -c hux.scm
$ bigloo -jvm main.scm foo.class bar.class hux.class
</pre>
</td></tr>
</tbody></table></center>

For an explanation about the <code id='code24152'
>.afile</code>, see <a href="bigloo-4.html#Modules" class="inbound">Modules</a>.<br/><br/></div>
</div><br>
<!-- JVM back-end and SRFI-0 -->
<a name="JVM-back-end-and-SRFI-0"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">26.2 JVM back-end and SRFI-0</font>
</h3></td></tr></table>
</div><div class="section">
<a name="JVM-back-end-and-SRFI-0" class="mark"></a><a name="g24154" class="mark"></a><a name="g24156" class="mark"></a>
The currently running back-end may be tested by the means of the SRFI-0
<code id='code24158'
>cond-expand</code> form (see <a href="bigloo-30.html#SRFIs" class="inbound">SRFIs</a>). That is, when the JVM is ran,
the <code id='code24159'
>bigloo-jvm</code> clause is true. Otherwise, the <code id='code24160'
>bigloo-c</code>
is true. Example:<br/><br/><center id='center24164'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog24162'
>$ cat &gt; foo.scm
(module foo (main main))
(define (main argv)
   (cond-expand
      (bigloo-jvm (print &quot;JVM back-end&quot;))
      (bigloo-c (print &quot;C back-end&quot;))
      (else (error &quot;main&quot; &quot;unsupported back-end&quot; #unspecified))))
$ bigloo -jvm foo.scm
$ a.out
  -| JVM back-end
$ bigloo foo.scm
$ a.out
  -| C back-end
</pre>
</td></tr>
</tbody></table></center>

</div><br>
<!-- Limitation of the JVM back-end -->
<a name="Limitation-of-the-JVM-back-end"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">26.3 Limitation of the JVM back-end</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Limitation-of-the-JVM-back-end" class="mark"></a><a name="g24165" class="mark"></a>
The JVM back-end supports the entire Bigloo source language but the
<code id='code24167'
>call/cc</code> function. More precisely, using the JVM back-end, the
continuation reified in a <code id='code24168'
>call/cc</code> form can only be invoked in the
dynamic extent of that form. <br/><br/>The other restrictions of the C back-end apply to the JVM
back-end. Mainly, <br/><br/><ul class="itemize" id='itemize24190'
><li>Bigloo is not able to compile all the tail recursive call
without stack consumption (however, most of the tail recursive calls are
optimized by Bigloo and don't use stack activation frames).<br/><br/></li>
<li>Bigloo compiled applications do not check for arithmetic overflow.

</li>
<li>When compiling to Jvm, the <code id='code24174'
>extern</code> module clauses are not used.

</li>
<li>Jvm runtime system does support the following function <code id='code24176'
>chdir</code>.

</li>
<li>Jvm runtime system support for <code id='code24178'
>chmod</code> is restricted.

</li>
<li>In order to read a shell variable from a Bigloo compiled Jvm program,
      you have to use the Bigloo link option <code id='code24180'
>-jvm-env</code> <em id='emph24181'
>when</em>
      linking that program. However, some shell variables are 
      automatically defined (<code id='code24182'
>HOME</code>, <code id='code24183'
>USER</code>, <code id='code24184'
>CLASSPATH</code> and
      <code id='code24185'
>TMPDIR</code>.<br/><br/></li>
<li>JVM code generation does not support <code id='code24188'
>pragma</code> forms. 

</li>
</ul>
</div><br>
<!-- Connecting Scheme and Java code -->
<a name="Connecting-Scheme-and-Java-code"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">26.4 Connecting Scheme and Java code</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Connecting-Scheme-and-Java-code" class="mark"></a><a name="g24191" class="mark"></a>
When compiling and linking with the JVM back-end, Bigloo source code may
use the Java API. That is, Bigloo Scheme source code may use (refer or set)
Java static variables, Bigloo source code may call static or virtual
Java methods. In addition, Bigloo variables and functions may be exported
to Java, that is use, set or called in Java source code. Java module clauses
are enabled (read and parsed) only when compiling to JVM byte code.<br/><br/>Java definitions are declared in Bigloo modules by the mean of a Bigloo
module clause: the <em id='emph24194'
>java</em> module clause. The syntax of a <em id='emph24195'
>Java</em>
clause is defined by:<br/><br/><center id='center24199'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog24197'
>&lt;java&gt; ==&gt; &lt;declare-class-clause&gt;
     | &lt;declare-abstract-class-clause&gt;
     | &lt;extend-class-clause&gt;
     | &lt;array-clause&gt;
     | &lt;export-clause&gt;
</pre>
</td></tr>
</tbody></table></center>

As for the <em id='emph24200'
>extern</em> clause, <em id='emph24201'
>java</em> clauses are automatically
``transmitted'' by the importation process.  That is, if module
<code id='code24202'
>module1</code> imports a module <code id='code24203'
>module2</code>, <code id='code24204'
>module</code> treats the
<code id='code24205'
>java</code> clauses of <code id='code24206'
>module2</code> as though they were included in
its own module declaration. Redefinition of a variable or a function
already defined in an java clause is an error. However, the definition of
a Java class or an Java abstract class may be enriched from module to
module.<br/><br/>
<!-- Automatic Java clauses generation -->
<a name="Automatic-Java-clauses-generation"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.1 Automatic Java clauses generation</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Automatic-Java-clauses-generation" class="mark"></a><a name="g24208" class="mark"></a><a name="g24211" class="mark"></a>
Java clauses can be automatically generated using the Jigloo program
which is distributed in the same package as Bigloo. Using Jigloo may be
a good way to understand how Java classes, methods, and variables have to 
be declared in Bigloo. Jigloo reads Java <em id='emph24213'
>class</em> files and generate the 
Bigloo java clauses for that classes.<br/><br/></div>
<!-- Declaring Java classes -->
<a name="Declaring-Java-classes"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.2 Declaring Java classes</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Declaring-Java-classes" class="mark"></a><a name="g24215" class="mark"></a>The &lt;declare-class-clause&gt; clause denotes importation of Java classes.<br/><br/><center id='center24238'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog24236'
>&lt;declare-class-clause&gt; ==&gt; <code id='code24218'
>(</code>class &lt;typed-ident&gt; &lt;slot&gt;* &lt;string&gt;<code id='code24219'
>)</code> 
&lt;slot&gt; ==&gt; &lt;field&gt; | &lt;method&gt; | &lt;constructor&gt;
&lt;field&gt; ==&gt; <code id='code24220'
>(field</code> &lt;modifier&gt; &lt;typed-ident&gt; &lt;string&gt;<code id='code24221'
>)</code>
&lt;method&gt; ==&gt; <code id='code24222'
>(field</code> &lt;modifier&gt; &lt;typed-ident&gt; <code id='code24223'
>(</code>&lt;typed-ident&gt;*<code id='code24224'
>)</code> &lt;string&gt;<code id='code24225'
>)</code>
&lt;constructor&gt; ==&gt; <code id='code24226'
>(constructor</code> &lt;ident&gt; <code id='code24227'
>(</code>&lt;typed-ident&gt;*<code id='code24228'
>))</code>
&lt;modifier&gt; ==&gt; <code id='code24229'
>public</code> | <code id='code24230'
>private</code> | <code id='code24231'
>protected</code>
     | <code id='code24232'
>static</code> | <code id='code24233'
>final</code> | <code id='code24234'
>synchronized</code> | <code id='code24235'
>abstract</code>
</pre>
</td></tr>
</tbody></table></center>

When the compiler encounters a Java class declaration, it automatically
creates a predicate. If the class identifier is <code id='code24239'
>id</code>, the predicate
is named <code id='code24240'
>id?</code>. In addition, the compiler generates functions that
fetch and set the field values. For a field named <code id='code24241'
>f</code>, these functions
are named <code id='code24242'
>id-f</code> and <code id='code24243'
>id-f-set!</code>. Methods and constructors are
also always prefixed the name of the class. That is, for a method named 
<code id='code24244'
>m</code> of a class <code id='code24245'
>k</code>, the Scheme name of the method is <code id='code24246'
>k-m</code>.<br/><br/>Example:<br/><br/><center id='center24269'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog24267'
>(<font color="#1919af"><strong id='bold30591'
>module</strong></font> <font color="#1919af"><strong id='bold30593'
>java-example</strong></font>
   (java (<strong id='bold30595'
>class</strong> point
            (constructor new-default ())
            (field x<font color="#00cf00"><strong id='bold30596'
>::int</strong></font> <font color="red">&quot;x&quot;</font>)
            (method show<font color="#00cf00"><strong id='bold30599'
>::void</strong></font> (<font color="#00cf00"><strong id='bold30601'
>::point</strong></font>) <font color="red">&quot;show&quot;</font>)
            (method static statistics<font color="#00cf00"><strong id='bold30604'
>::int</strong></font> () <font color="red">&quot;PointStatistics&quot;</font>)
            <font color="red">&quot;Point&quot;</font>)
         (<strong id='bold30608'
>class</strong> point-3d<font color="#00cf00"><strong id='bold30609'
>::point</strong></font>
            <font color="red">&quot;Point3D&quot;</font>)))<br/><br/>(<strong id='bold30612'
>let</strong> ((p (point-new-default)))
   (print (point? p))   -| <code id='code24250'
>#t</code>
   (point-x-set! p 3)
   (print (point-x p))) -| <code id='code24251'
>3</code>
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Declaring abstract Java classes -->
<a name="Declaring-abstract-Java-classes"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.3 Declaring abstract Java classes</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Declaring-abstract-Java-classes" class="mark"></a><a name="g24270" class="mark"></a>
A Bigloo abstract Java class declaration corresponds to a Java interface.
It cannot be instantiate but regular classes may inherit from it.<br/><br/><center id='center24277'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog24275'
>&lt;declare-abstract-class-clause&gt; ==&gt; <code id='code24273'
>(</code>abstract-class &lt;typed-ident&gt; &lt;slot&gt;* &lt;string&gt;<code id='code24274'
>)</code> 
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Extending Java classes -->
<a name="Extending-Java-classes"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.4 Extending Java classes</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Extending-Java-classes" class="mark"></a>A class definition may be split into several pieces. One class declaration
(see &lt;declare-class-clause&gt;) and several extensions. The syntax for a Java
class extension is:<br/><br/><center id='center24283'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog24281'
>&lt;extend-class-clause&gt; ==&gt; <code id='code24279'
>(</code>class &lt;typed-ident&gt; &lt;slot&gt;*<code id='code24280'
>)</code> 
</pre>
</td></tr>
</tbody></table></center>

Example:<br/><br/><center id='center24298'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog24296'
>(<font color="#1919af"><strong id='bold30613'
>module</strong></font> <font color="#1919af"><strong id='bold30615'
>java-example2</strong></font>
   (<font color="#1919af"><strong id='bold30617'
>import</strong></font> <font color="#1919af"><strong id='bold30619'
>java-example</strong></font>)
   (java (<strong id='bold30621'
>class</strong> point 
            (field y<font color="#00cf00"><strong id='bold30622'
>::int</strong></font> <font color="red">&quot;y&quot;</font>)
            (field static num<font color="#00cf00"><strong id='bold30625'
>::int</strong></font> <font color="red">&quot;point_num&quot;</font>)
            (constructor new (<font color="#00cf00"><strong id='bold30628'
>::int</strong></font> <font color="#00cf00"><strong id='bold30630'
>::int</strong></font>)))))
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Declaring Java arrays -->
<a name="Declaring-Java-arrays"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.5 Declaring Java arrays</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Declaring-Java-arrays" class="mark"></a><a name="g24299" class="mark"></a>
Java arrays may be allocated and used inside Scheme code. The syntax of
a Java array module clause is:<br/><br/><center id='center24306'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog24304'
>&lt;array-clause&gt; ==&gt; <code id='code24302'
>(array</code> &lt;ident&gt; &lt;typed-ident&gt;<code id='code24303'
>)</code>
</pre>
</td></tr>
</tbody></table></center>

The &lt;typed-ident&gt; must refer to the name of an existing type (i.e., a
primitive Bigloo type, a Bigloo class, an already defined Java class or
an already defined Java array). For an array named <code id='code24307'
>ar</code>, Bigloo
generates:<br/><br/><ul class="itemize" id='itemize24321'
><li>a creator named <code id='code24309'
>make-ar</code> which is a function of one integer 
      argument.<br/><br/></li>
<li>a predicate named <code id='code24312'
>ar?</code>.

</li>
<li>a getter named <code id='code24314'
>ar-ref</code> which is a function of one integer argument.

</li>
<li>a setter named <code id='code24316'
>ar-set!</code> which is a function of two arguments, an
      integer and a value of the array item types.<br/><br/></li>
<li>a length named <code id='code24319'
>ar-length</code>.

</li>
</ul>
Example:<br/><br/><center id='center24336'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog24334'
>(<font color="#1919af"><strong id='bold30632'
>module</strong></font> <font color="#1919af"><strong id='bold30634'
>foo</strong></font>
   (java (array int* <font color="#00cf00"><strong id='bold30636'
>::int</strong></font>)
         (<strong id='bold30638'
>class</strong> bar
            (method static hello<font color="#00cf00"><strong id='bold30639'
>::int</strong></font> (<font color="#00cf00"><strong id='bold30641'
>::int*</strong></font>) <font color="red">&quot;hello&quot;</font>)
            <font color="red">&quot;bar&quot;</font>))
   (main main))<br/><br/>(<font color="#6959cf"><strong id='bold30645'
>define</strong></font> (<font color="#6959cf"><strong id='bold30647'
>main</strong></font> argv)
   (<strong id='bold30649'
>let</strong> ((tab (make-int* 2)))
      (int*-set! tab 0 3)
      (int*-set! tab 1 6)
      (print (bar-hello tab))))
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Exporting Scheme variables -->
<a name="Exporting-Scheme-variables"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.6 Exporting Scheme variables</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Exporting-Scheme-variables" class="mark"></a><a name="g24337" class="mark"></a>
As for the C connection, a Scheme variable (or function) can be exported
to the Java world if and only if it is also exported using an
<code id='code24339'
>export</code> Java clause. Type information is given in the Scheme
exportation, thus, the only requirement for a variable to be Java
exported is to be given a Java name. The Java &lt;export-clause&gt; does
this:<br/><br/><center id='center24345'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog24343'
>&lt;export-clause&gt; ==&gt; <code id='code24341'
>(export</code> &lt;ident&gt; &lt;string&gt;<code id='code24342'
>)</code>
</pre>
</td></tr>
</tbody></table></center>
 
Here is an example of exportation:<br/><br/><center id='center24361'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog24359'
>(<font color="#1919af"><strong id='bold30650'
>module</strong></font> <font color="#1919af"><strong id='bold30652'
>example</strong></font>
   (<font color="#1919af"><strong id='bold30654'
>export</strong></font> (<font color="#1919af"><strong id='bold30656'
>fib</strong></font><font color="#00cf00"><strong id='bold30658'
>::long</strong></font> <font color="#00cf00"><strong id='bold30660'
>::long</strong></font>))
   (java (<font color="#1919af"><strong id='bold30662'
>export</strong></font> <font color="#1919af"><strong id='bold30664'
>fib</strong></font> <font color="red">&quot;scheme_fib&quot;</font>)))<br/><br/>(<font color="#6959cf"><strong id='bold30667'
>define</strong></font> (<font color="#6959cf"><strong id='bold30669'
>fib</strong></font> x) (<strong id='bold30671'
>if</strong> (&lt; x 2) 1 ...))
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Bigloo runtime customization -->
<a name="Bigloo-runtime-customization"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.7 Bigloo runtime customization</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Bigloo-runtime-customization" class="mark"></a><a name="g24362" class="mark"></a>
When the Scheme program completes normally, that is when the last
expression of the Bigloo main is executed without error, the Bigloo runtime
system explicitly call the Java function <code id='code24364'
>System.exit</code>. In some
situation, it may be useful to disable this call. For this, one
must set the <code id='code24365'
>boolean</code> Java static variable 
<code id='code24366'
>bigloo.foreign.must_exitp</code> to <code id='code24367'
>false</code>. This can be implemented
in Java or in Scheme. Here is a Scheme module that sets the variable to
<code id='code24368'
>false</code>.<br/><br/><center id='center24380'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog24378'
>(<font color="#1919af"><strong id='bold30672'
>module</strong></font> <font color="#1919af"><strong id='bold30674'
>no-exit</strong></font>
  (java (<strong id='bold30676'
>class</strong> bigloo
           (field static must-exitp<font color="#00cf00"><strong id='bold30677'
>::bool</strong></font> <font color="red">&quot;must_exitp&quot;</font>)
           <font color="red">&quot;bigloo.foreign&quot;</font>)))<br/><br/>(cond-expand
  (bigloo-jvm (<strong id='bold30681'
>set!</strong> bigloo-must-exitp #f)))
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Bigloo module initialization -->
<a name="Bigloo-module-initialization"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">26.4.8 Bigloo module initialization</font>
</h3></td></tr></table>
</div><div class="subsection">
<a name="Bigloo-module-initialization" class="mark"></a><a name="g24381" class="mark"></a>
By default Bigloo modules are initialized when the application starts. It might
be convenient to initialize the module when the Java classes implementing
the Bigloo modules are loaded. It is possible to drive the Bigloo compiler
to introduce code inside the Java class constructors for initializing the
modules. This is the role of the <code id='code24383'
>-jvm-cinit-module</code> compiler option.<br/><br/><br/></div>
</div><br>
<!-- Performance of the JVM back-end -->
<a name="Performance-of-the-JVM-back-end"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">26.5 Performance of the JVM back-end</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Performance-of-the-JVM-back-end" class="mark"></a><a name="g24385" class="mark"></a>
We are currently improving and investigating about the performance of
the JVM back-end. JVM performance is extremely sensitive to the host
platform (for instance, very unfortunately, Linux seems to be a poor
platform to run JVM code). Currently, it seems that the JVM back-end
produces codes that are in between 4 times and 10 times slower than
codes produced by the C back-end. The ratio between JVM and C is subject
to changes. The gap between JVM and C code is bound to bridge because
of the huge amount of efforts applied to efficiently implement Java
virtual machines.


</div><br>
</div></td>
</tr></table><div class="skribe-ending">
<hr> 
<p class="ending" id='paragraph30687'
><font size="-1">
This <span class="sc">Html</span> page has been produced by 
<a href="http://www.inria.fr/mimosa/fp/Skribe" class="http">Skribe</a>.
<br/>
Last update <em id='it30685'
>Tue Jun  2 11:43:27 2009</em>.</font></p></div>
</body>
</html>