(**
 	Module: Symbol	
	Description: Symbols' information in faust.
	@author WANG Haisheng	
	Created: 05/08/2013	Modified: 05/08/2013
*)

open Types;;

exception Symbol_error of string;;

(* MACRO *)
let delay_memory_length = 100000;;
let rdtable_memory_length = 100000;;
let vectorize_memory_length = 1000;;

let dimension_of_symbol : symbol -> int * int =
  fun (s : symbol) ->
    match s with
    |Add	 ->  (2, 1)
    |Sub	 ->  (2, 1)		
    |Mul	 ->  (2, 1)
    |Div	 ->  (2, 1)
    |Pass	 ->  (1, 1)
    |Stop	 ->  (1, 0)
    |Mem	 ->  (1, 1)
    |Delay	 ->  (2, 1)
    |Floor	 ->  (1, 1)
    |Int	 ->  (1, 1)
    |Sin	 ->  (1, 1)
    |Cos	 ->  (1, 1)
    |Atan	 ->  (1, 1)
    |Atan2	 ->  (2, 1)
    |Sqrt	 ->  (1, 1)
    |Rdtable	 ->  (3, 1)
    |Mod  	 ->  (2, 1)
    |Vectorize	 ->  (2, 1)
    |Vconcat	 ->  (2, 1)
    |Vpick	 ->  (2, 1)
    |Serialize	 ->  (1, 1)
    |Larger	 ->  (2, 1)
    |Smaller	 ->  (2, 1)
    |Max         ->  (2, 1) 
    |Min         ->  (2, 1)
    |Prefix	 ->  (2, 1)
    |Select2	 ->  (3, 1)
    |Select3     ->  (4, 1);;

let delay_of_symbol : symbol -> int =
  fun (s : symbol) ->
    match s with
    |Add	 ->	0
    |Sub	 ->	0		
    |Mul	 ->	0
    |Div	 ->	0
    |Pass	 ->	0
    |Stop	 ->	0
    |Mem	 ->	1
    |Delay	 ->	delay_memory_length 
    |Floor	 ->	0
    |Int	 ->	0
    |Sin	 ->	0
    |Cos	 ->     0
    |Atan	 ->     0
    |Atan2	 ->     0
    |Sqrt	 ->     0
    |Rdtable	 ->	rdtable_memory_length
    |Mod	 ->	0
    |Larger	 ->	0
    |Smaller	 ->	0
    |Max         ->     0	
    |Min         ->     0
    |Vectorize	 ->	vectorize_memory_length
    |Vconcat	 ->	0
    |Vpick	 ->	0
    |Serialize	 ->	0
    |Prefix	 ->	1
    |Select2	 ->	0
    |Select3     ->	0;;

let string_of_symbol : symbol -> string = 
  fun (s : symbol) ->
    match s with
    |Add	 ->	"Add"
    |Sub	 ->	"Sub"		
    |Mul	 ->	"Mul"
    |Div	 ->	"Div"
    |Pass	 ->	"Pass"
    |Stop	 ->	"Stop"
    |Mem	 ->	"Mem"
    |Delay	 ->	"Delay" 
    |Floor	 ->	"Floor"
    |Int	 ->	"Int"
    |Sin	 ->	"Sin"
    |Cos	 ->     "Cos"
    |Atan	 ->     "Atan"
    |Atan2	 ->     "Atan2"
    |Sqrt	 ->     "Sqrt"
    |Rdtable	 ->	"Rdtable"
    |Mod	 ->	"Mod"
    |Larger	 ->	"Larger"
    |Smaller	 ->	"Smaller"
    |Max         ->     "Max"
    |Min         ->     "Min"
    |Vectorize	 ->	"Vectorize"
    |Vconcat	 ->	"Vconcat"
    |Vpick	 ->	"Vpick"
    |Serialize	 ->	"Serialize"
    |Prefix	 ->	"Prefix"
    |Select2	 ->	"Select2"
    |Select3     ->	"Select3";;