NAME

Dreamer - An arbitrary emulator of one-operand computers

VERSION

Version 0.851

SYNOPSIS

use VM::Dreamer qw( initialize_machine load_program get_next_instruction increment_counter execute_next_instruction ); use VM::Dreamer::Languages::Grasshopper qw( get_instruction_set );

my $definition = { base => 10, op_code_width => 1, operand_width => 2 };

my $instruction_set = get_instruction_set(); my $machine = initialize_machine( $definition, $instruction_set );

my $program = $ARGV[0]; load_program( $machine, $program );

until( $machine->{halt} ) { get_next_instruction($machine); increment_counter($machine); execute_next_instruction($machine); }

DESCRIPTION

Dreamer is a framework to emulate arbitrary 1-operand computers. It comes with pre-defined machines, but also lets you define and operate your own. It was written as a generalization of the Little Man Computer to help myself and others understand the foundations of Computer Science.

EXPORT

initialize_machine load_program get_next_instruction increment_counter execute_next_instruction

FUNCTIONS

initialize_machine

Takes two hash_refs as input and returns a hash ref.

The first input is the machine's definition. It should have and the second is it's instruction set.

load_program

Takes a reference to your machine and a path to a program for your machine. If the file cannot be opened or is not valid, it raises an exception. Otherwise it puts the instructions into the corresponding addresses in your machine's memory and returns 0.

GETTING STARTED

The easiest way to get started is to execute a pre-written program for a pre-defined machine. This is as simple as:

    $ grasshopper sample_code/grasshopper/io

It will just ask you for a number and then give it back.

After you do that, I would try writing your own program for Grasshopper. It comes with a well-written tutorial.

From there, you could move on to writing programs for Eagle or you could start defining your own machine and writing code for it.

Defining your own machine

This is explained extensively in VM::Dreamer::Tutorial::MachineDefinition. If you'd rather learn by example, the one for Grasshopper should be a good example - see VM::Dreamer::Languages::Grasshopper.

Developing the code base

If you really get into this and you'd like to work on the code base, please let me know:

NEXT STEPS

You can also find the documenation on defining your own machines. Then you can start writing your own programs for it. If you really get bored, you can write an assembler. If that isn't enough you can create a higher level language and write a compiler for your instruction set. Really, the sky's the limit ;-)

I also thought that these simple machines could be of mathematical interest in the sense that they can operate on very, very large numbers in a relatively arbitrary base (though you could probably already do this with bc).

They might also be intersting to people who want to translate machine code from one machine to another or to target multiple platforms from a generic assembly code like UNCOL.

Enjoy!

AUTHOR

William Stevenson <dreamer at coders dot coop>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by William Stevenson.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)