
ok. just use the current file format..
a file is a list of lines, where the first n characters are an opcode

opcodes:

should include table defs.

support 4 basic operations:

select
insert
update
delete

internal:
each table is a list of records.


provide the function select:


u= Select("entry.text to",&text,"entry.date to",&date,
		  "where entry.recno=",recno,";");
Iterate(u);
End(u);

Execute("insert into tagmap tagmap.tag=",tag,"tagmap.record=",recno);


returned strings will be stored into the string value, the user strdup's
them if he wishes.

returned blob's will be stored as blob access pointers.
user will use that pointer to access the blob. i.e.

blob_getsize
blob_getdata


instructions:

R= 0 or 1
fetch field name, R1
fetcha address, R1
equal/less/great/nless/ngreat/nequal R1,R2, jump label
label name
or/xor/and/not/add/sub/mul/div/mod/cat R1, R2, R3
call jumplabel, Rcall, Rarg1,Rarg2, Rargn
jump label
accept
reject

using a predicate:

#define cv(x) "\001",sizeof(x),x
#define ca(x) "\002", x
cv stands for C variable
ca stands for C array

"where ",a, "(db.entry, bla bla", cv(x), cv(y), cv(z),")"

we need values from C in 4 contexts:

1- as select destinations, to hold values that were selected
2- as expressions, supplied to insert, update etc.
3- as expressions, supplied to the where clause
4- as arguments to a C-predicate.


for 1, we need the address, this is easy
for 2,3 we will get value correctly, no problem
for 4,
	1- we can just say that only pointers or integers may be passed to
	   C predicates
	2- we could encode the size of the argument
	3- we can provide both, so make the user use a special address and
	   size encoding macro when needed.

at the start, just collect all arguments into a list or array, or something

then, collect the text for all of them, 
parse that and generate instructions

ok.


when calling a function, 
	we know the number of arguments and the address of the function
	just allow up to say, 256 arguments and then have a big switch. like:

	case 1: return (*f)(a1);
	case 2: return (*f)(a1,a2);
	case 3: return (*f)(a1,a2,a3); 
	etc.

	this will prohibit passing in large values, but that will do.
	ok then


the grammar is:

Select:
	coldefs
	[ "from" fromclause ]
	[ whereclause  ]
	";"

coldefs = 
	varname "=" fieldname "," coldefs
	| varname= fieldname 
	;

fromclause = 
	tablename "," fromclause
	| tablename 
	;

whereclause :
	"where" expr
	;

expr= expression made up of the operators and stuff.


preprocessor interface:


c= SELECT a= x, b= y, c= d+z FROM table  WHERE condition [ONCE] ;


into:

		c= select x,y,d,z from table;

ITERATE c

into 
		req= iterate(c)

or

x= db_select(db,function(R) return R.x,R.y,R.z end,"t", function(R) return R.a==3 and R.b==4 end)
a,b,c= db_iterate(x)
db_end(x)

ok. this is good.

db_insert(db,"t", function(R) R.a=x R.b=c R.d=e end)
db_delete(db,"t", function(R) return ... end)
db_update(db,"t", function(R) R.a=R.a+1 R.b=x R.c=y end , function(R) return R.a==3 and R.b==4 end)

