Wednesday, November 16, 2011

The G machine has utility!

It operates as a controllable batch processor for large and proprietary SQL procedures on undifferentiated tables.  Here is how the current lab version works:
1) It pops a triple from the start of table view self
2) it executes the triple link operator
where triple is the record format:
(key text,link int,pointer int)

What is the link operator?
It is one of the following, to the G machine:
a) Install the SQL procedure in key
2) Execute the procedure identified by link
3) Jump the current table view row to  atoi(key)

Hence, a simple controllable batch processor for sql statements.  Since key is undifferentiated text, just dump a bunch of SQL in it as the initial install, and away you go, programming in triples, each triple may initiate some complex SQL, returning to G  at SQLITE_DONE.

How do we program in triples?
Use the m4 processor.  We can cut and past large SQL procedures right into any simple editor. My M4 macros have utilities to lay out the executing self table.  For jumps one macro increments a row counter as it lays out the triples.  Then I run the output through M4 and into sqlite3. I go from simple editor to direct control of sqlite3 for management of large complex groups of SQL procedures.


Here is my typical M4 layout in the lab.  It completely build the tables and view in sqlite3, inserts all the triples an manages the row counter for jumps.  SCRIPT refers to some arbitrary blob of text defines before this layout.  The output from the M$ pocessor feeds directly into sqlite3.  Then just start the G machine.
TABLE(`result')
TABLE(`self_alias')
TABLE(`other_alias')
VIEW(`self',`self_alias')
VIEW(`other',`other_alias')
define(Tname,self_alias) define(G_row,0)
NEWRECORD ("SCRIPT",2,1);
NEWRECORD ("Entry",operand,0);
NEWRECORD ("Return",3,0);

define(Tname,result) define(G_row,0)
NEWRECORD ("Test1",99,0);
NEWRECORD ("Test2",99,0);
NEWRECORD ("Test3",99,0);

Maintain libraries of batch procedures, each as a string of triples.  Then use alter table rename to self_alias, and run G.  self_alias, actually misnamed, is the real table underneath the view self. There is a jump operator for jump table, but still in lab. Looking at the code you can see swap table, tested but unconnected.
Finally, any arbitrary procedure stored in G machine can execute a specific jump with:
 select "Location",JUMP,0;

No comments: