diff --git a/.ocamlformat b/.ocamlformat index 892a2080..e2dc5a5a 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -14,4 +14,5 @@ if-then-else=fit-or-vertical break-cases=all comment-check=false wrap-comments=false -doc-comments-padding=3 \ No newline at end of file +doc-comments-padding=3 +doc-comments=before \ No newline at end of file diff --git a/src/core/args.ml b/src/core/args.ml index 4383643e..c71ae51b 100644 --- a/src/core/args.ml +++ b/src/core/args.ml @@ -45,6 +45,7 @@ type code = | JavaCode [@@deriving show, eq, ord] +(** Stores the options passed to the command line *) type args = { mutable files : input list ; mutable dparse : bool @@ -66,7 +67,6 @@ type args = ; mutable prefix : string } [@@deriving show, eq, ord] -(** Stores the options passed to the command line *) let default_arguments : args = { files = [] diff --git a/src/core/env.ml b/src/core/env.ml index 4e74d244..662c77c8 100644 --- a/src/core/env.ml +++ b/src/core/env.ml @@ -605,6 +605,7 @@ let builtin_table extensions = ; [ "get" ], Scope.Function, Typ.Const.array_get (), false ; [ "size" ], Scope.Function, Typ.Const.array_size (), false ; [ "makeArray" ], Scope.Function, Typ.Const.array_make (), false + ; [ "makeComplexArray" ], Scope.Function, Typ.Const.array_make (), false ; [ "abs" ], Scope.Function, Typ.Const.freal_freal (), false ; [ "exp" ], Scope.Function, Typ.Const.freal_freal (), false ; [ "log10" ], Scope.Function, Typ.Const.freal_freal (), false diff --git a/src/core/interpreter.ml b/src/core/interpreter.ml index 40ec3ba1..a0c83f5b 100644 --- a/src/core/interpreter.ml +++ b/src/core/interpreter.ml @@ -61,8 +61,8 @@ module Env = struct ; tick : int } - type env = t list (** Non empty list of 't' *) + type env = t list let new_t () = { locals = [ SimpleMap.create 4 ] diff --git a/src/generators/codeJs.ml b/src/generators/codeJs.ml index 29252b82..6a62a031 100644 --- a/src/generators/codeJs.ml +++ b/src/generators/codeJs.ml @@ -55,6 +55,7 @@ module Templates = struct this.int_to_float = function(i) { return i; }; this.float_to_int = function(i) { return Math.floor(i); }; this.makeArray = function(size, v){ var a = new Array(size); for(var i=0;i +<#code#> +|pla} + let apply params (module_name : string) (template : string) (code : Pla.t) : (Pla.t * FileKind.t) list = match template with | "default" -> [ default params.config module_name code, FileKind.ExtOnly "lua" ] | "performance" -> Performance.getLua params (default params.config module_name code) | "vcv-prototype" -> [ vcv params.config module_name code, FileKind.ExtOnly "lua" ] + | "simple" -> [ simple params.config module_name code, FileKind.ExtOnly "lua" ] | _ -> [ none code, FileKind.ExtOnly "lua" ] end let isSpecial (params : params) (name : string) : bool = - if params.template <> "vcv-prototype" then + if params.template = "default" then match name with | _ when name = params.module_name ^ "_process" -> true | _ when name = params.module_name ^ "_noteOn" -> true @@ -379,6 +386,10 @@ let rec printSwitchStmt params e cases def = and printStmt (params : params) (stmt : cstmt) : Pla.t option = match stmt with + | CSBind (CLId (_, name), CECall ("makeComplexArray", [ size; CECall (init, [], _) ], _)) -> + let name = dot name in + let size_t = printExp params size in + Some {pla|<#name#> = makeComplexArray(<#size_t#>,<#init#s>);|pla} | CSVar (CLWild, None) -> None | CSVar (CLId (typ, name), None) -> let init = getInitValue typ in diff --git a/src/generators/generate.ml b/src/generators/generate.ml index a20cb769..8b61adbd 100644 --- a/src/generators/generate.ml +++ b/src/generators/generate.ml @@ -291,7 +291,7 @@ let checkConfig (config : config) (args : args) = let () = checksForVCVPrototype config args in if (args.code = CCode && args.template <> "default") - || (args.code = LuaCode && args.template <> "vcv-prototype") + || (args.code = LuaCode && args.template = "default") || args.code = JSCode then if diff --git a/src/generators/progToCode.ml b/src/generators/progToCode.ml index 2bd63702..b7bbdf4b 100644 --- a/src/generators/progToCode.ml +++ b/src/generators/progToCode.ml @@ -487,7 +487,8 @@ let rec convertStmt (p : parameters) (s : stmt) : cstmt = let attr = { is_root } in CSFunction (convertTypeMakeTupleUnit p ret, fname, arg_names, body', attr) (* special case for c/c++ to replace the makeArray function *) - | StmtBind (LWild _, PCall (NoInst, [ "makeArray" ], [ size; init; var ], attr), _) when p.code = CCode -> + | StmtBind (LWild _, PCall (NoInst, [ ("makeArray" | "makeComplexArray") ], [ size; init; var ], attr), _) + when p.code = CCode -> let init' = convertExp p init in let size' = convertExp p size in let init_typ = expType p init in diff --git a/src/generators/templates/config.ml b/src/generators/templates/config.ml index 25bbd8c9..0e0ce391 100644 --- a/src/generators/templates/config.ml +++ b/src/generators/templates/config.ml @@ -34,6 +34,7 @@ type output = | OInt | OBool +(** Represents the 'plugin' configuration *) type config = { module_name : string ; process_inputs : input list @@ -47,13 +48,13 @@ type config = ; update_outputs : output list ; update_found : bool } -(** Represents the 'plugin' configuration *) type target_file = | Implementation | Header | Tables +(** Represents the parameters used during code generation *) type params = { real : string (** 'Real' number representation *) ; template : string (** Used template *) @@ -64,7 +65,6 @@ type params = ; prefix : string (** Prefix given to java code *) ; config : config (** Plugin configuration *) } -(** Represents the parameters used during code generation *) (** Empty default configuration *) let empty_conf module_name = diff --git a/src/generators/templates/max.ml b/src/generators/templates/max.ml index c98c36fb..f58a046f 100644 --- a/src/generators/templates/max.ml +++ b/src/generators/templates/max.ml @@ -22,8 +22,8 @@ THE SOFTWARE. *) -open Config (** Template for the Teensy Audio library *) +open Config let tables (params : params) (code : Pla.t) : Pla.t = let file = String.uppercase params.output in diff --git a/src/generators/templates/pd.ml b/src/generators/templates/pd.ml index 22dcefc2..b7c58a67 100644 --- a/src/generators/templates/pd.ml +++ b/src/generators/templates/pd.ml @@ -22,8 +22,8 @@ THE SOFTWARE. *) -open Config (** Template for the Teensy Audio library *) +open Config let tables (params : params) (code : Pla.t) : Pla.t = let file = String.uppercase params.output in diff --git a/src/generators/templates/teensyAudio.ml b/src/generators/templates/teensyAudio.ml index 2c921694..95e9caee 100644 --- a/src/generators/templates/teensyAudio.ml +++ b/src/generators/templates/teensyAudio.ml @@ -22,8 +22,8 @@ THE SOFTWARE. *) -open Config (** Template for the Teensy Audio library *) +open Config let inputsArray n_inputs = if n_inputs > 0 then diff --git a/src/parser/ptypes.ml b/src/parser/ptypes.ml index 7634a532..7efff5be 100644 --- a/src/parser/ptypes.ml +++ b/src/parser/ptypes.ml @@ -76,6 +76,7 @@ type 'kind token = ; loc : Loc.t } +(** Type containing the stream of tokens *) type 'kind stream = { lexbuf : Lexing.lexbuf ; mutable has_errors : bool @@ -84,4 +85,3 @@ type 'kind stream = ; mutable prev : 'kind token ; lines : lexed_lines } -(** Type containing the stream of tokens *) diff --git a/src/parser/tokenStream.ml b/src/parser/tokenStream.ml index 0838d96e..5d6a0301 100644 --- a/src/parser/tokenStream.ml +++ b/src/parser/tokenStream.ml @@ -24,8 +24,8 @@ open Ptypes -exception ParserError of Error.t (** Parsing exception *) +exception ParserError of Error.t module type TokenKindSig = sig type kind @@ -42,6 +42,7 @@ module type TokenKindSig = sig end module TokenStream (S : TokenKindSig) = struct + (** Type containing the stream of tokens *) type stream = { lexbuf : Lexing.lexbuf ; mutable has_errors : bool @@ -50,7 +51,6 @@ module TokenStream (S : TokenKindSig) = struct ; mutable prev : S.kind token ; source : Loc.source } - (** Type containing the stream of tokens *) let backup (s : stream) = let lexbuf = diff --git a/src/passes/pass3.ml b/src/passes/pass3.ml index 26ceb9a6..7b93bc57 100644 --- a/src/passes/pass3.ml +++ b/src/passes/pass3.ml @@ -133,9 +133,14 @@ module CreateInitFunction = struct | Typ.TId ([ "bool" ], _) -> PBool (false, typedAttr) | Typ.TId (name, _) -> PCall (NoInst, getInitFunctioName name, [], typedAttr) | Typ.TComposed ([ "array" ], [ sub; { contents = Typ.TInt (size, _) } ], _) -> - let sub_init = getInitValue sub in + let init_sub = getInitValue sub in let intTypeAttr = { emptyAttr with typ = Some Typ.Const.int_type } in - PCall (NoInst, [ "makeArray" ], [ PInt (size, intTypeAttr); sub_init ], typedAttr) + let make_function = + match init_sub with + | PCall _ -> "makeComplexArray" + | _ -> "makeArray" + in + PCall (NoInst, [ make_function ], [ PInt (size, intTypeAttr); init_sub ], typedAttr) | Typ.TComposed ([ "tuple" ], types, _) -> let elems = List.map getInitValue types in PTuple (elems, typedAttr) diff --git a/src/util/loc.ml b/src/util/loc.ml index a59b4810..a4f49eca 100644 --- a/src/util/loc.ml +++ b/src/util/loc.ml @@ -22,20 +22,20 @@ THE SOFTWARE. *) -open Lexing (** Type to hold the location *) +open Lexing (** Source of the code *) type source = | File of string | Text of string +(** Location information *) type t = { start_pos : position ; end_pos : position ; source : source } -(** Location information *) let pp fmt _ = Format.pp_print_string fmt "loc" diff --git a/src/util/printBuffer.ml b/src/util/printBuffer.ml index b4dca388..af674a71 100644 --- a/src/util/printBuffer.ml +++ b/src/util/printBuffer.ml @@ -1,10 +1,10 @@ +(** String buffer with a few useful functions *) type print_buffer = { buffer : Buffer.t ; mutable indent : int ; mutable space : string ; mutable insert : bool } -(** String buffer with a few useful functions *) (** Creates a print buffer *) let makePrintBuffer () = { buffer = Buffer.create 100; indent = 0; space = ""; insert = false } diff --git a/test/code/ad.lua.base b/test/code/ad.lua.base index 01d8d7d5..19c8fb97 100644 --- a/test/code/ad.lua.base +++ b/test/code/ad.lua.base @@ -21,6 +21,7 @@ function sqrt(x) return x; end function set(a, i, v) a[i+1]=v; end function get(a, i) return a[i+1]; end function makeArray(size, v) local a = {}; for i=1,size do a[i]=v end return a; end +function makeComplexArray(size, f) local a = {}; for i=1,size do a[i]=f() end return a; end function wrap_array(a) return a; end function Util__ctx_type_0_init() diff --git a/test/code/adsr.lua.base b/test/code/adsr.lua.base index 6d4f5460..9844b961 100644 --- a/test/code/adsr.lua.base +++ b/test/code/adsr.lua.base @@ -21,6 +21,7 @@ function sqrt(x) return x; end function set(a, i, v) a[i+1]=v; end function get(a, i) return a[i+1]; end function makeArray(size, v) local a = {}; for i=1,size do a[i]=v end return a; end +function makeComplexArray(size, f) local a = {}; for i=1,size do a[i]=f() end return a; end function wrap_array(a) return a; end function Util__ctx_type_0_init() diff --git a/test/code/af_f.js.base.browser b/test/code/af_f.js.base.browser index 8084cd00..56398943 100644 --- a/test/code/af_f.js.base.browser +++ b/test/code/af_f.js.base.browser @@ -22,6 +22,7 @@ function vultProcess() { this.int_to_float = function(i) { return i; }; this.float_to_int = function(i) { return Math.floor(i); }; this.makeArray = function(size, v){ var a = new Array(size); for(var i=0;i