60 likes | 147 Views
Representation of Data Structures in OCAML. Outside Heap. pointer. Register. Heap. int value. 1. Header. Register. Register. pointer. „Block“. Register. Encoding. int value encodes integer nullary constructor conversion for int values shl(x,1) + 1 shr(x,1)
E N D
Outside Heap ... pointer Register Heap int value 1 Header Register Register pointer „Block“ ... Register
Encoding • int value encodes • integer • nullary constructor • conversion for int values • shl(x,1) + 1 • shr(x,1) • no conversion for pointers neededblocks are word aligned lowest bit is 0 • loose 1 bit for int representation • no loss in address space
Header 31 10 9 7 0 8 tag size color (GC) tag: • distinguish constructors of a type • 0 <= tag <= 247 for tuples, arrays, constructor terms
Special Tags (>= 248) • 248: objects • 249, 250: functions (see below) • >= 251: non-heap data (GC does not look inside) • 251: unused • 252: strings • 253: floats • 254: float arrays • 255: finalization
(Recursive) Functions 250 size f PC start offset 249 let rec f x = ...and g x = ...and h x y = ...;; g PC start offset 249 h PC otherglobals