Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with Writable Memory in Haskell - Implementation of Infocom's Z-Machine VM

Many people who were computer enthusiasts in the 80's have heard of the Infocom series of interactive fiction games, notably ones such as 'Zork', 'The Hitchhiker's Guide to the Galaxy', 'Planetfall', 'A Mind Forever Voyaging', etc.

These games were implemented on top of the "Z-Machine" virtual machine. The machine is implemented as a block of RAM, a stack and a virtual processor. The process executes instructions which can dynamically read and write to the RAM.

My question is this: the VMs RAM is dynamic. What is an efficient and reasonably idiomatic way to represent this RAM (and more holistically the structure of the virtual machine) so that I can implement software to run these games? For example, should I use Data.Array to represent the RAM and the state monad?

like image 707
Muchin Avatar asked Jan 17 '11 07:01

Muchin


1 Answers

Haskell has various types of array with varying levels of side-effect control and in both boxed and unboxed variants. A boxed array is an array of pointers to values, unboxed arrays are arrays of contiguous block of memory. For RAM you just want to treat this as a block of contiguous memory so you probably want to go for an unboxed array type like STUARray or IOUArray or StorableArray or similar.

like image 154
snk_kid Avatar answered Sep 28 '22 07:09

snk_kid