"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hobbit.info" between
scm-5f2.zip and scm-5f3.zip

About: SCM is a Scheme Language Interpreter.

hobbit.info  (scm-5f2):hobbit.info  (scm-5f3)
This is hobbit.info, produced by makeinfo version 4.13 from hobbit.texi. This is hobbit.info, produced by makeinfo version 6.5 from hobbit.texi.
This manual is for the Hobbit compiler for SCM (version 5f2, January This manual is for the Hobbit compiler for SCM (version 5f3, February
2015), 2020),
Copyright (C) 2002 Free Software Foundation Copyright (C) 2002 Free Software Foundation
Permission is granted to make and distribute verbatim copies of Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission this manual provided the copyright notice and this permission
notice are preserved on all copies. notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided this manual under the conditions for verbatim copying, provided
that the entire resulting derived work is distributed under the that the entire resulting derived work is distributed under the
terms of a permission notice identical to this one. terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for manual into another language, under the above conditions for
modified versions, except that this permission notice may be modified versions, except that this permission notice may be stated
stated in a translation approved by the author. in a translation approved by the author.
INFO-DIR-SECTION The Algorithmic Language Scheme INFO-DIR-SECTION The Algorithmic Language Scheme
START-INFO-DIR-ENTRY START-INFO-DIR-ENTRY
* hobbit: (hobbit). SCM Compiler. * hobbit: (hobbit). SCM Compiler.
END-INFO-DIR-ENTRY END-INFO-DIR-ENTRY
 
File: hobbit.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) File: hobbit.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
Hobbit Hobbit
****** ******
This manual is for the Hobbit compiler for SCM (version 5f2, January This manual is for the Hobbit compiler for SCM (version 5f3, February
2015), 2020),
Copyright (C) 2002 Free Software Foundation Copyright (C) 2002 Free Software Foundation
Permission is granted to make and distribute verbatim copies of Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission this manual provided the copyright notice and this permission
notice are preserved on all copies. notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided this manual under the conditions for verbatim copying, provided
that the entire resulting derived work is distributed under the that the entire resulting derived work is distributed under the
terms of a permission notice identical to this one. terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for manual into another language, under the above conditions for
modified versions, except that this permission notice may be modified versions, except that this permission notice may be stated
stated in a translation approved by the author. in a translation approved by the author.
* Menu: * Menu:
* Introduction:: * Introduction::
* Compiling with Hobbit:: * Compiling with Hobbit::
* The Language Compiled:: * The Language Compiled::
* Performance of Compiled Code:: * Performance of Compiled Code::
* Principles of Compilation:: * Principles of Compilation::
* About Hobbit:: * About Hobbit::
* Index:: * Index::
skipping to change at line 75 skipping to change at line 74
1 Introduction 1 Introduction
************** **************
Hobbit is a small optimizing scheme-to-C compiler written in Report 4 Hobbit is a small optimizing scheme-to-C compiler written in Report 4
scheme and intended for use together with the SCM scheme interpreter of scheme and intended for use together with the SCM scheme interpreter of
A. Jaffer. Hobbit compiles full Report 4 scheme, except that: A. Jaffer. Hobbit compiles full Report 4 scheme, except that:
* It does not fully conform to the requirement of being properly * It does not fully conform to the requirement of being properly
tail-recursive: non-mutual tailrecursion is detected, but mutual tail-recursive: non-mutual tailrecursion is detected, but mutual
tailrecursion is not. tailrecursion is not.
* Macros from the Report 4 appendix are not supported (yet): only the
* Macros from the Report 4 appendix are not supported (yet): only common-lisp-like defmacro is supported.
the common-lisp-like defmacro is supported.
Hobbit treats SCM files as a C library and provides integration of Hobbit treats SCM files as a C library and provides integration of
compiled procedures and variables with the SCM interpreter as new compiled procedures and variables with the SCM interpreter as new
primitives. primitives.
Hobbit compiles scheme files to C files and does not provide anything Hobbit compiles scheme files to C files and does not provide anything
else by itself (eg. calling the C compiler, dynamic loading). Such else by itself (eg. calling the C compiler, dynamic loading). Such
niceties are described in the next chapter *note Compiling And niceties are described in the next chapter *note Compiling And
Linking::. Linking::.
Hobbit (derived from hobbit5x) is now part of the SCM Scheme Hobbit (derived from hobbit5x) is now part of the SCM Scheme
implementation. The most recent information about SCM can be found on implementation. The most recent information about SCM can be found on
SCM's "WWW" home page: SCM's "WWW" home page:
`http://people.csail.mit.edu/jaffer/SCM' <http://people.csail.mit.edu/jaffer/SCM>
Hobbit4d has also been ported to the Guile Scheme implementation: Hobbit4d has also been ported to the Guile Scheme implementation:
`http://www.gnu.org/software/guile/anon-cvs.html' <http://www.gnu.org/software/guile/anon-cvs.html>
 
File: hobbit.info, Node: Compiling with Hobbit, Next: The Language Compiled, Prev: Introduction, Up: Top File: hobbit.info, Node: Compiling with Hobbit, Next: The Language Compiled, Prev: Introduction, Up: Top
2 Compiling with Hobbit 2 Compiling with Hobbit
*********************** ***********************
* Menu: * Menu:
* Compiling And Linking:: * Compiling And Linking::
* Error Detection:: * Error Detection::
* Hobbit Options:: * Hobbit Options::
* CC Optimizations:: * CC Optimizations::
 
File: hobbit.info, Node: Compiling And Linking, Next: Error Detection, Prev: Compiling with Hobbit, Up: Compiling with Hobbit File: hobbit.info, Node: Compiling And Linking, Next: Error Detection, Prev: Compiling with Hobbit, Up: Compiling with Hobbit
2.1 Compiling And Linking 2.1 Compiling And Linking
========================= =========================
`(require 'compile)' '(require 'compile)'
-- Function: hobbit name1.scm name2.scm ... -- Function: hobbit name1.scm name2.scm ...
Invokes the HOBBIT compiler to translate Scheme files `NAME1.scm', Invokes the HOBBIT compiler to translate Scheme files 'NAME1.scm',
`NAME2.scm', ... to C files `NAME1.c' and `NAME1.h'. 'NAME2.scm', ... to C files 'NAME1.c' and 'NAME1.h'.
-- Function: compile-file name1.scm name2.scm ... -- Function: compile-file name1.scm name2.scm ...
Compiles the HOBBIT translation of NAME1.scm, NAME2.scm, ... to a Compiles the HOBBIT translation of NAME1.scm, NAME2.scm, ... to a
dynamically linkable object file NAME1<object-suffix>, where dynamically linkable object file NAME1<object-suffix>, where
<object-suffix> is the object file suffix for your computer (for <object-suffix> is the object file suffix for your computer (for
instance, `.so'). NAME1.scm must be in the current directory; instance, '.so'). NAME1.scm must be in the current directory;
NAME2.scm, ... may be in other directories. NAME2.scm, ... may be in other directories.
If a file named `NAME1.opt' exists, then its options are passed to If a file named 'NAME1.opt' exists, then its options are passed to
the `build' invocation which compiles the `c' files. the 'build' invocation which compiles the 'c' files.
cd ~/scm/ cd ~/scm/
scm -rcompile -e"(compile-file \"example.scm\")" scm -rcompile -e"(compile-file \"example.scm\")"
Starting to read example.scm Starting to read example.scm
Generic (slow) arithmetic assumed: 1.0e-3 found. Generic (slow) arithmetic assumed: 1.0e-3 found.
** Pass 1 completed ** ** Pass 1 completed **
** Pass 2 completed ** ** Pass 2 completed **
skipping to change at line 163 skipping to change at line 161
(nonkeyword_make-promise damped-oscillator map-streams scale-vector element wise runge-kutta-4 integrate-system) (nonkeyword_make-promise damped-oscillator map-streams scale-vector element wise runge-kutta-4 integrate-system)
; Scheme (linux) script created by SLIB/batch Sun Apr 7 22:49:49 2002 ; Scheme (linux) script created by SLIB/batch Sun Apr 7 22:49:49 2002
; ================ Write file with C defines ; ================ Write file with C defines
(delete-file "scmflags.h") (delete-file "scmflags.h")
(call-with-output-file (call-with-output-file
"scmflags.h" "scmflags.h"
(lambda (fp) (lambda (fp)
(for-each (for-each
(lambda (string) (write-line string fp)) (lambda (string) (write-line string fp))
'("#define IMPLINIT \"Init5f2.scm\"" '("#define IMPLINIT \"Init5f3.scm\""
"#define BIGNUMS" "#define BIGNUMS"
"#define FLOATS" "#define FLOATS"
"#define ARRAYS" "#define ARRAYS"
"#define DLL")))) "#define DLL"))))
; ================ Compile C source files ; ================ Compile C source files
(system "gcc -O2 -fpic -c -I/usr/local/lib/scm/ example.c") (system "gcc -O2 -fpic -c -I/usr/local/lib/scm/ example.c")
(system "gcc -shared -o example.so example.o -lm -lc") (system "gcc -shared -o example.so example.o -lm -lc")
(delete-file "example.o") (delete-file "example.o")
; ================ Link C object files ; ================ Link C object files
(delete-file "slibcat") (delete-file "slibcat")
Compilation finished at Sun Apr 7 22:49:50 Compilation finished at Sun Apr 7 22:49:50
-- Function: compile->executable exename name1.scm name2.scm ... -- Function: compile->executable exename name1.scm name2.scm ...
Compiles and links the HOBBIT translation of NAME1.scm, NAME2.scm, Compiles and links the HOBBIT translation of NAME1.scm, NAME2.scm,
... to a SCM executable named EXENAME. NAME1.scm must be in the ... to a SCM executable named EXENAME. NAME1.scm must be in the
current directory; NAME2.scm, ... may be in other directories. current directory; NAME2.scm, ... may be in other directories.
If a file named `EXENAME.opt' exists, then its options are passed If a file named 'EXENAME.opt' exists, then its options are passed
to the `build' invocation which compiles the `c' files. to the 'build' invocation which compiles the 'c' files.
cd ~/scm/ cd ~/scm/
scm -rcompile -e"(compile->executable \"exscm\" \"example.scm\")" scm -rcompile -e"(compile->executable \"exscm\" \"example.scm\")"
Starting to read example.scm Starting to read example.scm
Generic (slow) arithmetic assumed: 1.0e-3 found. Generic (slow) arithmetic assumed: 1.0e-3 found.
** Pass 1 completed ** ** Pass 1 completed **
** Pass 2 completed ** ** Pass 2 completed **
skipping to change at line 215 skipping to change at line 213
(nonkeyword_make-promise damped-oscillator map-streams scale-vector element wise runge-kutta-4 integrate-system) (nonkeyword_make-promise damped-oscillator map-streams scale-vector element wise runge-kutta-4 integrate-system)
; Scheme (linux) script created by SLIB/batch Sun Apr 7 22:46:31 2002 ; Scheme (linux) script created by SLIB/batch Sun Apr 7 22:46:31 2002
; ================ Write file with C defines ; ================ Write file with C defines
(delete-file "scmflags.h") (delete-file "scmflags.h")
(call-with-output-file (call-with-output-file
"scmflags.h" "scmflags.h"
(lambda (fp) (lambda (fp)
(for-each (for-each
(lambda (string) (write-line string fp)) (lambda (string) (write-line string fp))
'("#define IMPLINIT \"Init5f2.scm\"" '("#define IMPLINIT \"Init5f3.scm\""
"#define COMPILED_INITS init_example();" "#define COMPILED_INITS init_example();"
"#define CCLO" "#define CCLO"
"#define FLOATS")))) "#define FLOATS"))))
; ================ Compile C source files ; ================ Compile C source files
(system "gcc -O2 -c continue.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c example.c scm.c") (system "gcc -O2 -c continue.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c example.c scm.c")
; ================ Link C object files ; ================ Link C object files
(system "gcc -rdynamic -o exscm continue.o scmmain.o findexec.o script.o ti me.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o example.o scm.o -L/u sr/local/lib/scm/ -lm -lc") (system "gcc -rdynamic -o exscm continue.o scmmain.o findexec.o script.o ti me.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o example.o scm.o -L/u sr/local/lib/scm/ -lm -lc")
Compilation finished at Sun Apr 7 22:46:44 Compilation finished at Sun Apr 7 22:46:44
_Note Bene:_ `#define CCLO' must be present in `scmfig.h'. _Note Bene:_ '#define CCLO' must be present in 'scmfig.h'.
In order to see calls to the C compiler and linker, do In order to see calls to the C compiler and linker, do
(verbose 3) (verbose 3)
before calling these functions. before calling these functions.
 
File: hobbit.info, Node: Error Detection, Next: Hobbit Options, Prev: Compili ng And Linking, Up: Compiling with Hobbit File: hobbit.info, Node: Error Detection, Next: Hobbit Options, Prev: Compili ng And Linking, Up: Compiling with Hobbit
2.2 Error Detection 2.2 Error Detection
=================== ===================
Error detection during compilation is minimal. In case your scheme code Error detection during compilation is minimal. In case your scheme code
is syntactically incorrect, hobbit may crash with no sensible error is syntactically incorrect, hobbit may crash with no sensible error
messages or it may produce incorrect C code. messages or it may produce incorrect C code.
Hobbit does not insert any type-checking code into the C output it Hobbit does not insert any type-checking code into the C output it
produces. Eg, if a hobbit-compiled program applies `car' to a number, produces. Eg, if a hobbit-compiled program applies 'car' to a number,
the program will probably crash with no sensible error messages. the program will probably crash with no sensible error messages.
Thus it is strongly suggested to compile only throughly debugged scheme Thus it is strongly suggested to compile only throughly debugged scheme
code. code.
Alternatively, it is possible to compile all the primitives into calls Alternatively, it is possible to compile all the primitives into calls
to the SCM procedures doing type-checking. Hobbit will do this if you to the SCM procedures doing type-checking. Hobbit will do this if you
tell it to assume that all the primitives may be redefined. Put tell it to assume that all the primitives may be redefined. Put
(define compile-all-proc-redefined #t) (define compile-all-proc-redefined #t)
skipping to change at line 315 skipping to change at line 313
2. Redefinition of procedures. 2. Redefinition of procedures.
By default hobbit assumes that neither primitives nor compiled By default hobbit assumes that neither primitives nor compiled
procedures are redefined, neither before the compiled program is procedures are redefined, neither before the compiled program is
initialized, during its work or later via the interpreter. initialized, during its work or later via the interpreter.
Hobbit checks the compiled source and whenever some variable bar is Hobbit checks the compiled source and whenever some variable bar is
defined as a procedure, but is later redefined, or set! is applied defined as a procedure, but is later redefined, or set! is applied
to bar, then hobbit assumes thas this particular variable bar is to bar, then hobbit assumes thas this particular variable bar is
redefinable. bar may be a primitive (eg `car') or a name of a redefinable. bar may be a primitive (eg 'car') or a name of a
compiled procedure. compiled procedure.
_Note Bene:_ According to the Report 4 it is NOT allowed to use _Note Bene:_ According to the Report 4 it is NOT allowed to use
scheme keywords as variables (you may redefine these as macros scheme keywords as variables (you may redefine these as macros
defined by defmacro, though): defined by defmacro, though):
=> and begin case cond define delay do else if lambda => and begin case cond define delay do else if lambda
let let letrec or quasiquote quote set! unquote unquote-splicing let let letrec or quasiquote quote set! unquote unquote-splicing
If you want to be able to redefine some procedures, eg. `+' and If you want to be able to redefine some procedures, eg. '+' and
`baz', then put both 'baz', then put both
(set! + +) (set! + +)
(set! baz baz) (set! baz baz)
somewhere into your file. somewhere into your file.
As a consequence hobbit will generate code for `+' and `baz' using As a consequence hobbit will generate code for '+' and 'baz' using
the run-time values of these variables. This is generally much the run-time values of these variables. This is generally much
slower than using non-redefined `+' and `baz' (especially for `+'). slower than using non-redefined '+' and 'baz' (especially for '+').
If you want to be able to redefine all the procedures, both If you want to be able to redefine all the procedures, both
primitives (eg `car') and the compiled procedures, then put the primitives (eg 'car') and the compiled procedures, then put the
following into the compiled file: following into the compiled file:
(define compile-all-proc-redefined T) (define compile-all-proc-redefined T)
where T is arbitrary. where T is arbitrary.
If you want to be able to redefine all the compiled procedures, If you want to be able to redefine all the compiled procedures, but
but not the scheme primitives, then put the following into the not the scheme primitives, then put the following into the compiled
compiled file: file:
(define compile-new-proc-redefined T) (define compile-new-proc-redefined T)
where T is arbitrary. where T is arbitrary.
Again, remember that redefinable procedures will be typically much Again, remember that redefinable procedures will be typically much
slower than non-redefinable procedures. slower than non-redefinable procedures.
3. Inlined variables and procedures. 3. Inlined variables and procedures.
You may inline top-level-defined variables and procedures. Notice You may inline top-level-defined variables and procedures. Notice
that inlining is DIFFERENT for variables and procedures! that inlining is DIFFERENT for variables and procedures!
NEVER inline variables or procedures which are set! or redefined NEVER inline variables or procedures which are set! or redefined
anywhere in you program: this will produce wrong code. anywhere in you program: this will produce wrong code.
* You may declare certain top-level defined variables to be * You may declare certain top-level defined variables to be
inlined. For example, if the following variable foo is inlined. For example, if the following variable foo is
declared to be inlined declared to be inlined
(define foo 100) (define foo 100)
then `foo' will be everywhere replaced by `100'. then 'foo' will be everywhere replaced by '100'.
To declare some variables foo and bar to be inlined, put a To declare some variables foo and bar to be inlined, put a
following definition anywhere into your file: following definition anywhere into your file:
(define compile-inline-vars '(foo bar)) (define compile-inline-vars '(foo bar))
Usually it makes sense to inline only these variables whose value Usually it makes sense to inline only these variables whose value
is either a small integer, character or a boolean. is either a small integer, character or a boolean.
_Note Bene:_ Do not use this kind of inlining for inlining _Note Bene:_ Do not use this kind of inlining for inlining
skipping to change at line 417 skipping to change at line 415
following definition anywhere into your file: following definition anywhere into your file:
(define compile-inline '(foo bar)) (define compile-inline '(foo bar))
4. Speeding up vectors: 4. Speeding up vectors:
Put Put
(define compile-stable-vectors '(baz foo)) (define compile-stable-vectors '(baz foo))
into your file to declare that baz and foo are vector names into your file to declare that baz and foo are vector names defined
defined once on the top level, and set! is never applied to them once on the top level, and set! is never applied to them
(vector-set! is, of course, allowed). This speeds up vector (vector-set! is, of course, allowed). This speeds up vector
reference to those vectors by precomputing their location. reference to those vectors by precomputing their location.
5. Speeding up and hiding certain global variables: 5. Speeding up and hiding certain global variables:
Put Put
(define compile-uninterned-variables '(bazvar foovar)) (define compile-uninterned-variables '(bazvar foovar))
into your file to declare that bazvar and foovar are defined on into your file to declare that bazvar and foovar are defined on the
the top level and they do always have an immediate value, ie a top level and they do always have an immediate value, ie a boolean,
boolean, immediate (30-bit) integer or a character. Then bazvar immediate (30-bit) integer or a character. Then bazvar and foovar
and foovar will NOT be accessible from the interpreter. They'll will NOT be accessible from the interpreter. They'll be compiled
be compiled directly into static C vars and used without an extra directly into static C vars and used without an extra C *-operation
C *-operation prefixed to other global scheme variables. prefixed to other global scheme variables.
6. Intermediate files 6. Intermediate files
To see the output of compiler passes, change the following To see the output of compiler passes, change the following
definition in `hobbit.scm'. definition in 'hobbit.scm'.
(define *build-intermediate-files* #f) (define *build-intermediate-files* #f)
to: to:
(define *build-intermediate-files* #t) (define *build-intermediate-files* #t)
7. Name clashes 7. Name clashes
It may happen that several originally different scheme variable It may happen that several originally different scheme variable
names are represented by one and the same C variable. This will names are represented by one and the same C variable. This will
happen, for example, if you have separate variables a-1 and a_1. happen, for example, if you have separate variables a-1 and a_1.
If such (or any other) name clashes occur you may need to change If such (or any other) name clashes occur you may need to change
some control variables in the first sections of `hobbit.scm' (up some control variables in the first sections of 'hobbit.scm' (up to
to the section "global variable defs") or just rename some the section "global variable defs") or just rename some variables
variables in your scheme program. in your scheme program.
8. Other options 8. Other options
See various control variables in the first sections of `hobbit.scm' See various control variables in the first sections of 'hobbit.scm'
(up to section "global variable defs"). (up to section "global variable defs").
 
File: hobbit.info, Node: CC Optimizations, Prev: Hobbit Options, Up: Compilin g with Hobbit File: hobbit.info, Node: CC Optimizations, Prev: Hobbit Options, Up: Compilin g with Hobbit
2.4 CC Optimizations 2.4 CC Optimizations
==================== ====================
When using the C compiler to compile the C code output by hobbit, always When using the C compiler to compile the C code output by hobbit, always
use strong optimizations (eg. `cc -xO3' for cc on Sun, `gcc -O2' or use strong optimizations (eg. 'cc -xO3' for cc on Sun, 'gcc -O2' or
`gcc -O3' for gcc). Hobbit does not attempt to do optimizations of the 'gcc -O3' for gcc). Hobbit does not attempt to do optimizations of the
kind we anticipate from the C compiler, therefore it often makes a kind we anticipate from the C compiler, therefore it often makes a
serious difference whether the C compiler is run with a strong serious difference whether the C compiler is run with a strong
optimization flag or not. optimization flag or not.
For the final and fast version of your program you may want to first For the final and fast version of your program you may want to first
recompile the whole scm (scmlit for the version scm4e2) using the recompile the whole scm (scmlit for the version scm4e2) using the
`-DRECKLESS' flag suppressing error checking: the hobbit-compiled code '-DRECKLESS' flag suppressing error checking: the hobbit-compiled code
uses some SCM primitives in the compiled files with the suffix .o, and uses some SCM primitives in the compiled files with the suffix .o, and a
a number of these primitives become faster when error checking is number of these primitives become faster when error checking is disabled
disabled by `-DRECKLESS'. Notice that hobbit never inserts error by '-DRECKLESS'. Notice that hobbit never inserts error checking into
checking into the code it produces. the code it produces.
 
File: hobbit.info, Node: The Language Compiled, Next: Performance of Compiled Code, Prev: Compiling with Hobbit, Up: Top File: hobbit.info, Node: The Language Compiled, Next: Performance of Compiled Code, Prev: Compiling with Hobbit, Up: Top
3 The Language Compiled 3 The Language Compiled
*********************** ***********************
Calls to `load' or `require' occurring at the top level of a file being Calls to 'load' or 'require' occurring at the top level of a file being
compiled are ignored. Calls to `load' or `require' within a procedure compiled are ignored. Calls to 'load' or 'require' within a procedure
are compiled to call (interpreted) `load' or `require' as appropriate. are compiled to call (interpreted) 'load' or 'require' as appropriate.
Several SCM and SLIB extensions to the Scheme report are recognized by Several SCM and SLIB extensions to the Scheme report are recognized by
hobbit as Scheme primitives. hobbit as Scheme primitives.
* Menu: * Menu:
* Macros:: * Macros::
* SCM Primitive Procedures:: * SCM Primitive Procedures::
* SLIB Logical Procedures:: * SLIB Logical Procedures::
* Fast Integer Calculations:: * Fast Integer Calculations::
skipping to change at line 517 skipping to change at line 515
3.1 Macros 3.1 Macros
========== ==========
The Common-lisp style defmacro implemented in SCM is recognized and The Common-lisp style defmacro implemented in SCM is recognized and
procedures defined by defmacro are expanded during compilation. procedures defined by defmacro are expanded during compilation.
_Note Bene:_ any macro used in a compiled file must be also defined in _Note Bene:_ any macro used in a compiled file must be also defined in
one of the compiled files. one of the compiled files.
`#.<EXPRESSION>' is read as the object resulting from the evaluation of '#.<EXPRESSION>' is read as the object resulting from the evaluation of
<EXPRESSION>. The calculation is performed during compile time. Thus <EXPRESSION>. The calculation is performed during compile time. Thus
<EXPRESSION> must not contain variables defined or set! in the compiled <EXPRESSION> must not contain variables defined or set! in the compiled
file. file.
 
File: hobbit.info, Node: SCM Primitive Procedures, Next: SLIB Logical Procedur es, Prev: Macros, Up: The Language Compiled File: hobbit.info, Node: SCM Primitive Procedures, Next: SLIB Logical Procedur es, Prev: Macros, Up: The Language Compiled
3.2 SCM Primitive Procedures 3.2 SCM Primitive Procedures
============================ ============================
skipping to change at line 542 skipping to change at line 540
speed): speed):
real-sqrt real-exp real-ln real-expt real-sin real-cos real-tan real-sqrt real-exp real-ln real-expt real-sin real-cos real-tan
real-asin real-acos real-atan real-sinh real-cosh real-tanh real-asinh real-asin real-acos real-atan real-sinh real-cosh real-tanh real-asinh
real-acosh real-atanh real-acosh real-atanh
_Note Bene:_ These procedures are compiled to faster code than the _Note Bene:_ These procedures are compiled to faster code than the
corresponding generic versions sqrt, abs, ... expt. corresponding generic versions sqrt, abs, ... expt.
A selection of other extra primitives in SCM is also recognized as A selection of other extra primitives in SCM is also recognized as
primitives. eg. get-internal-run-time, quit, abort, restart, chdir, primitives. eg. get-internal-run-time, quit, abort, restart, chdir,
delete-file, rename-file. delete-file, rename-file.
 
File: hobbit.info, Node: SLIB Logical Procedures, Next: Fast Integer Calculati ons, Prev: SCM Primitive Procedures, Up: The Language Compiled File: hobbit.info, Node: SLIB Logical Procedures, Next: Fast Integer Calculati ons, Prev: SCM Primitive Procedures, Up: The Language Compiled
3.3 SLIB Logical Procedures 3.3 SLIB Logical Procedures
=========================== ===========================
The following bitwise procedures in the scheme library file The following bitwise procedures in the scheme library file
`logical.scm' are compiled directly to fast C operations on immediate 'logical.scm' are compiled directly to fast C operations on immediate
integers (small 30-bit integers) (Scheme library funs in the upper row, integers (small 30-bit integers) (Scheme library funs in the upper row,
C ops below): C ops below):
logand logior logxor lognot logsleft logsright logand logior logxor lognot logsleft logsright
& | ^ ~ << >> & | ^ ~ << >>
The following alternative names logical:logand, logical:logior, The following alternative names logical:logand, logical:logior,
logical:logxor, logical:lognot, and ash are compiled for the generic logical:logxor, logical:lognot, and ash are compiled for the generic
case, not immediate-integers-only and are thus much slower. case, not immediate-integers-only and are thus much slower.
Notice that the procedures logsleft, logsright are NOT in the the Notice that the procedures logsleft, logsright are NOT in the the
library file `logical.scm:' the universal procedure ash is instead. library file 'logical.scm:' the universal procedure ash is instead.
Procedures ash, logcount, integer-length, integer-expt, bit-extract, Procedures ash, logcount, integer-length, integer-expt, bit-extract,
ipow-by-squaring, in `logical.scm' are not primtives and they are all ipow-by-squaring, in 'logical.scm' are not primtives and they are all
compiled into calls to interpreted code. compiled into calls to interpreted code.
logsleft and logsright are defined for non-compiled use in the file logsleft and logsright are defined for non-compiled use in the file
`scmhob.scm' included in the SCM distribution. 'scmhob.scm' included in the SCM distribution.
 
File: hobbit.info, Node: Fast Integer Calculations, Next: Force and Delay, Pr ev: SLIB Logical Procedures, Up: The Language Compiled File: hobbit.info, Node: Fast Integer Calculations, Next: Force and Delay, Pr ev: SLIB Logical Procedures, Up: The Language Compiled
3.4 Fast Integer Calculations 3.4 Fast Integer Calculations
============================= =============================
The following primitives are for immediate (30-bit) integer-only The following primitives are for immediate (30-bit) integer-only
arithmetics. The are compiled directly into the corresponding C arithmetics. The are compiled directly into the corresponding C
operations plus some bitshifts if necessary. They are good for speed in operations plus some bitshifts if necessary. They are good for speed in
case the compiled program uses BOTH generic arithmetics (reals, bignums) case the compiled program uses BOTH generic arithmetics (reals, bignums)
and immediate (30-bit) integer arithmetics. These procedures are much and immediate (30-bit) integer arithmetics. These procedures are much
faster than corresponding generic procedures taking also reals and faster than corresponding generic procedures taking also reals and
bignums. There is no point in using these unless the program as a whole bignums. There is no point in using these unless the program as a whole
is compiled using generic arithmetics, since otherwise all the is compiled using generic arithmetics, since otherwise all the
arithmetics procedures are compiled directly into corresponding C arithmetics procedures are compiled directly into corresponding C
operations anyway. operations anyway.
_Note Bene:_ These primitives are NOT defined in SCM or its libraries. _Note Bene:_ These primitives are NOT defined in SCM or its libraries.
For non-compiled use they are defined in the file `scmhob.scm' included For non-compiled use they are defined in the file 'scmhob.scm' included
in the SCM distribution. in the SCM distribution.
%negative? %number? %> %>= %= %<= %< %negative? %number? %> %>= %= %<= %<
%positive? %zero? %eqv? %+ %- %* %/ %positive? %zero? %eqv? %+ %- %* %/
 
File: hobbit.info, Node: Force and Delay, Next: Suggestions for writing fast c ode, Prev: Fast Integer Calculations, Up: The Language Compiled File: hobbit.info, Node: Force and Delay, Next: Suggestions for writing fast c ode, Prev: Fast Integer Calculations, Up: The Language Compiled
3.5 Force and Delay 3.5 Force and Delay
=================== ===================
The nonessential procedure `force' and syntax `delay' are implemented The nonessential procedure 'force' and syntax 'delay' are implemented
exactly as suggested in the report 4. This implementation deviates exactly as suggested in the report 4. This implementation deviates
internally from the implementation of `force' and `delay' in the SCM internally from the implementation of 'force' and 'delay' in the SCM
interpeter, thus it is incorrect to pass a promise created by `delay' interpeter, thus it is incorrect to pass a promise created by 'delay' in
in the compiled code to the `force' used by interpreter, and vice-versa the compiled code to the 'force' used by interpreter, and vice-versa for
for the promises created by the interpreter. the promises created by the interpreter.
 
File: hobbit.info, Node: Suggestions for writing fast code, Prev: Force and De lay, Up: The Language Compiled File: hobbit.info, Node: Suggestions for writing fast code, Prev: Force and De lay, Up: The Language Compiled
3.6 Suggestions for writing fast code 3.6 Suggestions for writing fast code
===================================== =====================================
The following suggestions may help you to write well-optimizable and The following suggestions may help you to write well-optimizable and
fast code for the hobbit-scm combination. Roughly speaking, the main fast code for the hobbit-scm combination. Roughly speaking, the main
points are: points are:
skipping to change at line 636 skipping to change at line 634
roughly speaking, explicit lambda-terms and call/cc) in roughly speaking, explicit lambda-terms and call/cc) in
speed-critical parts, speed-critical parts,
* using special options and fast-compiled primitives of the compiler. * using special options and fast-compiled primitives of the compiler.
Here come the details. Here come the details.
1. Immediate arithmetics (ie using small, up to 30 bits integers) is 1. Immediate arithmetics (ie using small, up to 30 bits integers) is
much faster than generic (reals and bignums) arithmetics. If you much faster than generic (reals and bignums) arithmetics. If you
have to use generic arithmetic in your program, then try to use have to use generic arithmetic in your program, then try to use
special immediate arithmetics operations `%=', `%<=', `%+', `%*', special immediate arithmetics operations '%=', '%<=', '%+', '%*',
... for speed-critical parts of the program whenever possible. ... for speed-critical parts of the program whenever possible.
Also, if you use bitwise logical operations, try to use the Also, if you use bitwise logical operations, try to use the
immediate-integer-only versions immediate-integer-only versions
logand logior logxor lognot logsleft logsright logand logior logxor lognot logsleft logsright
and not `logical:logand' or `ash', for example. and not 'logical:logand' or 'ash', for example.
2. Due to its inner stack-based architecture, the generic (not 2. Due to its inner stack-based architecture, the generic (not
escape-only) continuations are very slow in SCM. Thus they are escape-only) continuations are very slow in SCM. Thus they are also
also slow in compiled code. Try to avoid continuations (calls to slow in compiled code. Try to avoid continuations (calls to the
the procedure call-with-current-continuation and calls to the procedure call-with-current-continuation and calls to the
continuations it produces) in speed-critical parts. continuations it produces) in speed-critical parts.
3. In speed-critical parts of your program try to avoid using 3. In speed-critical parts of your program try to avoid using
procedures which are redefined or defined by set!: procedures which are redefined or defined by set!:
(set! bar +) (set! bar +)
(set! f (lambda (x) (if (zero? x) 1 (* x (f (- x 1)))))) (set! f (lambda (x) (if (zero? x) 1 (* x (f (- x 1))))))
anywhere in the compiled program. Avoid using compiler flags anywhere in the compiled program. Avoid using compiler flags
(*note Hobbit Options::): (*note Hobbit Options::):
(define compile-all-proc-redefined T) (define compile-all-proc-redefined T)
(define compile-new-proc-redefined T) (define compile-new-proc-redefined T)
4. Do not use complicated higher-order procedures in speed-critical 4. Do not use complicated higher-order procedures in speed-critical
parts. By "complicated" we mean "not clonable", where clonability parts. By "complicated" we mean "not clonable", where clonability
is defined in the following way (_Note Bene:_ the primitives `map' is defined in the following way (_Note Bene:_ the primitives 'map'
and `for-each' are considered clonable and do not inflict a speed and 'for-each' are considered clonable and do not inflict a speed
penalty). penalty).
A higher-order procedure (HOP for short) is defined as a procedure A higher-order procedure (HOP for short) is defined as a procedure
with some of its formal arguments occuring in the procedure body in with some of its formal arguments occuring in the procedure body in
a function position, that is, as a first element of a list. Such a function position, that is, as a first element of a list. Such
an argument is called a "higher-order argument". an argument is called a "higher-order argument".
A HOP `bar' is clonable iff it satisfies the following four A HOP 'bar' is clonable iff it satisfies the following four
conditions: conditions:
1. `bar' is defined as 1. 'bar' is defined as
(define bar (lambda ...)) (define bar (lambda ...))
or or
(define (bar ...) ...) (define (bar ...) ...)
on top level and bar is not redefined anywhere. on top level and bar is not redefined anywhere.
2. the name `bar' occurs inside the body of bar only in a 2. the name 'bar' occurs inside the body of bar only in a
function position and not inside an internal lambda-term. function position and not inside an internal lambda-term.
3. Let f be a higher-order argument of bar. Any occurrence of f 3. Let f be a higher-order argument of bar. Any occurrence of f
in bar has one of the following two forms: in bar has one of the following two forms:
* f occurs in a function position, * f occurs in a function position,
* f is passed as an argument to bar and in the call it * f is passed as an argument to bar and in the call it
occurs in the same position as in the argument list. occurs in the same position as in the argument list.
4. Let f be a higher-order argument of bar. f does not occur 4. Let f be a higher-order argument of bar. f does not occur
inside a lambda-term occurring in bar. inside a lambda-term occurring in bar.
Examples: Examples:
If `member-if' is defined on top level and is not redefined If 'member-if' is defined on top level and is not redefined
anywhere, then `member-if' is a clonable HOP: anywhere, then 'member-if' is a clonable HOP:
(define (member-if fn lst) (define (member-if fn lst)
(if (fn (car lst)) (if (fn (car lst))
lst lst
(member-if fn (cdr lst)) )) (member-if fn (cdr lst)) ))
member-if-not is not a clonable HOP (fn occurs in a member-if-not is not a clonable HOP (fn occurs in a
lambdaterm): lambdaterm):
(define (member-if-not fn lst) (define (member-if-not fn lst)
skipping to change at line 740 skipping to change at line 737
(define plus (define plus
(lambda (x) (lambda (x)
(lambda (y) (+ y x)) )) (lambda (y) (+ y x)) ))
returns a procedure. returns a procedure.
6. A generalisation of the previous case 5: 6. A generalisation of the previous case 5:
In speed-critical parts avoid using lambda-terms except in In speed-critical parts avoid using lambda-terms except in
non-set! function definitions like non-set! function definitions like
(define foo (lambda ...)), (define foo (lambda ...)),
(let ((x 1) (f (lambda ...))) ...) (let ((x 1) (f (lambda ...))) ...)
(let* ((x 1) (f (lambda ...))) ...) (let* ((x 1) (f (lambda ...))) ...)
(let name ((x 1) (f (lambda ...))) ...) (let name ((x 1) (f (lambda ...))) ...)
(letrec ((f (lambda ...)) (g (lambda ...))) ...) (letrec ((f (lambda ...)) (g (lambda ...))) ...)
or as arguments to clonable HOP-s or primitives map and or as arguments to clonable HOP-s or primitives map and
for-each, like for-each, like
skipping to change at line 767 skipping to change at line 764
except in a function position (first element of a list) or as except in a function position (first element of a list) or as
an argument to a clonable HOP, map or for-each. an argument to a clonable HOP, map or for-each.
Lambda-terms conforming to the current point are said to be Lambda-terms conforming to the current point are said to be
liftable. liftable.
Examples: Examples:
(define (bar x) (let ((f car)) (f (f x)))) (define (bar x) (let ((f car)) (f (f x))))
has `car' in a non-function and non-HOP-argument position in has 'car' in a non-function and non-HOP-argument position in
`(f car)', thus it is slower than '(f car)', thus it is slower than
(define (bar x) (let ((f 1)) (car (car x)))) (define (bar x) (let ((f 1)) (car (car x))))
Similarly, Similarly,
(define (bar y z w) (define (bar y z w)
(let ((f (lambda (x) (+ x y)))) (let ((f (lambda (x) (+ x y))))
(set! w f) (set! w f)
(cons (f (car z)) (cons (f (car z))
(map f z) ))) (map f z) )))
has `f' occurring in a non-function position in `(set! w f)', has 'f' occurring in a non-function position in '(set! w f)',
thus the lambda-term `(lambda (x) (+ x y))' is not liftable thus the lambda-term '(lambda (x) (+ x y))' is not liftable
and the upper `bar' is thus slower than the following and the upper 'bar' is thus slower than the following
equivalent `bar' with a liftable inner lambda-term: equivalent 'bar' with a liftable inner lambda-term:
(define (bar y z w) (define (bar y z w)
(let ((f (lambda (x) (+ x y)))) (let ((f (lambda (x) (+ x y))))
(set! w 0) (set! w 0)
(cons (f (car z)) (cons (f (car z))
(map f z) ))) (map f z) )))
Using a procedure bar defined as Using a procedure bar defined as
(define bar (let ((x 1)) (lambda (y) (set! x y) (+ x y)))) (define bar (let ((x 1)) (lambda (y) (set! x y) (+ x y))))
skipping to change at line 805 skipping to change at line 802
is slower than using a procedure bar defined as is slower than using a procedure bar defined as
(define *bar-x* 1) (define *bar-x* 1)
(define bar (lambda (y) (set! *bar-x* y) (+ *bar-x* y))) (define bar (lambda (y) (set! *bar-x* y) (+ *bar-x* y)))
since the former definition contains a non-liftable since the former definition contains a non-liftable
lambda-term. lambda-term.
7. Try to minimize the amount of consing in the speed-critical 7. Try to minimize the amount of consing in the speed-critical
program fragments, that is, a number of applications of cons, program fragments, that is, a number of applications of cons,
list, map, quasiquote (`) and vector->list during the time list, map, quasiquote (') and vector->list during the time
program is running. `cons' (called also by `list', `map' and program is running. 'cons' (called also by 'list', 'map' and
`quasiquote') is translated into a C call to an internal cons 'quasiquote') is translated into a C call to an internal cons
procedure of the SCM interpreter. Excessive consing also procedure of the SCM interpreter. Excessive consing also
means that the garbage collection happens more often. Do means that the garbage collection happens more often. Do
`(verbose 3)' to see the amount of time used by garbage '(verbose 3)' to see the amount of time used by garbage
collection while your program is running. collection while your program is running.
Try to minimize the amount of creating new vectors, strings Try to minimize the amount of creating new vectors, strings
and symbols in the speed-critical program frgaments, that is, and symbols in the speed-critical program frgaments, that is,
a number of applications of make-vector, vector, list->vector, a number of applications of make-vector, vector, list->vector,
make-string, string-append, *->string, string->symbol. make-string, string-append, *->string, string->symbol.
Creating such objects takes typically much more time than Creating such objects takes typically much more time than
consing. consing.
8. The Scheme iteration construction `do' is compiled directly 8. The Scheme iteration construction 'do' is compiled directly
into the C iteration construction `for'. We can expect that into the C iteration construction 'for'. We can expect that
the C compiler has some knowledge about `for' in the the C compiler has some knowledge about 'for' in the
optimization stage, thus it is probably faster to use `do' optimization stage, thus it is probably faster to use 'do' for
for iteration than non-mutual tailrecursion (which is iteration than non-mutual tailrecursion (which is recognized
recognized by hobbit as such and is compiled into a jump to a by hobbit as such and is compiled into a jump to a beginning
beginning of a procedure) and certainly much faster than of a procedure) and certainly much faster than
non-tail-recursion or mutual tailrecursion (the latter is not non-tail-recursion or mutual tailrecursion (the latter is not
recognized by hobbit as such). recognized by hobbit as such).
9. Declare small nonrecursive programs which do not contain 9. Declare small nonrecursive programs which do not contain let-s
let-s or lambdaterms as being inlinable. or lambdaterms as being inlinable.
Declare globally defined variables which are never set! or Declare globally defined variables which are never set! or
redefined and whose value is a small integer, character or a redefined and whose value is a small integer, character or a
boolean, as being inlinable. *Note Hobbit Options::. boolean, as being inlinable. *Note Hobbit Options::.
10. If possible, declare vectors as being stable. *Note Speeding 10. If possible, declare vectors as being stable. *Note Speeding
up vectors: Hobbit Options. This gives a minor improvement up vectors: Hobbit Options. This gives a minor improvement in
in speed. speed.
11. If possible, declare critical global vars as being uninterned. 11. If possible, declare critical global vars as being
*Note Speeding up and hiding certain global variables: Hobbit uninterned. *Note Speeding up and hiding certain global
Options. This gives a minor improvement in speed. Declare variables: Hobbit Options. This gives a minor improvement in
the global variables which are never set! and have an speed. Declare the global variables which are never set! and
(unchanged) numeric or boolean value as being inlined. *Note have an (unchanged) numeric or boolean value as being inlined.
Hobbit Options::. *Note Hobbit Options::.
In addition, take the following into account: In addition, take the following into account:
* When using the C compiler to compile the C code output by * When using the C compiler to compile the C code output by
hobbit, always use strong optimizations (eg. `cc -xO3' for cc hobbit, always use strong optimizations (eg. 'cc -xO3' for cc
on Sun, `gcc -O2' or `gcc -O3' for gcc). Hobbit does not on Sun, 'gcc -O2' or 'gcc -O3' for gcc). Hobbit does not
attempt to do optimizations of the kind we anticipate from attempt to do optimizations of the kind we anticipate from the
the C compiler, therefore it often makes a big difference if C compiler, therefore it often makes a big difference if the C
the C compiler is run with a strong optimization flag or not. compiler is run with a strong optimization flag or not.
* hobbit does not give proper tailrecursion behaviour for mutual * hobbit does not give proper tailrecursion behaviour for mutual
tailrecursion (foo calling bar, bar calling foo tailrecursion (foo calling bar, bar calling foo
tailrecursively). tailrecursively).
Hobbit guarantees proper tailrecursive behaviour for Hobbit guarantees proper tailrecursive behaviour for
non-mutual tailrecursion (foo calling foo tailrecursively), non-mutual tailrecursion (foo calling foo tailrecursively),
provided that foo is not redefined anywhere and that foo is provided that foo is not redefined anywhere and that foo is
not a local function which occurs also in a non-function and not a local function which occurs also in a non-function and
non-clonable-HOP-argument position (i.e. cases 3 and 6 above). non-clonable-HOP-argument position (i.e. cases 3 and 6
above).
 
File: hobbit.info, Node: Performance of Compiled Code, Next: Principles of Com pilation, Prev: The Language Compiled, Up: Top File: hobbit.info, Node: Performance of Compiled Code, Next: Principles of Com pilation, Prev: The Language Compiled, Up: Top
4 Performance of Compiled Code 4 Performance of Compiled Code
****************************** ******************************
* Menu: * Menu:
* Gain in Speed:: * Gain in Speed::
skipping to change at line 890 skipping to change at line 888
File: hobbit.info, Node: Gain in Speed, Next: Benchmarks, Prev: Performance o f Compiled Code, Up: Performance of Compiled Code File: hobbit.info, Node: Gain in Speed, Next: Benchmarks, Prev: Performance o f Compiled Code, Up: Performance of Compiled Code
4.1 Gain in Speed 4.1 Gain in Speed
================= =================
The author has so far compiled and tested a number of large programs The author has so far compiled and tested a number of large programs
(theorem provers for various logics and hobbit itself). (theorem provers for various logics and hobbit itself).
The speedup for the provers was between 25 and 40 times for various The speedup for the provers was between 25 and 40 times for various
provable formulas. Comparison was made between the provers being provable formulas. Comparison was made between the provers being
interpreted and compiled with `gcc -O2 -DRECKLESS' on Sparcstation ELC interpreted and compiled with 'gcc -O2 -DRECKLESS' on Sparcstation ELC
in both cases. in both cases.
The provers were written with care to make the compiled version run The provers were written with care to make the compiled version run
fast. They do not perform excessive consing and they perform very fast. They do not perform excessive consing and they perform very
little arithmetic. little arithmetic.
According to experiments made by A. Jaffer, the compiled form of the According to experiments made by A. Jaffer, the compiled form of the
example program `pi.scm' was approximately 11 times faster than the example program 'pi.scm' was approximately 11 times faster than the
interpreted form. interpreted form.
As a comparison, his hand-coded C program for the same algorithm of As a comparison, his hand-coded C program for the same algorithm of
computing pi was about 12 times faster than the interpreted form. computing pi was about 12 times faster than the interpreted form.
`pi.scm' spends most of of its time in immediate arithmetics, 'pi.scm' spends most of of its time in immediate arithmetics, vector-ref
vector-ref and vector-set!. and vector-set!.
P. Kelloma"ki has reported a 20-fold speedup for his generic scheme P. Kelloma"ki has reported a 20-fold speedup for his generic scheme
debugger. T. Moore has reported a 16-fold speedup for a large debugger. T. Moore has reported a 16-fold speedup for a large
gate-level IC optimizer. gate-level IC optimizer.
Self-compilation speeds Hobbit up only ca 10 times. Self-compilation speeds Hobbit up only ca 10 times.
However, there are examples where the code compiled by hobbit runs However, there are examples where the code compiled by hobbit runs
actually slower than the same code running under interpreter: this may actually slower than the same code running under interpreter: this may
happen in case the speed of the code relies on non-liftable closures happen in case the speed of the code relies on non-liftable closures and
and proper mutual tailrecursion. See for example the closure-intensive proper mutual tailrecursion. See for example the closure-intensive
benchmark CPSTAK in the following table. benchmark CPSTAK in the following table.
 
File: hobbit.info, Node: Benchmarks, Next: Benchmark Sources, Prev: Gain in S peed, Up: Performance of Compiled Code File: hobbit.info, Node: Benchmarks, Next: Benchmark Sources, Prev: Gain in S peed, Up: Performance of Compiled Code
4.2 Benchmarks 4.2 Benchmarks
============== ==============
We will present a table with the performance of three scheme systems on We will present a table with the performance of three scheme systems on
a number of benchmarks: interpreted SCM, byte-compiled VSCM and a number of benchmarks: interpreted SCM, byte-compiled VSCM and
skipping to change at line 947 skipping to change at line 945
FFT is real-arithmetic-intensive. FFT is real-arithmetic-intensive.
All times are in seconds. All times are in seconds.
SCM 4c0(U) and 1.1.5*(U) (the latter is the newest version of VSCM) are SCM 4c0(U) and 1.1.5*(U) (the latter is the newest version of VSCM) are
compiled and run by Matthias Blume on a DecStation 5000 (Ultrix). VSCM compiled and run by Matthias Blume on a DecStation 5000 (Ultrix). VSCM
is a bytecode-compiler using continuation-passing style, and is well is a bytecode-compiler using continuation-passing style, and is well
optimized for continuations and closures. optimized for continuations and closures.
SCM 4e2(S) and Hobbit4b(S) compiled (with `cc -xO3') and run by Tanel SCM 4e2(S) and Hobbit4b(S) compiled (with 'cc -xO3') and run by Tanel
Tammet on a Sun SS10 (lips.cs.chalmers.se). Hobbit is a Scheme-to-C Tammet on a Sun SS10 (lips.cs.chalmers.se). Hobbit is a Scheme-to-C
compiler for SCM, the code it produces does not do any checking. SCM compiler for SCM, the code it produces does not do any checking. SCM
and hobbit are not optimized for continuations. Hobbit is not and hobbit are not optimized for continuations. Hobbit is not optimized
optimized for closures and proper mutual tailrecursion. for closures and proper mutual tailrecursion.
SCM and Hobbit benchmarks were run giving ca 8 MB of free heap space SCM and Hobbit benchmarks were run giving ca 8 MB of free heap space
before each test. before each test.
Benchmark |SCM 4c0(U) 1.1.5*(U)| SCM 4e2(S) Hobbit4b(S) Benchmark |SCM 4c0(U) 1.1.5*(U)| SCM 4e2(S) Hobbit4b(S)
----------------|------------------------------------------------ ----------------|------------------------------------------------
Deriv | 3.40 3.86 | 2.9 0.18 Deriv | 3.40 3.86 | 2.9 0.18
Div-iter | 3.45 2.12 | 2.6 0.083 Div-iter | 3.45 2.12 | 2.6 0.083
Div-rec | 3.45 2.55 | 3.5 0.42 Div-rec | 3.45 2.55 | 3.5 0.42
TAK | 1.81 1.71 | 1.4 0.018 TAK | 1.81 1.71 | 1.4 0.018
skipping to change at line 1254 skipping to change at line 1252
* Statement-lifting:: Pass 4 * Statement-lifting:: Pass 4
* Higher-order Arglists:: Pass 5 * Higher-order Arglists:: Pass 5
* Typing and Constants:: Pass 6 * Typing and Constants:: Pass 6
 
File: hobbit.info, Node: Macro-Expansion and Analysis, Next: Building Closures , Prev: Principles of Compilation, Up: Principles of Compilation File: hobbit.info, Node: Macro-Expansion and Analysis, Next: Building Closures , Prev: Principles of Compilation, Up: Principles of Compilation
5.1 Expansion and Analysis 5.1 Expansion and Analysis
========================== ==========================
1. Macros defined by defmacro and all the quasiquotes are expanded 1. Macros defined by defmacro and all the quasiquotes are expanded and
and compiled into equivalent form without macros and quasiquotes. compiled into equivalent form without macros and quasiquotes.
For example, `(a , x) will be converted to (cons 'a (cons x '())). For example, '(a , x) will be converted to (cons 'a (cons x '())).
2. Define-s with the nonessential syntax like 2. Define-s with the nonessential syntax like
(define (foo x) ...) (define (foo x) ...)
are converted to defines with the essential syntax are converted to defines with the essential syntax
(define foo (lambda (x) ...)) (define foo (lambda (x) ...))
Non-top-level defines are converted into equivalent letrec-s. Non-top-level defines are converted into equivalent letrec-s.
skipping to change at line 1291 skipping to change at line 1289
(define foo (define foo
(lambda (x y) (lambda (x y)
(let* ((x__1 y) (let* ((x__1 y)
(z x) (z x)
(x__2 (+ z x__1))) (x__2 (+ z x__1)))
x__2))) x__2)))
4. In case the set of procedures defined in one letrec is actually not 4. In case the set of procedures defined in one letrec is actually not
wholly mutually recursive (eg, f1 calls f2, but f2 does not call wholly mutually recursive (eg, f1 calls f2, but f2 does not call
f1, or there are three procedures, f1, f2, f3 so that f1 and f2 f1, or there are three procedures, f1, f2, f3 so that f1 and f2 are
are mutually recursive but f3 is not called from f1 or f2 and it mutually recursive but f3 is not called from f1 or f2 and it does
does not call them, etc), it is possible to minimize the number of not call them, etc), it is possible to minimize the number of
additional variables passed to procedures. additional variables passed to procedures.
Thus letrec-s are split into ordered chunks using dependency Thus letrec-s are split into ordered chunks using dependency
analysis and topological sorting, to reduce the number of mutually analysis and topological sorting, to reduce the number of mutually
passed variables. Wherever possible, letrec-s are replaced by passed variables. Wherever possible, letrec-s are replaced by
let*-s inside these chunks. let*-s inside these chunks.
5. Normalization is performed. This converts a majority of scheme 5. Normalization is performed. This converts a majority of scheme
control procedures like `cond', `case', `or', `and' into control procedures like 'cond', 'case', 'or', 'and' into equivalent
equivalent terms using a small set of primitives. New variables terms using a small set of primitives. New variables may be
may be introduced in this phase. introduced in this phase.
In case a procedure like `or' or `and' occurs in the place where In case a procedure like 'or' or 'and' occurs in the place where
its value is treated as a boolean (eg. first argument of `if'), it its value is treated as a boolean (eg. first argument of 'if'), it
is converted into an analogous boolean-returning procedure, which is converted into an analogous boolean-returning procedure, which
will finally be represented by an analogous C procedure (eg. || or will finally be represented by an analogous C procedure (eg. || or
&&). &&).
Associative procedures are converted into structures of Associative procedures are converted into structures of
corresponding nonassociative procedures. List is converted to a corresponding nonassociative procedures. List is converted to a
structure of cons-s. structure of cons-s.
Map and for-each with more than two arguments are converted into an Map and for-each with more than two arguments are converted into an
equivalent do-cycle. map-s and for-each-s with two arguments are equivalent do-cycle. map-s and for-each-s with two arguments are
treated as if they were defined in the compiled file - the treated as if they were defined in the compiled file - the
definitions map1 and for-each1 are automatically included, if definitions map1 and for-each1 are automatically included, if
needed. needed.
There is an option in `hobbit.scm' to make all map-s and There is an option in 'hobbit.scm' to make all map-s and for-each-s
for-each-s be converted into equivalent do-loops, avoiding the use be converted into equivalent do-loops, avoiding the use of map1
of map1 and/or for-each1 altogether. and/or for-each1 altogether.
6. Code is analysed for determining which primitive names and 6. Code is analysed for determining which primitive names and compiled
compiled procedure names are assumed to be redefinable. procedure names are assumed to be redefinable.
7. Analysing HOP clonability: hobbit will find a list of clonable 7. Analysing HOP clonability: hobbit will find a list of clonable
HOP-s with information about higher-order arguments. HOP-s with information about higher-order arguments.
Criterias for HOP clonability are given in the section 6.4. Criterias for HOP clonability are given in the section 6.4.
8. Analysis of liftability: hobbit will determine which lambda-terms 8. Analysis of liftability: hobbit will determine which lambda-terms
have to be built as real closures (implemented as a vector where have to be built as real closures (implemented as a vector where
the first element is a pointer to a function and the rest contain the first element is a pointer to a function and the rest contain
values of environment variables or environment blocks of values of environment variables or environment blocks of
skipping to change at line 1357 skipping to change at line 1355
===================== =====================
Here Hobbit produces code for creating real closures for all the Here Hobbit produces code for creating real closures for all the
lambda-terms which are not marked as being liftable by the previous lambda-terms which are not marked as being liftable by the previous
liftability analysis. liftability analysis.
Global variables (eg x-glob) are translated as pointers (locations) to Global variables (eg x-glob) are translated as pointers (locations) to
SCM objects and used via a fetch: *x_glob (or a fetch macro SCM objects and used via a fetch: *x_glob (or a fetch macro
GLOBAL(x-glob) which translates to *x_glob). GLOBAL(x-glob) which translates to *x_glob).
While producing closures hobbit tries to minimize the indirection While producing closures hobbit tries to minimize the indirection levels
levels necessary. Generally a local variable x may have to be necessary. Generally a local variable x may have to be translated to an
translated to an element of a vector of local variables built in the element of a vector of local variables built in the procedure creating
procedure creating x. If x occurs in a non-liftable closure, the whole x. If x occurs in a non-liftable closure, the whole vector of local
vector of local variables is passed to a closure. variables is passed to a closure.
Such a translation using a local vector will only take place if either x Such a translation using a local vector will only take place if either x
is set! inside a non-liftable lambda-term or x is a name of a is set! inside a non-liftable lambda-term or x is a name of a
recursively defined non-liftable function, and the definition of x is recursively defined non-liftable function, and the definition of x is
irregular. The definition of x is irregular if x is given the irregular. The definition of x is irregular if x is given the
non-liftable recursive value T by extra computation, eg as non-liftable recursive value T by extra computation, eg as
(set! x (let ((u 1)) (lambda (y) (display u) (x (+ u 1))))) (set! x (let ((u 1)) (lambda (y) (display u) (x (+ u 1)))))
and not as a simple lambdaterm: and not as a simple lambdaterm:
(set! x (lambda (y) (display x) (x (+ y 1)))) (set! x (lambda (y) (display x) (x (+ y 1))))
In all the other cases a local scheme variable x is translated directly In all the other cases a local scheme variable x is translated directly
to a local C variable x having the type SCM (a 32-bit integer). If to a local C variable x having the type SCM (a 32-bit integer). If such
such an x occurs in a non-liftable closure, then only its value is an x occurs in a non-liftable closure, then only its value is passed to
passed to a closure via the closure-vector. In case the a closure via the closure-vector. In case the directly-translated
directly-translated variable x is passed to a liftable lambda-term variable x is passed to a liftable lambda-term where it is set!, then x
where it is set!, then x is passed indirectly by using its address &x. is passed indirectly by using its address &x. In the lifted lambda-term
In the lifted lambda-term it is then accessed via *. it is then accessed via *.
If all the variables x1, ..., xn created in a procedure can be If all the variables x1, ..., xn created in a procedure can be
translated directly as C variables, then the procedure does not create a translated directly as C variables, then the procedure does not create a
special vector for (a subset of) local variables. special vector for (a subset of) local variables.
An application (foo ...) is generally translated to C by an internal An application (foo ...) is generally translated to C by an internal
apply of the SCM interpreter: apply(GLOBAL(foo), ...). Using an apply of the SCM interpreter: apply(GLOBAL(foo), ...). Using an
internal apply is much slower than using direct a C function call, internal apply is much slower than using direct a C function call,
since: since:
* there is an extra fetch by GLOBAL(foo), * there is an extra fetch by GLOBAL(foo),
* internal apply performs some computations, * internal apply performs some computations,
* the arguments of foo are passed as a list constructed during * the arguments of foo are passed as a list constructed during
application: that is, there is a lot of expensive consing every application: that is, there is a lot of expensive consing every
time foo is applied via an internal apply. time foo is applied via an internal apply.
However, in case foo is either a name of a non-redefined primitive or a However, in case foo is either a name of a non-redefined primitive or a
name of a non-redefined liftable procedure, the application is name of a non-redefined liftable procedure, the application is
translated to C directly without the extra layer of calling apply: translated to C directly without the extra layer of calling apply:
foo(...). foo(...).
Sometimes lambda-lifting generates the case that some variable x is Sometimes lambda-lifting generates the case that some variable x is
skipping to change at line 1418 skipping to change at line 1414
Undefined procedures are assumed to be defined via interpreter and are Undefined procedures are assumed to be defined via interpreter and are
called using an internal apply. called using an internal apply.
 
File: hobbit.info, Node: Lambda-lifting, Next: Statement-lifting, Prev: Build ing Closures, Up: Principles of Compilation File: hobbit.info, Node: Lambda-lifting, Next: Statement-lifting, Prev: Build ing Closures, Up: Principles of Compilation
5.3 Lambda-lifting 5.3 Lambda-lifting
================== ==================
When this pass starts, all the real (nonliftable) closures have been When this pass starts, all the real (nonliftable) closures have been
translated to closure-creating code. The remaining lambda-terms are translated to closure-creating code. The remaining lambda-terms are all
all liftable. liftable.
Lambda-lifting is performed. That is, all procedures defined inside Lambda-lifting is performed. That is, all procedures defined inside
some other procedure (eg. in letrec) and unnamed lambda-terms are made some other procedure (eg. in letrec) and unnamed lambda-terms are made
top-level procedure definitions. Any N variables not bound in such top-level procedure definitions. Any N variables not bound in such
procedures which were bound in the surrounding procedure are given as procedures which were bound in the surrounding procedure are given as
extra N first parameters of the procedure, and whenever the procedure is extra N first parameters of the procedure, and whenever the procedure is
called, the values of these variables are given as extra N first called, the values of these variables are given as extra N first
arguments. arguments.
For example: For example:
(define foo (define foo
(lambda (x y) (lambda (x y)
skipping to change at line 1516 skipping to change at line 1512
return (*z = (u + x) + *z); return (*z = (u + x) + *z);
} }
 
File: hobbit.info, Node: Statement-lifting, Next: Higher-order Arglists, Prev : Lambda-lifting, Up: Principles of Compilation File: hobbit.info, Node: Statement-lifting, Next: Higher-order Arglists, Prev : Lambda-lifting, Up: Principles of Compilation
5.4 Statement-lifting 5.4 Statement-lifting
===================== =====================
As the scheme do-construction is compiled into C for, but for cannot As the scheme do-construction is compiled into C for, but for cannot
occur in all places in C (it is a statement), then if the do in a occur in all places in C (it is a statement), then if the do in a scheme
scheme procedure occurs in a place which will not be a statement in C, procedure occurs in a place which will not be a statement in C, the
the whole do-term is lifted out into a new top-level procedure whole do-term is lifted out into a new top-level procedure analogously
analogously to lambda-lifting. Any statement-lifted parts of some to lambda-lifting. Any statement-lifted parts of some procedure foo are
procedure foo are called foo_auxN, where N is a number. called foo_auxN, where N is a number.
The special C-ish procedure **return** is pushed into a scheme term as The special C-ish procedure **return** is pushed into a scheme term as
far as possible to extend the scope of statements in the resulting C far as possible to extend the scope of statements in the resulting C
program. For example, program. For example,
(define foo (define foo
(lambda (x y) (lambda (x y)
(if x (+ 1 y) (+ 2 y)) )) (if x (+ 1 y) (+ 2 y)) ))
is converted to is converted to
(define foo (define foo
(lambda (x y) (lambda (x y)
(if x (**return** (+ 1 y)) (**return** (+ 2 y))) )) (if x (**return** (+ 1 y)) (**return** (+ 2 y))) ))
Immediate tailrecursion (foo calling foo tailrecursively) is recognized Immediate tailrecursion (foo calling foo tailrecursively) is recognized
and converted into an assignment of new values to args and a jump to and converted into an assignment of new values to args and a jump to the
the beginning of the procedure body. beginning of the procedure body.
 
File: hobbit.info, Node: Higher-order Arglists, Next: Typing and Constants, P rev: Statement-lifting, Up: Principles of Compilation File: hobbit.info, Node: Higher-order Arglists, Next: Typing and Constants, P rev: Statement-lifting, Up: Principles of Compilation
5.5 Higher-order Arglists 5.5 Higher-order Arglists
========================= =========================
All procedures taking a list argument are converted into ordinary All procedures taking a list argument are converted into ordinary
non-list taking procedures and they are called with the list-making non-list taking procedures and they are called with the list-making
calls inserted. For example, calls inserted. For example,
skipping to change at line 1568 skipping to change at line 1564
(cons x (reverse y)) )) (cons x (reverse y)) ))
and any call to foo will make a list for a variable y. For example, and any call to foo will make a list for a variable y. For example,
(foo 1 2 3) (foo 1 2 3)
is converted to is converted to
(foo 1 (cons 2 (cons 3 '()))). (foo 1 (cons 2 (cons 3 '()))).
All higher-order procedure calls where an argument-term contains All higher-order procedure calls where an argument-term contains unbound
unbound variables will generate a new instance (provided it has not variables will generate a new instance (provided it has not been created
been created already) of this higher-order procedure, carrying the already) of this higher-order procedure, carrying the right amount of
right amount of free variables inside to right places. free variables inside to right places.
For example, if there is a following definition: For example, if there is a following definition:
(define (member-if fn lst) (define (member-if fn lst)
(if (fn (car lst)) (if (fn (car lst))
lst lst
(member-if fn (cdr lst)) )) (member-if fn (cdr lst)) ))
and a call and a call
(member-if (lambda (x) (eq? x y)) lst), (member-if (lambda (x) (eq? x y)) lst),
a new instance of member-if is created (if an analogous one has not a new instance of member-if is created (if an analogous one has not been
been created before): created before):
(define (member-if_inst1 tmp fn lst) (define (member-if_inst1 tmp fn lst)
(if (fn tmp (car lst)) (if (fn tmp (car lst))
lst lst
(member-if_inst1 tmp fn (cdr lst)) )) (member-if_inst1 tmp fn (cdr lst)) ))
and the call is converted to and the call is converted to
(member-if_inst1 y foo lst) (member-if_inst1 y foo lst)
skipping to change at line 1670 skipping to change at line 1666
 
File: hobbit.info, Node: The Aims of Developing Hobbit, Next: Manifest, Prev: About Hobbit, Up: About Hobbit File: hobbit.info, Node: The Aims of Developing Hobbit, Next: Manifest, Prev: About Hobbit, Up: About Hobbit
6.1 The Aims of Developing Hobbit 6.1 The Aims of Developing Hobbit
================================= =================================
1. Producing maximally fast C code from simple scheme code. 1. Producing maximally fast C code from simple scheme code.
By "simple" we mean code which does not rely on procedures By "simple" we mean code which does not rely on procedures
returning procedures (closures) and nontrivial forms of returning procedures (closures) and nontrivial forms of
higher-order procedures. All the latter are also compiled, but higher-order procedures. All the latter are also compiled, but the
the optimizations specially target simple code fragments. Hobbit optimizations specially target simple code fragments. Hobbit
performs global optimization in order to locate such fragments. performs global optimization in order to locate such fragments.
2. Producing C code which would preserve as much original scheme code 2. Producing C code which would preserve as much original scheme code
structure as possible, to enable using the output C code by a structure as possible, to enable using the output C code by a human
human programmer (eg. for introducing special optimizations programmer (eg. for introducing special optimizations possible in
possible in C). Also, this will hopefully help the C compiler to C). Also, this will hopefully help the C compiler to find better
find better optimizations. optimizations.
 
File: hobbit.info, Node: Manifest, Next: Author and Contributors, Prev: The A ims of Developing Hobbit, Up: About Hobbit File: hobbit.info, Node: Manifest, Next: Author and Contributors, Prev: The A ims of Developing Hobbit, Up: About Hobbit
6.2 Manifest 6.2 Manifest
============ ============
`hobbit.scm' the hobbit compiler. 'hobbit.scm' the hobbit compiler.
`scmhob.scm' the file defining some additional procedures recognized 'scmhob.scm' the file defining some additional procedures recognized
by hobbit as primitives. Use it with the interpreter by hobbit as primitives. Use it with the interpreter
only. only.
`scmhob.h' the common headerfile for hobbit-compiled C files. 'scmhob.h' the common headerfile for hobbit-compiled C files.
`hobbit.texi' documentation for hobbit. 'hobbit.texi' documentation for hobbit.
 
File: hobbit.info, Node: Author and Contributors, Next: Future Improvements, Prev: Manifest, Up: About Hobbit File: hobbit.info, Node: Author and Contributors, Next: Future Improvements, Prev: Manifest, Up: About Hobbit
6.3 Author and Contributors 6.3 Author and Contributors
=========================== ===========================
Tanel Tammet Tanel Tammet
Department of Computing Science Department of Computing Science
Chalmers University of Technology Chalmers University of Technology
University of Go"teborg University of Go"teborg
S-41296 Go"teborg Sweden S-41296 Go"teborg Sweden
A. Jaffer (agj@alum.mit.edu), the author of SCM, has been of major help A. Jaffer (agj@alum.mit.edu), the author of SCM, has been of major help
with a number of suggestions and hacks, especially concerning the with a number of suggestions and hacks, especially concerning the
interface between compiled code and the SCM interpreter. interface between compiled code and the SCM interpreter.
Several people have helped with suggestions and detailed bug reports, Several people have helped with suggestions and detailed bug reports,
e.g. David J. Fiander (davidf@mks.com), Gordon Oulsnam e.g. David J. Fiander (davidf@mks.com), Gordon Oulsnam
(STCS8004@IRUCCVAX.UCC.IE), Pertti Kelloma"ki (pk@cs.tut.fi), Dominique (STCS8004@IRUCCVAX.UCC.IE), Pertti Kelloma"ki (pk@cs.tut.fi), Dominique
de Waleffe (ddw2@sunbim.be) Terry Moore (tmm@databook.com), Marshall de Waleffe (ddw2@sunbim.be) Terry Moore (tmm@databook.com), Marshall
Abrams (ab2r@midway.uchicago.edu). Georgy K. Bronnikov Abrams (ab2r@midway.uchicago.edu). Georgy K. Bronnikov
(goga@bronnikov.msk.su), Bernard Urban (Bernard.URBAN@meteo.fr), (goga@bronnikov.msk.su), Bernard Urban (Bernard.URBAN@meteo.fr), Charlie
Charlie Xiaoli Huang, Tom Lord (lord@cygnus.com), Xiaoli Huang, Tom Lord (lord@cygnus.com), NMICHAEL@us.oracle.com, Lee
NMICHAEL@us.oracle.com, Lee Iverson (leei@ai.sri.com), Burt Leavenworth Iverson (leei@ai.sri.com), Burt Leavenworth (EDLSOFT@aol.com).
(EDLSOFT@aol.com).
 
File: hobbit.info, Node: Future Improvements, Next: Release History, Prev: Au thor and Contributors, Up: About Hobbit File: hobbit.info, Node: Future Improvements, Next: Release History, Prev: Au thor and Contributors, Up: About Hobbit
6.4 Future Improvements 6.4 Future Improvements
======================= =======================
1. Optimisations: 1. Optimisations:
* the calls to internal apply: we'd like to avoid the excessive * the calls to internal apply: we'd like to avoid the excessive
consing of always building the list of arguments. consing of always building the list of arguments.
* speeding up the creation of a vector for assignable * speeding up the creation of a vector for assignable
closure-variables closure-variables
* several peephole optimisations. * several peephole optimisations.
2. Improve Variable creation and naming to avoid C function name 2. Improve Variable creation and naming to avoid C function name
clashes. clashes.
3. Report 4 macros. 3. Report 4 macros.
4. Better error-checking. 4. Better error-checking.
5. Better liftability analysis. 5. Better liftability analysis.
skipping to change at line 1757 skipping to change at line 1750
8. Fast real-only arithmetics: $eqv, $=, $>, $+, $*, etc. 8. Fast real-only arithmetics: $eqv, $=, $>, $+, $*, etc.
 
File: hobbit.info, Node: Release History, Prev: Future Improvements, Up: Abou t Hobbit File: hobbit.info, Node: Release History, Prev: Future Improvements, Up: Abou t Hobbit
6.5 Release History 6.5 Release History
=================== ===================
[In February 2002, hobbit5x was integrated into the SCM [In February 2002, hobbit5x was integrated into the SCM
distribution. Changes since then are recorded in `scm/ChangeLog'.] distribution. Changes since then are recorded in 'scm/ChangeLog'.]
hobbit4d: hobbit4d:
* the incorrect translation of char>?, char-ci>?, char>=?, * the incorrect translation of char>?, char-ci>?, char>=?,
char-ci>=? string>?, string-ci>?, string-ci>=?, string>=? char-ci>=? string>?, string-ci>?, string-ci>=?, string>=?
reported by Burt Leavenworth (EDLSOFT@aol.com) was fixed. reported by Burt Leavenworth (EDLSOFT@aol.com) was fixed.
* the name clash bug for new variables new_varN occurring in * the name clash bug for new variables new_varN occurring in
non-liftable closures (reported by Lee Iverson non-liftable closures (reported by Lee Iverson
(leei@ai.sri.com)) was fixed. (leei@ai.sri.com)) was fixed.
* the major COPYRIGHT change: differently from all the previous * the major COPYRIGHT change: differently from all the previous
versions of Hobbit, hobbit4d is Free Software. versions of Hobbit, hobbit4d is Free Software.
hobbit4c: hobbit4c:
* a liftability-analysis bug for for-each and map reported by * a liftability-analysis bug for for-each and map reported by
Lee Iverson (leei@ai.sri.com) has been fixed. Lee Iverson (leei@ai.sri.com) has been fixed.
* The output C code does not contain the unnecessary ;-s on * The output C code does not contain the unnecessary ;-s on
separate lines any more. separate lines any more.
hobbit4b: hobbit4b:
The following bugs have been fixed: The following bugs have been fixed:
* Erroneous treatment of [ and ] inside symbols, reported by A. * Erroneous treatment of [ and ] inside symbols, reported by A.
Jaffer (agj@alum.mit.edu). Jaffer (agj@alum.mit.edu).
* A bug in the liftability analysis, reported by A. Jaffer * A bug in the liftability analysis, reported by A. Jaffer
(agj@alum.mit.edu). (agj@alum.mit.edu).
* A bug occurring in case arguments are evaluated right-to-left, * A bug occurring in case arguments are evaluated right-to-left,
which happens with Hobbit compiled by gcc on GNU/Linux. which happens with Hobbit compiled by gcc on GNU/Linux.
Reported and patched by George K. Bronnikov Reported and patched by George K. Bronnikov
(goga@bronnikov.msk.su) (goga@bronnikov.msk.su)
* A closure-building bug sometimes leading to a serious loss of * A closure-building bug sometimes leading to a serious loss of
efficiency (liftability not recognized), reported by efficiency (liftability not recognized), reported by
NMICHAEL@us.oracle.com. NMICHAEL@us.oracle.com.
* A bug in the liftability analysis (non-liftable lambda-term * A bug in the liftability analysis (non-liftable lambda-term
inside a liftable lambda-term) reported by Lee Iverson inside a liftable lambda-term) reported by Lee Iverson
(leei@ai.sri.com) (leei@ai.sri.com)
hobbit4a: hobbit4a:
Several bugs found in version4x are fixed. Several bugs found in version4x are fixed.
hobbit4x (not public): hobbit4x (not public):
* A major overhaul: Hobbit is now able to compile full scheme, * A major overhaul: Hobbit is now able to compile full scheme,
not just the fast liftable-clonable fragment. not just the fast liftable-clonable fragment.
skipping to change at line 1820 skipping to change at line 1806
hobbit3d: hobbit3d:
bugs found in the version 3c are fixed. bugs found in the version 3c are fixed.
hobbit3c: hobbit3c:
* the form * the form
(define foo (let ((x1 <t1>) ... (xn <tn>)) (lambda ...))) (define foo (let ((x1 <t1>) ... (xn <tn>)) (lambda ...)))
is now supported for all terms <ti> except procedures defined is now supported for all terms <ti> except procedures defined
in the compiled files. in the compiled files.
* macros are partially supported by doing a preprocessing pass * macros are partially supported by doing a preprocessing pass
using the procedures pprint-filter-file and defmacro:expand* using the procedures pprint-filter-file and defmacro:expand*
defined in slib. defined in slib.
* the file 'scmhob.scm' defining hobbit-recognized nonstandard
* the file `scmhob.scm' defining hobbit-recognized nonstandard
procedures is created. procedures is created.
* the documentation is improved (thanks go to Aubrey for * the documentation is improved (thanks go to Aubrey for
suggestions). suggestions).
hobbit3b: hobbit3b:
* Aubrey fixed some problems with the version 3. * Aubrey fixed some problems with the version 3.
* It is now OK to define procedures "by name" on top level. * It is now OK to define procedures "by name" on top level.
* It is now OK to apply "apply", etc to procedures defined in * It is now OK to apply "apply", etc to procedures defined in
the compiled file. Compiled procedures may now be passed to the compiled file. Compiled procedures may now be passed to
procedures not defined but still called in the compiled files. procedures not defined but still called in the compiled files.
hobbit3: hobbit3:
* Generic arithmetic supported by SCM (exact and inexact reals, * Generic arithmetic supported by SCM (exact and inexact reals,
bignums) is made available. bignums) is made available.
* The #. special syntactic form of SCM is made available.
* The #. special syntactic form of SCM is made available.
* Procedures with chars are compiled open-coded, making them * Procedures with chars are compiled open-coded, making them
faster. faster.
* The bug concerning strings containing an embedded \nl char is * The bug concerning strings containing an embedded \nl char is
corrected (thanks to Terry Moore, (tmm@databook.com)). corrected (thanks to Terry Moore, (tmm@databook.com)).
* The special declaration compile-stable-vectors for optimizing * The special declaration compile-stable-vectors for optimizing
vector access is introduced. vector access is introduced.
* Source code may contain top-level computations, top-level * Source code may contain top-level computations, top-level
loads are ignored. loads are ignored.
* The bug causing "or" to (sometimes) lose tailrecursiveness is * The bug causing "or" to (sometimes) lose tailrecursiveness is
corrected. corrected.
* Hobbit now allows the following very special form: * Hobbit now allows the following very special form:
(define foo (let ((bar bar)) (lambda ...))) (define foo (let ((bar bar)) (lambda ...)))
Notice `(bar bar)'. See the section 5 above. It will Notice '(bar bar)'. See the section 5 above. It will produce
produce wrong code if bar is redefined. wrong code if bar is redefined.
There were several versions of the 2-series, like 2.x, which There were several versions of the 2-series, like 2.x, which
were not made public. The changes introduced are present in were not made public. The changes introduced are present in
the version 3. the version 3.
hobbit2: hobbit2:
* The following bitwise procedures in the scheme library file * The following bitwise procedures in the scheme library file
`logical.scm' are compiled directly to C (Scheme library funs 'logical.scm' are compiled directly to C (Scheme library funs
in the upper row, C ops below): in the upper row, C ops below):
logand logior logxor lognot logsleft logsright logand logior logxor lognot logsleft logsright
& | ^ ~ << >> & | ^ ~ << >>
Notice that the procedures logsleft, logsright are NOT in the Notice that the procedures logsleft, logsright are NOT in the
the library file `logical.scm': the universal procedure ash the library file 'logical.scm': the universal procedure ash is
is instead. Procedures ash, logcount, integer-length, instead. Procedures ash, logcount, integer-length,
integer-expt, bit-extract in `logical.scm' are not recognized integer-expt, bit-extract in 'logical.scm' are not recognized
by hobbit. by hobbit.
hobbit1a3 (not public): hobbit1a3 (not public):
* the letrec-sorting bug often resulting in not recognizing * the letrec-sorting bug often resulting in not recognizing
procedures defined in letrec (or local defines) has been procedures defined in letrec (or local defines) has been
corrected. corrected.
* the primitives string and vector are now compiled correctly. * the primitives string and vector are now compiled correctly.
hobbit1a2 (not public): hobbit1a2 (not public):
* any fixed arity procedure (including primitives) may be * any fixed arity procedure (including primitives) may be passed
passed to any higher-order procedure by name. Variable arity to any higher-order procedure by name. Variable arity
procedures (eg primitives list, +, display and defined funs procedures (eg primitives list, +, display and defined funs
like `(define (foo x . y) x)') must not be passed to new like '(define (foo x . y) x)') must not be passed to new
defined higher-order funs. defined higher-order funs.
* some optimizations have been introduced for calls to map and * some optimizations have been introduced for calls to map and
for-each. for-each.
* (map list x y) bug has been corrected. * (map list x y) bug has been corrected.
* Corrected self-compilation name clash between call_cc and * Corrected self-compilation name clash between call_cc and
call-cc. call-cc.
hobbit1a1 (not public): hobbit1a1 (not public):
* named let is supported. * named let is supported.
* the inlining bug is fixed: all procedures declared to be * the inlining bug is fixed: all procedures declared to be
inlined are fully inlined, except when the flag inlined are fully inlined, except when the flag
*full-inlining-flag* is defined as #f. *full-inlining-flag* is defined as #f.
* the letrec (or in-procedure define) bug where local procedure * the letrec (or in-procedure define) bug where local procedure
names were not recognized, is fixed. names were not recognized, is fixed.
* documentation says explicitly that definitions like * documentation says explicitly that definitions like
(define foo (let ((x 0)) (lambda (y) ...))) (define foo (let ((x 0)) (lambda (y) ...)))
are assumed to be closure-returning procedures and are are assumed to be closure-returning procedures and are
prohibited. prohibited.
* documentation allows more liberty with passing procedures to * documentation allows more liberty with passing procedures to
higher-order funs by dropping the general requirement that higher-order funs by dropping the general requirement that
only unnamed lambda-terms may be passed. Still, primitives only unnamed lambda-terms may be passed. Still, primitives
and list-taking procedures may not be passed by name. and list-taking procedures may not be passed by name.
* documentation prohibits passing lambda-terms with free * documentation prohibits passing lambda-terms with free
variables to recursive calls of higher-order procedures in variables to recursive calls of higher-order procedures in the
the definition of a higher-order procedure. definition of a higher-order procedure.
hobbit1: hobbit1:
the first release the first release
 
File: hobbit.info, Node: Index, Prev: About Hobbit, Up: Top File: hobbit.info, Node: Index, Prev: About Hobbit, Up: Top
Index Index
***** *****
[index] [index]
* Menu: * Menu:
* compile->executable: Compiling And Linking. * compile->executable: Compiling And Linking.
(line 67) (line 66)
* compile-file: Compiling And Linking. * compile-file: Compiling And Linking.
(line 13) (line 12)
* hobbit: Compiling And Linking. * hobbit: Compiling And Linking.
(line 9) (line 8)
 
Tag Table: Tag Table:
Node: Top1024 Node: Top1023
Node: Introduction2112 Node: Introduction2112
Node: Compiling with Hobbit3428 Node: Compiling with Hobbit3429
Node: Compiling And Linking3686 Node: Compiling And Linking3686
Node: Error Detection8378 Node: Error Detection8378
Node: Hobbit Options9684 Node: Hobbit Options9684
Node: CC Optimizations16416 Node: CC Optimizations16415
Node: The Language Compiled17372 Node: The Language Compiled17372
Node: Macros18031 Node: Macros18031
Node: SCM Primitive Procedures18635 Node: SCM Primitive Procedures18635
Node: SLIB Logical Procedures19557 Node: SLIB Logical Procedures19559
Node: Fast Integer Calculations20712 Node: Fast Integer Calculations20714
Node: Force and Delay21846 Node: Force and Delay21848
Node: Suggestions for writing fast code22431 Node: Suggestions for writing fast code22433
Node: Performance of Compiled Code32630 Node: Performance of Compiled Code32642
Node: Gain in Speed32890 Node: Gain in Speed32902
Node: Benchmarks34475 Node: Benchmarks34487
Node: Benchmark Sources37575 Node: Benchmark Sources37587
Node: Destruct37921 Node: Destruct37933
Node: Recfib39508 Node: Recfib39520
Node: div-iter and div-rec39763 Node: div-iter and div-rec39775
Node: Hanoi40849 Node: Hanoi40861
Node: Tak41430 Node: Tak41442
Node: Ctak41785 Node: Ctak41797
Node: Takl42765 Node: Takl42777
Node: Cpstak43421 Node: Cpstak43433
Node: Pi44200 Node: Pi44212
Node: Principles of Compilation45333 Node: Principles of Compilation45345
Node: Macro-Expansion and Analysis45759 Node: Macro-Expansion and Analysis45771
Node: Building Closures49564 Node: Building Closures49578
Node: Lambda-lifting52455 Node: Lambda-lifting52468
Node: Statement-lifting55186 Node: Statement-lifting55200
Node: Higher-order Arglists56294 Node: Higher-order Arglists56308
Node: Typing and Constants58100 Node: Typing and Constants58114
Node: About Hobbit59364 Node: About Hobbit59378
Node: The Aims of Developing Hobbit59624 Node: The Aims of Developing Hobbit59638
Node: Manifest60515 Node: Manifest60529
Node: Author and Contributors60974 Node: Author and Contributors60988
Node: Future Improvements62027 Node: Future Improvements62042
Node: Release History62792 Node: Release History62805
Node: Index69590 Node: Index69576
 
End Tag Table End Tag Table
 End of changes. 135 change blocks. 
275 lines changed or deleted 240 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)