root/trunk/liquidsoap/src/lang/lang.mli @ 6527

Revision 6527, 6.4 KB (checked in by dbaelde, 17 months ago)

A first change towards one-format-per-source: the builtin functions should
know the type of value that they are producing.
I added an extra parameter, which is currently never used. The shallow but
wide modification was an opportunity to do a bit of cleanup everywhere,
partly line-breaking and also removing lots of coercions to Source.source
by restricting methods to be private. The rule of thumb is that only active
sources should have a coercion.

Line 
1(*****************************************************************************
2
3  Liquidsoap, a programmable audio stream generator.
4  Copyright 2003-2009 Savonet team
5
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details, fully stated in the COPYING
15  file at the root of the liquidsoap distribution.
16
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 *****************************************************************************)
22
23(** Values and types of the liquidsoap language. *)
24
25(** The type of a value. *)
26type kind = Lang_types.t
27
28(** {2 Values} *)
29
30(** A typed value. *)
31type value = { mutable t : kind ; value : in_value }
32and env = (string * value) list
33and in_value =
34  | Unit
35  | Bool    of bool
36  | Int     of int
37  | String  of string
38  | Float   of float
39  | Source  of Source.source
40  | Request of Request.raw Request.t option
41               (* Request.raw is arbitrary: this information is violated
42                * in the script language until it has enough expressivity. *)
43  | List    of value list
44  | Product of value * value
45  | Fun     of (string * string * value option) list *
46               env * env * Lang_values.term
47  | FFI     of (string * string * value option) list *
48               env * env * (env -> kind -> value)
49
50(** Get a string representation of a value. *)
51val print_value : value -> string
52
53(** Iter a function over all sources contained in a value. *)
54val iter_sources : (Source.source -> unit) -> value -> unit
55
56(** {2 Computation} *)
57
58(** Multiapply a value to arguments. *)
59val apply : value -> (string * value) list -> value
60
61(** {3 Helpers for source builtins} *)
62
63type proto =
64  (string * kind * value option * string option) list
65
66(** Some flags that can be attached to operators. *)
67type doc_flag =
68  | Hidden (** Don't list the plugin in the documentation. *)
69  | Deprecated (** The plugin should not be used. *)
70  | Experimental (** The plugin should not considered as stable. *)
71
72(** Add an builtin to the language. *)
73val add_builtin :
74  category:string ->
75  descr:string ->
76  ?flags:doc_flag list ->
77  string ->
78  proto -> kind -> (env -> kind -> value) ->
79  unit
80
81(** Category of an operator. *)
82type category =
83  | Input (** Input. *)
84  | Output (** Output. *)
85  | TrackProcessing (** Operations on tracks (e.g. mixing, etc.). *)
86  | SoundProcessing (** Operations on sound (e.g. compression, etc.). *)
87  | VideoProcessing (** Operations on video. *)
88  | Visualization (** Visializations of the sound. *)
89
90(** Get a string representation of a [doc_flag]. *)
91val string_of_flag : doc_flag -> string
92
93(** Add an operator to the language and to the documentation. *)
94val add_operator :
95  category:category ->
96  descr:string ->
97  ?flags:doc_flag list ->
98  string ->
99  proto -> (env -> kind -> Source.source) ->
100  unit
101
102(** {2 Manipulation of values} *)
103
104val to_bool : value -> bool
105val to_string : value -> string
106val to_string_getter : value -> unit -> string
107val to_float : value -> float
108val to_float_getter : value -> unit -> float
109val to_source : value -> Source.source
110(** Expands a value representing a request
111  * Value here *must* be an audio request.
112  * Assert false if not.. *)
113val to_request : value -> Request.audio Request.t option
114val to_request_raw : value -> Request.raw Request.t option
115val to_int : value -> int
116val to_list : value -> value list
117val to_product : value -> value * value
118val to_metadata : value -> Frame.metadata
119val to_string_list : value -> string list
120val to_int_list : value -> int list
121val to_source_list : value -> Source.source list
122
123(** [assoc x n l] returns the [n]-th [y] such that [(x,y)] is in the list [l].
124  * This is useful for retreiving arguments of a function. *)
125val assoc : 'a -> int -> ('a * 'b) list -> 'b
126
127val int_t      : kind
128val unit_t     : kind
129val float_t    : kind
130val bool_t     : kind
131val string_t   : kind
132val source_t   : kind
133val request_t  : kind
134val list_t     : kind -> kind
135val product_t  : kind -> kind -> kind
136
137(** [fun_t args r] is the type of a function taking [args] as parameters
138  * and returning values of type [r].
139  * The elements of [r] are of the form [(b,l,t)] where [b] indicates if
140  * the argument is optional, [l] is the label of the argument ([""] means no
141  * label) and [t] is the type of the argument. *)
142val fun_t      : (bool * string * kind) list -> kind -> kind
143val univ_t     : ?constraints:Lang_types.constraints -> int -> kind
144
145(** A shortcut for lists of pairs of strings. *)
146val metadata_t : kind
147
148(** A string getter. The argument is the number of the universal type parameter
149  * (should be >= 1). *)
150val string_getter_t : int -> kind
151(** A float getter. The argument is the number of the universal type parameter
152  * (should be >= 1). *)
153val float_getter_t : int -> kind
154
155val unit : value
156val int : int -> value
157val bool : bool -> value
158val float : float -> value
159val string : string -> value
160val list : value list -> value
161val source : Source.source -> value
162val request : Request.raw Request.t option -> value
163val product : value -> value -> value
164val val_fun :
165      (string * string * value option) list -> (env -> kind -> value) -> value
166
167(** Specialized builder for constant functions.
168  * It is slightly less opaque and allows the printing of the closure
169  * when the constant is ground. *)
170val val_cst_fun : (string * string * value option) list -> value -> value
171
172(** Convert a metadata packet to a list associating strings to strings. *)
173val metadata : Frame.metadata -> value
174
175(** {2 Errors raised by other modules} *)
176
177exception Invalid_value of value * string
178
179(** {2 Main script evaluation} *)
180
181(** Load the external libraries. *)
182val load_libs       : ?parse_only:bool -> unit -> unit
183
184(** Evaluate a script from an [in_channel]. *)
185val from_in_channel : ?parse_only:bool -> in_channel -> unit
186
187(** Evaluate a script from a file. *)
188val from_file       : ?parse_only:bool -> string -> unit
189
190(** Evaluate a script from a string. *)
191val from_string     : ?parse_only:bool -> string -> unit
Note: See TracBrowser for help on using the browser.