using System;
using System.Collections;

namespace Liss
{
	public class VM_Code
	{

		public VM_Code()
		{
		}


		/**********************************************************************
		*								 VM CODE 							  *
		**********************************************************************/

		public void writeLiss()
		{
			Console.WriteLine("\n\n;| ---------------------------------------------------- |");
			Console.WriteLine(";| CLISS Compiler. Version 1.0				|");
			Console.WriteLine(";|							|");		
			Console.WriteLine(";| Authors: João Gomes, Simão Melo de Sousa		|");
			Console.WriteLine(";| Date: September, 2006				|");		
			Console.WriteLine(";|							|");		
			Console.WriteLine(";| ---------------------------------------------------- |\n");
		}

		// Write C libraries
		public string WriteLib()
		{
			return "#include <stdio.h>\n" + 
					"#include <stdlib.h>\n" + 
					"#include \"liss_bool.h\"\n" +
					"#include \"liss_list.h\"\n" +
					"#include \"liss_set.h\"\n";
		}

		// Write C libraries
		public string WriteCaduceusLib()
		{
			return "/* THIS FILE WAS GENERATED TO BE USED IN CADUCEUS\n" +
					" *\n" +
					" */\n" +
					"#include \"liss_caduceus_list.h\"\n" +
					"#include \"liss_caduceus_set.h\"\n";
		}

		// print the correct identation
		public string PrintIdent(int n)
		{
			int i;
			string ident = "";
			for(i=0; i<n; i++)
				 ident += "\t";
			return ident;
		}
		
		// Write C main function
		public string WriteMain()
		{
			return "void main()\n";
		}

		// Write the program's ending -- NOT USED -- TODO
		public string WriteEnd()
		{
			return "return 0;\n";
		}
		
		// print a sequence
		public string printSequence(string name)
		{
			return "printList(" + name + ");\n";
		}

		// print a set
		public string printSet(string name)
		{
			return "printSet(" + name + ");\n";
		}

		// Join an element to the sequence (in the tail)
		public string Cons(string code, string name)
		{
			return "addElemList(" + code + ", " + name + ")";;
		}

		// index a sequence
		public string IndexSequence(string pos, string name)
		{
			return "getElemList(" + pos + ", " + name + ")";
		}
		
		// Delete the first occurrence of an element in a sequence 
		public string Delete(string elem, string name)
		{
			return "remElemList(" + elem + ", " + name + ")";
		}

		// Copy the elements of the first sequence to the other 
		public string Copy(string src, string dest)
		{
			return "copyList(" + src + ", " + dest + ")";
		}

		// assigns two sets 
		public string AssignSet(string src, string dest)
		{
			return "assignSet(" + src + ", &" + dest + ")";
		}

		// "Is In Set" operation 
		public string IsInSet(string val, string s)
		{
			return "isInSet(" + val + ", " + s + ")";
		}

		// Interception between two sets 
		public string InterceptionSet(string set1, string set2)
		{
			return "interceptionSet(" + set1 + ", " + set2 + ")";
		}

		// Union between two sets 
		public string UnionSet(string set1, string set2)
		{
			return "unionSet(" + set1 + ", " + set2 + ")";
		}

		// Verify if an element is member of sequence 
		public string IsMember(string elem, string name)
		{
			return "isMemberList(" + elem + ", " + name + ")";
		}

		// length of a sequence
		public string LengthSequence(string name)
		{
			return "getSizeList(" + name + ")";
		}

		// Verify if a sequence is empty 
		public string IsEmpty(string name)
		{
			return "isEmptyList(" + name + ")";
		}

		// head of a sequence
		public string Head(string name)
		{
			return "getHeadList(" + name + ")";
		}
		
		// tail of a sequence
		public string Tail(string name)
		{
			return "getTailList(" + name + ")";
		}
		
		// print a default value
		public string printDefaultValue(string name)
		{
			return "printf(\"%d\", " + name + ");\n";
		}

		// print a boolean value
		public string printBoolean(string name)
		{
			return "WriteBoolean(" + name + ");\n";
		}

		// read an integer
		public string Read(string name)
		{
			return "scanf(\"%d\", &" + name + ")";
		}

		// print "\n" character
		public string printLn()
		{
			return "printf(\"\\n\");\n";
		}

		// Code "PUSHI"
		public string Pushi(int num)
		{
			return "PUSHI " + num + "\n";
		}

		// Code "PUSHI"
		public string Pushi(string signal,int num)
		{
			return ("PUSHI " + signal + num + "\n");
		}

		// Code "STOREG"
		public string StoreG(int num)
		{
			return "STOREG " + num + "\n";
		}

        
		// Code "STOREG"
		public string StoreL(int num)
		{
			return "STOREL " + num + "\n";
		}


	

		// Code "Multiply"
		public string Mul()
		{
			return "MUL\n";
		}


		// ************************************************
		// *			HEAP							  *
		// ************************************************


	}
}