%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%      FORMAT OF TEXT PICKLES
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

A text pickle is a sequence of pairs. Each pair is of the form
  
    x:yyyy...

where "x" is a single char (tag) specifying the type and "yyyy..." is
it's value. There must be no blanks after the colon.

Possible tag:value pairs are:

	 S:<string>
	 I:<digit>+			% integer
	 D:<termtag>
	 O:<opcode>
	 L:<string>			% reference to a label
	    				% scope: surrounding code block
	 l:<string>			% definition of instruction label
	 B:<digit>+			% decimal code of a single byte
	 C:				% start of code block
	 c:				% end of code block
	 T:<string>			% reference to term (global scope)
	 t:<string>			% definition of term label (follows <termtag>)
	 #:<char>* <newline>		% comment
	    

Not every sequence of pairs is allowed (see grammar below).

Comments can occur between arbitrary pairs. They start with "#:" and
end with a newline.

Below is the full grammar. Non-terminals are enclosed into <...>
everything else are terminals.

MAJORVERSION = 1
MINORVERSION = 4


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  grammar for pickles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<pickle> ::=  <tstring>		       % version number "MAJOR#MINOR"
	      <value>		       % the value contained in the pickle


<value>	 ::= <ozref>   | <ozint>       | <ozfloat>  | <ozatom>   | <ozname> 
	   | <ozlist>  | <oztuple>     | <ozrecord> | <ozbigint> | <ozbuiltin> 
	   | <ozchunk> | <ozfsetvalue> | <ozdict>   | <ozclass>  | <ozproc>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% primitives
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<string> ::=	to be defined by Leif (like atoms in Oz)

<int>	 ::= <digit>+

<digit>  ::=  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tagged short, int, string, etc.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<tint>	       ::= I:<int>
<tbyte>	       ::= B:<int>
<tstring>      ::= S:<string>
<reftag>       ::= t:<int>         % definition of term label (follows termtag)



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<ozint>        ::= D:SMALLINT <int>

<ozfloat>      ::= D:FLOAT <int> <int>             % 64bit float repr. as 2 x 32bit ints

<ozbigint>     ::= D:BIGINT <tstring>		   % string representation of value

<ozatom>       ::= D:ATOM <reftag> <string>

<ozname>       ::= D:UNIQUENAME <reftag>
		   <tstring>			   % printname
                 | D:COPYABLENAME <reftag>
		   <tstring>			   % printname
                 | D:NAME <reftag>
		   <tstring>			   % printname
		   <gname>

<ozlist>       ::= D:LIST <reftag> 
	           <value> <value> % head, tail

<oztuple>      ::= D:TUPLE 
		   <reftag> 
		   <tint>			   % number k of arguments
		   <value>			   % label
		   <value>+			   % k arguments

<ozrecord>     ::= D:RECORD
		   <reftag> 
		   <value>			   % arity as a list of features
		   <value>			   % label
		   <value>+			   % k arguments

<ozbuiltin>    ::= D:BUILTIN <reftag> <tstring>	   % printname of builtin

<ozchunk>      ::= D:CHUNK <reftag> <gname> <value>

<ozfsetvalue>  ::= D:FSETVALUE <value>

<ozdict>       ::= D:DICT <reftag> 
		   <tint>			   % size
		   (<value> <value>)*		   % pairs key#value

<ozclass>      ::= D:CLASS <reftag>
		   <gname>
		   <tint>                          % flags
		   <value>			   % features

<ozproc>       ::= D:PROC 
		   <reftag>
		   <gname>
		   <value>			   % printname
		   <tint>			   % arity
		   <tint>			   % # of gregs
		   <tint>			   % # of max used xregs
		   <value>*			   % value of gregs
		   <code>

<ozref>        ::= D:REF <tint>		   % reference to term (global scope)



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% gnames
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<gname>	       ::= <site>
		   <tint> <tint>		   % id = long int (2 x 32 bits)
		   <tint>			   % gname type 
						   % NAME=0,PROC=1,CODE=2,CHUNK=3,
						   % OBJECT=4,CLASS=5,PROMISE=6

<site>	       ::= <tint>		           % address
		   <tint>			   % timestamp.start
		   <tint>			   % timestamp.pid



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% machine code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<code>	       ::= C:				   % mark beginning of segment
		   <instr>*
		   c:				   % mark end of segment

<instr>		::= O:<opcode> <oparg>*		   % args according to instrDefs.m4
		 |  l:<string>		           % label

<opcode>	::= moveXX | ...		   % see opcodes.hh

<oparg>		::= <value> 
		  | <tint> 
		  | <labelref>
		  | <predref>
		  | <predid>
		  | <htable>
		  | <recordarity>
		  | <gencallinfo>
		  | <gregref>
		  | <location>

<labelref>	::= L:<string>			  % label reference

<predref>       ::= I:0				  % not copyable
		  | I:1 D:ABSTRENTRY <reftag>	  % copyable
                  | I:1 D:REF T:<int>

<predid>        ::= <value>			  % printname
		    <recordarity>		  % (method)arity
		    <value>			  % filename
		    <tint>			  % line
		    <tint>			  % column
		    <value>			  % flags
		    <tint>			  % max Xregs used

<recordarity>	::= I:0 <int>			  % a tuples arity
		  | I:1 <value>			  % list of features of a record

<gencallinfo>	::= <tint>			  % flags
		    <value>			  % method name
		    <recordarity>		  % arity

<gregref>	::= <tint>			  % number of regs
		    <tint>*			  % index+type in one int

<location>      ::= <tint>			  % # of input args
		    <tint>			  % # of output args
		    <tint>*			  % indices

<htable>	::= <tint>			  % size
		    <labelref>			  % else label
		    <labelref>			  % list label
		    <tint>			  % number of entries
		    <htentry>*

<htentry>       ::= I:0 <labelref> <value>	         % a literal
		  | I:1 <labelref> <value>	         % a number
		  | I:2 <labelref> <value> <recordarity> % a record (label/arity)

