Pigeon Computer 0.1 Initial (BETA) release

Summary
============

The Pigeon Computer is a simple but sophisticated system for learning
and exploring the fundamentals of computers and programming.

It is written to support a course or class (as yet pending) to learn
programming from the bit to the compiler.

There is a DRAFT manual and a Pigeon User Interface that includes:

  * An assembler for the ATmega328P micro-controller.
  * A polymorphic meta-compiler.
  * Forth-like firmware in assembly.
  * Simple high-level language for assembly control structures.
  * A virtual computer that illustrates Functional Programming.

Source code is released under the GPL (v3) and is hosted on Github:
  https://github.com/PhoenixBureau/PigeonComputer

The manual is online in HTML form here:
  http://phoenixbureau.github.com/PigeonComputer/

Mailing list:
  https://groups.google.com/d/forum/pigeoncomputer

It has been tested on Linux with Python 2.7, YMMV.

I'm releasing it now because it's basically done even though it needs
polish and I'm just too excited about it.  Happy End of the World Day!


Details
============

The class starts with "the bit" and develops the core concepts
underlying computers with a hands-on exploration of bits and bytes as
embodied in physical "bits" on a table: coins or other binary
"tokens".

Using this "RAM-abacus" we explore different coding schemes (binary
numbers, ASCII codes, Grey codes, etc.) and then play with simple
operations to show how the bits can be used to perform math and logic
as well as simple "text processing".  We number the operations, lay in
simple "programs" in the "RAM", and manually act out the actions of a
(hypothetical) CPU.

Once the students have the idea we introduce a concrete example: the
ATmega328P, a simple but powerful 8-bit RISC micro-controller with
Harvard Architecture and a 16-bit program RAM that is used in many
popular devices such as the Arduino Uno.

Using this chip and the Pigeon User Interface students will be able to
develop simple robots and other devices and program them themselves.

 - - -

The Pigeon User Interface (PUI) is a simple and elegant IDE that
presents the user with a very simple but powerful stack-based virtual
computer that includes commands for assembling object code for the
ATmega328P and compiling high-level languages to assembly.

To get the students into assembly language the Pigeon Computer system
includes a tiny Forth-like firmware that implements a command
interpreter on the serial port (on-chip USART peripheral) in less than
a kilobyte of object code.

The firmware is a stub. It is meant to be understood and extended by
the students rather than used as-is.  I have written some commands for
it that give it the ability to use the TWI (I2C) subsystem of the
ATmega328P to communicate with other devices, and used that to talk to
an Inertial Motion Unit and get gyro and accelerometer readings, so
there's that.

Once students are comfortable with assembly, the PUI includes a tiny,
powerful, and extremely flexible meta-compiler: Val Shorre's Meta-II
(implemented in Python.)  This amazing bit of software is polymorphic
in the sense that you can feed it different compiler descriptions and
it becomes different compilers.

The underlying Meta-II virtual machine works just like an assembler to
read and "become" a compiler description, then it operates as a
syntax-driven compiler for the language described in the compiler
description.

It is simple enough to be understood by someone willing to take the
time, yet powerful enough to be used in earnest to develop "little
languages" for use in real projects.  The PUI includes a simple
compiler (a description in Meta-II) that generates control-flow
constructs for the firmware commands, illustrating the path from
hand-coded assembly to high-level languages.

(Those interested in further information regarding these issues are
urged to examine the work of the Viewpoints Research Institute.)

 - - -

Last but not least, the virtual computer in the PUI is a stack-based
Forth-like fully Functional Programming not-quite-language.  It mimics
the operation of the firmware but goes far beyond what that code is
capable of as it has the whole of Python and the host machine to work
with.

When you start the PUI it creates a "roost" directory (I apologize for
the pun) where it writes a Git repository (using a pure-Python Git
implementation called Dulwich) and two files: 'log' and
'system.pickle'.

Then the GUI starts and the user sees a window with two panes. On the
left is a listbox that shows the contents of the stack and on the
right is a text editor.

The 'log' file is kept in sync with the contents of the text
(auto-saved two seconds after the last edit) and the 'system.pickle'
file keeps a copy of the serialized state of the PUI and is updated
after every change to the virtual computer's state.  When either of
these files change a commit is made to the git repository.

This ensures that you never have to save (ever!) and you can never
lose your work (ever!).  When you re-open the PUI it reads the last
state and log from the "roost" directory and loads them, seamlessly
putting you in the exact spot where you left off.

You can use standard Git tools to examine and check out previous
history.  (Still to do: I want to add means for examining and
replaying histories as well as "cherry picking" objects and data from
previous states into the current one.)

In addition to the above automatic save mechanism, the text widget
includes undo/redo commands.

The stack-based virtual computer has a "dictionary" of command words
(like Forth) each of which operates solely on the stack and has no
side effects.  The virtual computer uses only those Python types that
are immutable (string/unicode, numbers, tuples) and this together with
the purely Functional command words means that the entire virtual
machine is pure Functional-Programming-style.

(One effect of this is that the whole machine state forms one
"persistent" data structure that captures the whole previous history
of every computation the machine performs as the user uses it to e.g.
write code for their chip(s).  This history is kept, serialized in the
'system.pickle' file, and could be made available to the user,
although at the moment it is discarded from the running PUI.  This
whole persistence mechanism is separate and orthogonal to the
git-based history store mentioned above.)

 - - -

The PUI has no menus, no buttons.

You execute commands by right-clicking on their names in the text editor.

Numbers can be put on the stack by right-clicking on them.

Strings can be put on the stack by selecting text and then, BEFORE
LETTING GO, clicking the right mouse button.

For example, start the PUI and type in two numbers. Right click on
each of the numbers and you'll see they appear on the stack.  Right
click "add" (type it in if it's not there) and you will see that the
two numbers have been replaced by their sum.

This is a summary of the mouse "chords" that you can use to control
the PUI (inspired by the Oberon OS and UI):

PUI Mouse Click Chord Commands:

   left - point and select
       * followed by right: copy selection to stack
       * followed by middle: cut selection to stack

   middle - paste, scroll
       * followed by left: paste stack to text
       * followed by right: pop stack to text

   right - command (execute word)
       * followed by left or middle: lookup word (put the named
         command onto the stack)

(Note: you use one mouse button and then, without letting go of the
first mouse button, use the second one to complete a mouse "chord".)

The default config.py includes key bindings as well:

  Selection-to-Stack:

    <F4>: Copy from selection to stack and system clipboard.

    <Shift-F4> or <F6>: Cut selection to stack and system clipboard.

  Stack-to-Insertion-Cursor:

    <F5>: Paste from stack to cursor leave stack undisturbed.

    <Shift-F5> or <F7>: Paste from stack to cursor and pop stack.

(You can edit these and add your own in the config file.)

The currently implemented command words are documented here:
  
http://phoenixbureau.github.com/PigeonComputer/user_interface.html#library-of-words

 - - -

Fibonacci:  Try putting 1 on the stack (type it in and right-click on
it) then right-click "dup" to duplicate it and have two ints on the
stack.  Now repeatedly execute (right-click on) "tuck" and "add"...

Neat, eh?

And it works (thanks to Python's underlying implementation of "foo +
bar") whether you use string "1" numerals or integer digits.

 - - -

Command words can be put onto the stack and combined into new commands
using three primitives: Sequence, Branch, Loop.

See 
http://phoenixbureau.github.com/PigeonComputer/user_interface.html#xerblin-base
for more information.

Once a new command has been made it can be included in other commands
or given a name and inscribed in the dictionary and used like the
other commands.

 - - -

Whew!  If you are still reading, thank you.  There is a lot more to be
done and I am hoping to form classes in early January 2013.  If you
are interested please email me at forman.si...@gmail.com

You can also participate on Github and join the mailing list.
  * https://github.com/PhoenixBureau/PigeonComputer
  * https://groups.google.com/d/forum/pigeoncomputer

Warm regards,
~Simon P. Forman
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

        Support the Python Software Foundation:
        http://www.python.org/psf/donations/

Reply via email to