NAME
Dreamer - A framework to emulate arbitrary one-operand computers
VERSION
Version 0.01
SYNOPSIS
use VM::Dreamer qw{ initialize_machine load_program get_next_instruction increment_counter }; use VM::Dreamer::Languages::MyComputer qw{ get_definition execute_next_instruction };
my $definition = get_definition(); my $machine = initialize_machine($definition);
my $program = '/path/to/my/program';
load_program( $machine, $program );
until( $machine->halt ) { get_next_instruction($machine); increment_counter($machine); execute_instruction($machine); }
exit 0;
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 pointer to a machine. The first input is the machine's definition and the second is it's instruction set.
Usually, the definition is received from get_definition and the instruction set is from VM::Dreamer::Languages::MyMachine::get_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.
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.
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)