From 23922b6f3a5f9813b822b4c60f05c8f2e384b070 Mon Sep 17 00:00:00 2001 From: WANG Date: Mon, 5 Aug 2013 18:23:43 +0200 Subject: [PATCH] Refactoring of class process in faustexp.ml. --- interpretor/faustexp.ml | 52 ++++++++++++++++++++++++++++++++++------- interpretor/types.ml | 1 - 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/interpretor/faustexp.ml b/interpretor/faustexp.ml index 684eb75..8ad37aa 100644 --- a/interpretor/faustexp.ml +++ b/interpretor/faustexp.ml @@ -6,12 +6,14 @@ *) open Types;; +open Basic;; open Value;; open Signal;; open Beam;; exception NotYetDone;; exception Dimension_error of string;; +exception Process_error of string;; class dimension : int * int -> dimension_type = fun (init : int * int) -> @@ -91,17 +93,51 @@ class process : faust_exp -> process_type = class proc_const : faust_exp -> process_type = fun (exp_init : faust_exp) -> object (self) - val exp = exp_init - val dim = - method evaluate = fun b1 -> - + val _exp = exp_init + val _dim = new dimension (0,1) + val _delay = 0 + val _const = + match exp_init with + | Const b -> b + | _ -> raise (Process_error "const process constructor.") + + method exp = _exp + method dim = _dim + method delay = _delay + method const = _const + + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + if input = [||] then + new beam [| new signal 0 (fun t -> new value self#const)|] + else + raise (Process_error "proc_const accepts no input.") end;; -class exp_ident = - object - inherit expression - +class exp_ident : faust_exp -> process_type = + fun (exp_init : faust_exp) -> + object (self) + val _exp = exp_init + val _symbol = + match exp_init with + | Ident s -> s + | _ -> raise (Process_error "ident process constructor.") + val _dim = dimension_of_symbol _symbol + val _delay = 0 + + + method exp = _exp + method dim = _dim + method delay = _delay + method const = _const + + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + if input = [||] then + new beam [| new signal 0 (fun t -> new value self#const)|] + else + raise (Process_error "proc_const accepts no input.") end;; diff --git a/interpretor/types.ml b/interpretor/types.ml index 6fa6513..5e88a1a 100644 --- a/interpretor/types.ml +++ b/interpretor/types.ml @@ -144,6 +144,5 @@ class type process_type = method exp : faust_exp method dim : dimension_type method delay : int - method to_string : string method evaluate : beam_type -> beam_type end;; -- 2.20.1