
The Benefits of NewtonScript
Portability
NTK compiles NewtonScript into machine code for a stack-based, virtual machine. Each Newton contains an interpreter for this virtual machine. This is the same approach that is used for the Java programming language. There are a couple of advantages to this approach:
- Applications you write today will run on Newtons of the future--even if they have different processors.
- Your compiled application is smaller than it would be if it were compiled for the native processor (the stack-based code is very compact).
There is one main disadvantage: your application is slower. This disadvantage can be addressed, however:
- NTK can generate native code for key, time-intensive functions in your application.
Your application grows slightly larger, but executes much more quickly. It continues to be portable, since these key functions are compiled in both native code and virtual machine code versions.
Note:
You specify which functions should have native code generated using the native keyword. Here's an example:
func native(a, b)
if a < b then
a
else
b;
You can declare types so that the compiler can generate more efficient code. The two types you can declare are int
and array
. Here's the same function which declares a
and b
to be integers:
func native(int a, int b)
if a < b then
a
else
b;
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996