This directory contains sources for a compiler from a small, safe subset

of C (called popcorn) to x86 typed asssembly.



popast.mli   	--  simplified abstract syntax 

popcompile.ml	--  compiles type-checked abstract syntax to TAL

popcorn.ml	--  the main driver

poplex.mll	--  lex definitions for popcorn

popparse.mly	--  yacc definitions for popcorn

popsyntax.ml{i} --  the abstract syntax tree built by the parser

poptype.ml{i}	--  type-checks the abstract syntax tree and elaborates

			into an internal typed abstract syntax tree

tests		--  contains some simple test programs



To build and use popcorn (assuming an x86), make sure that the following

executables are on your path:



  ocaml		(version 1.05)

  ml  		(MASM 6.11 -- needed to assemble the TAL code)

  talcheck.exe  (needed to verify the TAL code emitted by popcorn)

  link		(VC++ linker)



You'll also need to make sure that the standard Visual C library is in your

path, and that the TAL runtime library path is set.  For example, my 

autoexec.bat includes definitions like this:



  PATH=C:\OCAML\BIN;C:\PROGRAM FILES\DEVSTUDIO\VC\BIN;C:\MASM611\BIN;C\PROGRAM FILES\DEVSTUDIO\SHAREDIDE\BIN

  LIB=C:\PROGRAM FILES\DEVSTUDIO\VC\LIB

  CAMLLIB=C:\OCAML\LIB

  TALCLIB=C:\talc\tal\runtime



The Makefile (in the talc directory above this one) should contain all

the definitions needed to build popcorn.



Popcorn "sprang into existence" due to Chris Hawblitz's hacking over

a Christmas break.  I've since modified it a bit to deal with a few

more constructs and to emit slightly better code.



The compiler is extremely naive -- it is entirely stack-based.  



Only a very small subset of C is currently supported, including:



  - functions, ints, booleans, structs, and "optional" structs (?structs).

	structs behave more like Java objects than C structs.

	structs cannot be null.  ?structs can be.  

	when you use null, you have to mention its type

	to declare a struct:



	struct A { int x; int y;}

	?struct B {int x; int y;}



	to create a struct:



	A a = new A(3,4);

	B b = new B(3,4);

	B c = null B;



	to get a field of a struct:



	a.x + a.y

	b.x + b.y

	c.x + c.y  <-- will exit the program due to null pointer dereference



   - structs can be recursive:  for instance



	?struct int_list { int head; int_list tail; }







  