4 
A very incomplete introduction 
A very incomplete introduction 
5 
(by Matthias Blume (blume@research.belllabs.com)) 
(by Matthias Blume (blume@research.belllabs.com)) 
6 


7 

!!! Warning: this currently works on x86/Linux only! !!! 
8 


9 
The new NLFFI ("nolonger foreign function interface") is based on the 
The new NLFFI ("nolonger foreign function interface") is based on the 
10 
idea of datalevel interoperability: ML code (a mixture of 
idea of datalevel interoperability: ML code (a mixture of 
254 


255 
Arrays are secondclass values. Their (phantom) type is 
Arrays are secondclass values. Their (phantom) type is 
256 


257 
type ('t, 'f, 'n) arr 
type ('t, 'n) arr 
258 


259 
Here, 't is the type of the values stored in the array's individual 
Here, 't is the type of the values stored in the array's individual 
260 
elements, 'f here is the same as the 'f in the case of obj or ptr, 
elements, 'f here is the same as the 'f in the case of obj or ptr, 
278 


279 
The connection to array types is this: An array of size N has type 
The connection to array types is this: An array of size N has type 
280 


281 
('t, 'f, [N]) arr 
('t, [N]) arr 
282 


283 
iff "[N] dim" is the type assigned to N by our Dim construction. 
iff "[N] dim" is the type assigned to N by our Dim construction. 
284 


286 


287 
The C type (int[312]) is encoded as 
The C type (int[312]) is encoded as 
288 


289 
(sint, unit, dec dg3 dg1 dg2) arr 
(sint, dec dg3 dg1 dg2) arr 
290 


291 
In other words, if you "squint away" the "dec", the "dg"s, and the 
In other words, if you "squint away" the "dec", the "dg"s, and the 
292 
spaces, then the array dimension gets spelled out in decimal. 
spaces, then the array dimension gets spelled out in decimal. 
294 
4.2. Operations over arrays: 
4.2. Operations over arrays: 
295 


296 
Since array types are secondclass, there are no operations that 
Since array types are secondclass, there are no operations that 
297 
produce or consume values of type (?, ?, ?) arr. Instead, we use 
produce or consume values of type (?, ?) arr. Instead, we use 
298 
array objects of type ((?, ?, ?) arr, ?, ?) obj. 
array objects of type ((?, ?) arr, ?, ?) obj. 
299 


300 
Most operations related to array objects are in substructure Arr. 
Most operations related to array objects are in substructure Arr. 
301 


318 


319 
Function pointers have type 'f fptr where 'f is always instantiated 
Function pointers have type 'f fptr where 'f is always instantiated 
320 
to (A > B) for some A and B. This instantiation for 'f propagates 
to (A > B) for some A and B. This instantiation for 'f propagates 
321 
through all those 'f components of obj, ptr, or arrtypes whose 
through all those 'f components of obj, ptr, or T.typtypes whose 
322 
't component somehow involves the fptrtype. 
't component somehow involves the fptrtype. 
323 


324 
A function pointer of type (A > B) fptr can be invoked with an 
A function pointer of type (A > B) fptr can be invoked with an 
420 
upon) for most operations. 
upon) for most operations. 
421 


422 
Lightweight versions of these types (constructors carry a prime in 
Lightweight versions of these types (constructors carry a prime in 
423 
their names): "obj'", "ptr'", "fptr'") do not use RTI in their 
their names: "obj'", "ptr'", "fptr'") do not use RTI in their 
424 
concrete representations. This is more efficient for all 
concrete representations. This is more efficient for all 
425 
operations that don't need access to RTI. On the downside, it 
operations that don't need access to RTI. On the downside, it 
426 
means that RTI must be passed in explicitly by the programmer for 
means that RTI must be passed in explicitly by the programmer for 
435 
Array subscript, to name one example, on lightweight array objects 
Array subscript, to name one example, on lightweight array objects 
436 
enforces correct usage of RTI using ML's static typing: 
enforces correct usage of RTI using ML's static typing: 
437 


438 
Arr.sub' : (('t, 'f, 'n) arr, 'f) T.typ > 
Arr.sub' : (('t, 'n) arr, 'f) T.typ > 
439 
(('t, 'f, 'n) arr, 'f, 'c) obj' * int > ('t, 'f, 'c) obj' 
(('t, 'n) arr, 'f, 'c) obj' * int > ('t, 'f, 'c) obj' 
440 


441 
7.1 Light vs. heavy: 
7.1 Light vs. heavy: 
442 

