The R Project SVN R

Rev

Rev 85994 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 85994 Rev 88251
Line 1265... Line 1265...
1265
        get(name, compilerOptions)
1265
        get(name, compilerOptions)
1266
}
1266
}
1267
@ %def getCompilerOption
1267
@ %def getCompilerOption
1268
 
1268
 
1269
The [[suppressAll]] function determines whether a context has its
1269
The [[suppressAll]] function determines whether a context has its
1270
[[supressAll]] property set to [[TRUE]].
1270
[[suppressAll]] property set to [[TRUE]].
1271
<<[[suppressAll]] function>>=
1271
<<[[suppressAll]] function>>=
1272
suppressAll <- function(cntxt)
1272
suppressAll <- function(cntxt)
1273
    identical(cntxt$suppressAll, TRUE)
1273
    identical(cntxt$suppressAll, TRUE)
1274
@ %def suppressAll
1274
@ %def suppressAll
1275
The [[suppressNoSuperAssignVar]] function determines whether a context has
1275
The [[suppressNoSuperAssignVar]] function determines whether a context has
Line 1502... Line 1502...
1502
would significantly complicate the compiler and the compiled code, and
1502
would significantly complicate the compiler and the compiled code, and
1503
carry at least some runtime penalty. The approach taken here is
1503
carry at least some runtime penalty. The approach taken here is
1504
therefore to permit the compiler to inline some functions when they
1504
therefore to permit the compiler to inline some functions when they
1505
are not visibly shadowed in the compiled code.  What the compiler is
1505
are not visibly shadowed in the compiled code.  What the compiler is
1506
permitted to do is determined by the setting of an optimization level.
1506
permitted to do is determined by the setting of an optimization level.
1507
The details are desctibed in Section \ref{sec:inlining}.
1507
The details are described in Section \ref{sec:inlining}.
1508
 
1508
 
1509
For the compiler to be able to decide whether is can inline a function
1509
For the compiler to be able to decide whether is can inline a function
1510
it needs to be able to determine whether there are any local variable
1510
it needs to be able to determine whether there are any local variable
1511
that might shadow a variable from a base package. This requires adding
1511
that might shadow a variable from a base package. This requires adding
1512
environment information to the compilation process.
1512
environment information to the compilation process.
Line 1812... Line 1812...
1812
[[quote]].  These might be shadowed by local definitions in a
1812
[[quote]].  These might be shadowed by local definitions in a
1813
surrounding function.  To allow for this we can add an optional
1813
surrounding function.  To allow for this we can add an optional
1814
variable [[shadowed]] for providing a character vector of names of
1814
variable [[shadowed]] for providing a character vector of names of
1815
variables with shadowing local definitions.
1815
variables with shadowing local definitions.
1816
 
1816
 
1817
The more sophisticated implementaiton is also slightly optimized to avoid
1817
The more sophisticated implementation is also slightly optimized to avoid
1818
recursive calls. [[findLocals1]] now, instead of searching through the full
1818
recursive calls. [[findLocals1]] now, instead of searching through the full
1819
transitive closure of language objects, only searches from the first, but
1819
transitive closure of language objects, only searches from the first, but
1820
returns what remains to be searched. The variables found are stored into an
1820
returns what remains to be searched. The variables found are stored into an
1821
environment, which avoids some extra calls and assures that each variable is
1821
environment, which avoids some extra calls and assures that each variable is
1822
listed at most once.
1822
listed at most once.
Line 2770... Line 2770...
2770
not.  [[ENDLOOPCNTXT]] terminates the context established by
2770
not.  [[ENDLOOPCNTXT]] terminates the context established by
2771
[[STARTLOOPCNTXT]] and pops it off the context stack.  The context
2771
[[STARTLOOPCNTXT]] and pops it off the context stack.  The context
2772
data is stored on the byte code interpreter stack; in the case of a
2772
data is stored on the byte code interpreter stack; in the case of a
2773
[[for]] loop some loop state information is duplicated on the stack by
2773
[[for]] loop some loop state information is duplicated on the stack by
2774
[[STARTLOOPCNTXT]] and removed again by [[ENDLOOPCNTXT]]. The byte
2774
[[STARTLOOPCNTXT]] and removed again by [[ENDLOOPCNTXT]]. The byte
2775
code intepreter stores the [[pc]] in a slot in the [[RCNTXT]]
2775
code interpreter stores the [[pc]] in a slot in the [[RCNTXT]]
2776
structure so it is available after a [[longjmp]] triggered by a
2776
structure so it is available after a [[longjmp]] triggered by a
2777
[[break]] for retrieving the label on the [[ENDLOOPCNTXT]]
2777
[[break]] for retrieving the label on the [[ENDLOOPCNTXT]]
2778
instruction.  An alternative would be to add separate
2778
instruction.  An alternative would be to add separate
2779
[[STARTFORLOOPCNTXT]] and [[ENDFORLOOPCNTXT]] instructions. Then the
2779
[[STARTFORLOOPCNTXT]] and [[ENDFORLOOPCNTXT]] instructions. Then the
2780
[[pc]] or the label could be stored on the note stack.
2780
[[pc]] or the label could be stored on the note stack.
Line 3238... Line 3238...
3238
    }
3238
    }
3239
}
3239
}
3240
@ %def cmpPrim2
3240
@ %def cmpPrim2
3241
 
3241
 
3242
The [[INCLNK]] and [[DECLNK]] instructions are used to protect
3242
The [[INCLNK]] and [[DECLNK]] instructions are used to protect
3243
evaluated arguents on the stack from modifications during evaluation
3243
evaluated arguments on the stack from modifications during evaluation
3244
of subsequent arguments. These instructions can be omitted if the
3244
of subsequent arguments. These instructions can be omitted if the
3245
subsequent argument evaluations cannot modify values on the stack.
3245
subsequent argument evaluations cannot modify values on the stack.
3246
With changes to stack protection this is mechanism is no longer
3246
With changes to stack protection this is mechanism is no longer
3247
needed, so the check just returns [[FALSE]].
3247
needed, so the check just returns [[FALSE]].
3248
<<[[checkNeedsInc]] function>>=
3248
<<[[checkNeedsInc]] function>>=
Line 3303... Line 3303...
3303
})
3303
})
3304
@ 
3304
@ 
3305
 
3305
 
3306
A number of one argument math functions are handled by the interpreter
3306
A number of one argument math functions are handled by the interpreter
3307
using the function [[math1]] in [[arithmetic.c]]. The [[MATH1.OP]]
3307
using the function [[math1]] in [[arithmetic.c]]. The [[MATH1.OP]]
3308
instruction handles these for compuled code. The instruction takes two
3308
instruction handles these for compiled code. The instruction takes two
3309
operands, an index for the call expression in the constant table, and
3309
operands, an index for the call expression in the constant table, and
3310
an index for the function to be called in a table of function
3310
an index for the function to be called in a table of function
3311
pointers. The table of names in the byte code compiler has to match
3311
pointers. The table of names in the byte code compiler has to match
3312
the function pointer array in the byte code interpreter.  It would
3312
the function pointer array in the byte code interpreter.  It would
3313
have been possible to use the same indices as the offset values used
3313
have been possible to use the same indices as the offset values used
Line 4324... Line 4324...
4324
  it at this time. But it would be good to be able to change it in the
4324
  it at this time. But it would be good to be able to change it in the
4325
  future.
4325
  future.
4326
\end{itemize}
4326
\end{itemize}
4327
 
4327
 
4328
Because of these issues the compiler implements slightly different
4328
Because of these issues the compiler implements slightly different
4329
semantics for complex assignment than the current intepreter.
4329
semantics for complex assignment than the current interpreter.
4330
\emph{Evaluation} semantics should be identical; the difference arises
4330
\emph{Evaluation} semantics should be identical; the difference arises
4331
in how intermediate values are managed and has some effect on results
4331
in how intermediate values are managed and has some effect on results
4332
produced by [[substitute]].  In particular, no intermediate [[*tmp*]]
4332
produced by [[substitute]].  In particular, no intermediate [[*tmp*]]
4333
value is used and therefore no cleanup frame is needed.  This does
4333
value is used and therefore no cleanup frame is needed.  This does
4334
mean that uses of the form
4334
mean that uses of the form
Line 5347... Line 5347...
5347
}
5347
}
5348
@ %def .onLoad
5348
@ %def .onLoad
5349
 
5349
 
5350
When [[enableJIT]] is set to 3, loops should be compiled before executing. 
5350
When [[enableJIT]] is set to 3, loops should be compiled before executing. 
5351
However, if the [[optimize]] option is set to 0 or 1, a compiled loop will
5351
However, if the [[optimize]] option is set to 0 or 1, a compiled loop will
5352
call to the same primitive function as is used by the AST interpretter (e.g. 
5352
call to the same primitive function as is used by the AST interpreter (e.g. 
5353
[[do_for]]), and the compilation would run into infinite recursion. 
5353
[[do_for]]), and the compilation would run into infinite recursion. 
5354
[[checkCompilerOptions]] will detect invalid combinations of [[enableJIT]]
5354
[[checkCompilerOptions]] will detect invalid combinations of [[enableJIT]]
5355
and [[optimize]] and report a warning.
5355
and [[optimize]] and report a warning.
5356
%% **** could also change the interface and atomically set enableJIT and optimize
5356
%% **** could also change the interface and atomically set enableJIT and optimize
5357
<<[[checkCompilerOptions]] function>>=
5357
<<[[checkCompilerOptions]] function>>=
Line 5722... Line 5722...
5722
\appendix
5722
\appendix
5723
\section{General utility functions}
5723
\section{General utility functions}
5724
This appendix provides a few general utility functions.
5724
This appendix provides a few general utility functions.
5725
 
5725
 
5726
The utility function [[pasteExpr]] is used in the error messages.
5726
The utility function [[pasteExpr]] is used in the error messages.
5727
%% **** use elipsis instead of collapse??
5727
%% **** use ellipsis instead of collapse??
5728
%% **** use error context or catch errors?
5728
%% **** use error context or catch errors?
5729
%% **** maybe don't need expression if we catch errors?
5729
%% **** maybe don't need expression if we catch errors?
5730
<<[[pasteExpr]] function>>=
5730
<<[[pasteExpr]] function>>=
5731
pasteExpr <- function(e, prefix = "\n    ") {
5731
pasteExpr <- function(e, prefix = "\n    ") {
5732
    de <- deparse(e)
5732
    de <- deparse(e)
Line 5979... Line 5979...
5979
@ %def nsName
5979
@ %def nsName
5980
 
5980
 
5981
 
5981
 
5982
\section{Experimental utilities}
5982
\section{Experimental utilities}
5983
 
5983
 
5984
This section presents two experimental utililities that, for now, are
5984
This section presents two experimental utilities that, for now, are
5985
not exported. The first is a simple byte code profiler. This requires
5985
not exported. The first is a simple byte code profiler. This requires
5986
that the file [[eval.c]] be compiled with [[BC_PROFILING]] enabled,
5986
that the file [[eval.c]] be compiled with [[BC_PROFILING]] enabled,
5987
which on [[gcc]]-compatible compilers will disable threaded code. The
5987
which on [[gcc]]-compatible compilers will disable threaded code. The
5988
byte code profiler uses the profile timer to record the active byte
5988
byte code profiler uses the profile timer to record the active byte
5989
code instruction at interrupt time. The function [[bcprof]] runs the
5989
code instruction at interrupt time. The function [[bcprof]] runs the