Previously the definition of SYSTEM.VAL was:
Code: Select all
PROCEDURE VAL*(typeName: <any basic type>; x: <any basic type or pointer>): typeName;
Code: Select all
PROCEDURE VAL*(typeName <any type>; x: <any type>): typeName;
This Oberon enhancement was initially introduced in the Project Oberon 2014 compiler and operating system implemented by Niklaus Wirth and Paul Reed on a Xilinx FPGA development board.
Consequently, SYSTEM.VAL is now very useful for performing serialization i.e. transforming complex data structures into byte-streams and vice-versa. For example, in Project Oberon 2014 it is used to convert the internal filesystem directory structures and file headers to the raw sectors stored on a MicroSDHC card used for disk storage. The following is an extract from the Project Oberon file system type declarations:
Code: Select all
MODULE FileDir;
TYPE
FileHeader* =
RECORD (*first page of each file on disk*)
mark*: INTEGER;
name*: FileName;
aleng*, bleng*, date*: INTEGER;
ext*: ExtensionTable;
sec*: SectorTable;
fill: ARRAY SectorSize - HeaderSize OF BYTE;
END ;
DataSector* = ARRAY SectorSize OF BYTE;
Code: Select all
MODULE Files;
TYPE
BufferRecord =
RECORD apos, lim: INTEGER;
mod: BOOLEAN;
next: Buffer;
data: FileDir.DataSector
END ;
Buffer = POINTER TO BufferRecord;
Code: Select all
VAR
buf: Buffer;
fh: FileDir.FileHeader;
...
...
fh := SYSTEM.VAL(FileDir.FileHeader, buf.data);