From 59f577996e35109592b904522d4f0733b2722f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=94=84=EB=A6=AC=EB=A7=88?= Date: Sat, 1 Jun 2024 20:11:56 -0400 Subject: [PATCH] tests --- apps/builder/Builder.dib | 2 +- apps/plot/plot.rs | 2 +- apps/spiral/Eval.dib | 2 +- apps/spiral/Supervisor.dib | 2 +- apps/spiral/builder/spiral_builder.dib | 2 +- lib/fsharp/Plotting.dib | 2 +- lib/spiral/am'.dib | 8 +- lib/spiral/am'.spi | 8 +- lib/spiral/am'_prototypes.spi | 3 + lib/spiral/base.dib | 498 ++++++++++++++----------- lib/spiral/base.spi | 311 ++++++++------- lib/spiral/common.py | 16 +- lib/spiral/file_system.dib | 4 +- lib/spiral/file_system.fsx | 2 +- lib/spiral/file_system.py | 198 +++++----- lib/spiral/file_system.spi | 2 +- lib/spiral/iter.dib | 3 +- lib/spiral/iter.spi | 3 +- lib/spiral/lib.ps1 | 2 +- lib/spiral/package.spiproj | 4 +- lib/spiral/runtime.dib | 11 +- lib/spiral/runtime.spi | 11 +- lib/spiral/sm'_prototypes.spi | 2 + lib/spiral/sm.py | 44 +-- 24 files changed, 608 insertions(+), 534 deletions(-) create mode 100644 lib/spiral/am'_prototypes.spi create mode 100644 lib/spiral/sm'_prototypes.spi diff --git a/apps/builder/Builder.dib b/apps/builder/Builder.dib index 3ef7381a..72ef0b05 100644 --- a/apps/builder/Builder.dib +++ b/apps/builder/Builder.dib @@ -96,7 +96,7 @@ let inline persistCodeProject packages modules name hash code = async { let workspaceRoot = SpiralFileSystem.get_workspace_root () let targetDir = - let targetDir = workspaceRoot "target/polyglot/builder" name + let targetDir = workspaceRoot "target/Builder" name match hash with | Some hash -> targetDir "packages" hash | None -> targetDir diff --git a/apps/plot/plot.rs b/apps/plot/plot.rs index 8c545f34..aa2d079b 100644 --- a/apps/plot/plot.rs +++ b/apps/plot/plot.rs @@ -82,7 +82,7 @@ fn draw_line_plot( fn main() -> Result<(), Box> { let workspace_root = plot::SpiralFileSystem::get_workspace_root(); let workspace_root = std::path::PathBuf::from(workspace_root.to_string()); - let tmp_spiral_dir = workspace_root.join("target/polyglot/plotting"); + let tmp_spiral_dir = workspace_root.join("target/plot"); let line_plots_data_dir = tmp_spiral_dir.join("line_data"); let line_plots_svg_dir = tmp_spiral_dir.join("line_svg"); diff --git a/apps/spiral/Eval.dib b/apps/spiral/Eval.dib index 355ed5ab..4e945290 100644 --- a/apps/spiral/Eval.dib +++ b/apps/spiral/Eval.dib @@ -130,7 +130,7 @@ let inline mapErrors (severity, errors, lastTopLevelIndex) allCode = #!fsharp let workspaceRoot = SpiralFileSystem.get_workspace_root () -let targetDir = workspaceRoot "target/polyglot/spiral_eval" +let targetDir = workspaceRoot "target/spiral_Eval" [ targetDir ] |> List.iter (fun dir -> if Directory.Exists dir |> not then Directory.CreateDirectory dir |> ignore) diff --git a/apps/spiral/Supervisor.dib b/apps/spiral/Supervisor.dib index 0d26dd30..95dede11 100644 --- a/apps/spiral/Supervisor.dib +++ b/apps/spiral/Supervisor.dib @@ -373,7 +373,7 @@ let inline buildFile timeout port cancellationToken path = async { #!fsharp let inline persistCode code = async { - let targetDir = workspaceRoot "target/polyglot/spiral_eval" + let targetDir = workspaceRoot "target/spiral_Eval" let packagesDir = targetDir "packages" diff --git a/apps/spiral/builder/spiral_builder.dib b/apps/spiral/builder/spiral_builder.dib index 6e2e056c..7efc2e64 100644 --- a/apps/spiral/builder/spiral_builder.dib +++ b/apps/spiral/builder/spiral_builder.dib @@ -184,7 +184,7 @@ inl persist_code_project packages modules name hash code = inl workspace_root = file_system.get_workspace_root () inl target_dir = - inl target_dir = workspace_root "target/polyglot/spiral_builder" name + inl target_dir = workspace_root "target/spiral_builder" name match hash with | Some hash => target_dir "packages" hash | None => target_dir diff --git a/lib/fsharp/Plotting.dib b/lib/fsharp/Plotting.dib index b2ade40d..aac16dc7 100644 --- a/lib/fsharp/Plotting.dib +++ b/lib/fsharp/Plotting.dib @@ -37,7 +37,7 @@ open SpiralFileSystem.Operators #!fsharp let workspaceRoot = SpiralFileSystem.get_workspace_root () -let tmpSpiralPath = workspaceRoot "target/polyglot/plotting" +let tmpSpiralPath = workspaceRoot "target/plot" let linePlotsDataPath = tmpSpiralPath "line_data" let linePlotsSvgPath = tmpSpiralPath "line_svg" diff --git a/lib/spiral/am'.dib b/lib/spiral/am'.dib index 2332bf4c..88f703cb 100644 --- a/lib/spiral/am'.dib +++ b/lib/spiral/am'.dib @@ -18,7 +18,7 @@ open rust_operators #!markdown -## types () +## types #!spiral @@ -725,12 +725,10 @@ inl any forall t. (fn : t -> bool) (source : array_base t) : bool = #!spiral -open iter_prototypes - -instance iter_collect vec = fun (iter : iter_prototypes.into_iterator u) => +instance iter_collect vec = fun (iter : into_iterator u) => !\($'"!iter.collect::>()"') -instance iter_collect'' vec = fun (iter : iter_prototypes.into_iterator (t (u v))) => +instance iter_collect'' vec = fun (iter : into_iterator (t (u v))) => !\($'"!iter.collect::>()"') #!markdown diff --git a/lib/spiral/am'.spi b/lib/spiral/am'.spi index 1d10c8a1..ce7087d1 100644 --- a/lib/spiral/am'.spi +++ b/lib/spiral/am'.spi @@ -1,7 +1,7 @@ /// # am' open rust_operators -/// ## types () +/// ## types inl types () = global "#if FABLE_COMPILER\n[]\n#endif\ntype Slice<'T> = class end" global "#if FABLE_COMPILER\n[]\n#endif\ntype Slice'<'T> = class end" @@ -332,12 +332,10 @@ inl any forall t. (fn : t -> bool) (source : array_base t) : bool = !\($'"!source.any(|x| !fn(x))"') /// ## iter_collect vec -open iter_prototypes - -instance iter_collect vec = fun (iter : iter_prototypes.into_iterator u) => +instance iter_collect vec = fun (iter : into_iterator u) => !\($'"!iter.collect::>()"') -instance iter_collect'' vec = fun (iter : iter_prototypes.into_iterator (t (u v))) => +instance iter_collect'' vec = fun (iter : into_iterator (t (u v))) => !\($'"!iter.collect::>()"') /// ## new_vec diff --git a/lib/spiral/am'_prototypes.spi b/lib/spiral/am'_prototypes.spi new file mode 100644 index 00000000..1f633d32 --- /dev/null +++ b/lib/spiral/am'_prototypes.spi @@ -0,0 +1,3 @@ +/// ### array +inl array x = + x diff --git a/lib/spiral/base.dib b/lib/spiral/base.dib index 4922f62a..19211f0a 100644 --- a/lib/spiral/base.dib +++ b/lib/spiral/base.dib @@ -14,146 +14,159 @@ open testing #!markdown -## array - -#!spiral - -inl array x = x +## arithmetic #!markdown -## prototype +### (+.) #!spiral -prototype append t : t -> t -> t -prototype of_string t : string -> option t -prototype to_string t : t -> string +inl (+.) forall t. (a : t) (b : t) : t = + $'!a + !b ' #!markdown -## infer +### (-.) #!spiral -nominal infer = $'_' +inl (-.) forall t. (a : t) (b : t) : t = + $'!a - !b ' #!markdown -## invoke +### (*.) #!spiral -inl invoke fn = - fn () +inl (*.) forall t. (a : t) (b : t) : t = + $'!a * !b ' #!markdown -## not_join +### (/.) #!spiral -inl not_join x = - join not x +inl (/.) forall t. (a : t) (b : t) : t = + $'!a / !b ' + +#!markdown + +## comparison #!markdown -## (+.) +### (=.) #!spiral -inl (+.) forall t. (a : t) (b : t) : t = - $'!a + !b ' +inl (=.) forall t. (a : t) (b : t) : bool = + $'!a = !b ' #!markdown -## (-.) +### (<>.) #!spiral -inl (-.) forall t. (a : t) (b : t) : t = - $'!a - !b ' +inl (<>.) forall t. (a : t) (b : t) : bool = + $'!a <> !b ' + +#!markdown + +## composition #!markdown -## (*.) +### append #!spiral -inl (*.) forall t. (a : t) (b : t) : t = - $'!a * !b ' +prototype append t : t -> t -> t #!markdown -## (/.) +### (++) #!spiral -inl (/.) forall t. (a : t) (b : t) : t = - $'!a / !b ' +inl (++) a b = + b |> append a + +#!markdown + +## application #!markdown -## (=.) +### (||>) #!spiral -inl (=.) forall t. (a : t) (b : t) : bool = - $'!a = !b ' +inl (||>) (arg1, arg2) fn = + arg2 |> fn arg1 + +#!markdown + +## logic #!markdown -## (<>.) +### not_join #!spiral -inl (<>.) forall t. (a : t) (b : t) : bool = - $'!a <> !b ' +inl not_join x = + join not x #!markdown -## (||>) +### fix_condition #!spiral -inl (||>) (arg1, arg2) fn = - arg2 |> fn arg1 +inl fix_condition x a b = + if x () + then a () |> fun x => $'(*' : () + else + $'*) else' : () + b () |> fun x => $'(*' : () + |> fun x => $'*)' : () #!markdown -## (++) +## type + +#!markdown + +### infer #!spiral -inl (++) a b = - b |> append a +nominal infer = $'_' #!markdown -## target_runtime +### any #!spiral -union target_runtime = - | Native - | Wasm - | Contract +nominal any = $'obj' #!markdown -## target +### null #!spiral -union target = - | Rust : target_runtime - | Fsharp : target_runtime - | TypeScript : target_runtime - | Python : target_runtime +inl null forall t. () : t = + $'null |> unbox<`t>' #!markdown -## defaultof +### defaultof #!spiral @@ -162,7 +175,11 @@ inl defaultof forall t. () : t = #!markdown -## emit +## execution + +#!markdown + +### emit #!spiral @@ -171,7 +188,7 @@ inl emit forall t. (x : t) : t = #!markdown -## emit_unit +### emit_unit #!spiral @@ -180,15 +197,146 @@ inl emit_unit forall t. (x : t) : () = #!markdown +### use + +#!spiral + +inl use forall t. (x : t) : t = + $'use !x = !x ' : () + $'!x ' + +#!markdown + +## function + +#!markdown + +### invoke + +#!spiral + +inl invoke fn = + fn () + +#!markdown + +### capture + +#!spiral + +inl capture forall t. (fn : () -> t) : t = + inl result = dyn true + $'let mutable _!result : `t option = None ' + $'(' + $'(fun () ->' + $'(fun () ->' + fn () |> emit_unit + $')' + $'|> fun x -> x ()' + $') () )' + $'|> fun x -> _!result <- Some x' + $'match _!result with Some x -> x | None -> failwith "base.capture / _!result=None"' + +#!markdown + +### memoize + +#!spiral + +nominal lazy t = $'Lazy<`t>' + +inl memoize forall t. (fn : () -> t) : () -> t = + inl fn = join fn + inl result : lazy t = $'lazy !fn ()' + fun () => $'!result.Value' + +#!spiral + +//// test + +inl count = mut 0i32 +inl add = + fun () => count <- *count + 1 + |> memoize + +add () +add () +add () + +*count +|> _assert_eq 1 + +#!markdown + +## pair + +#!markdown + +### pair + +#!spiral + +nominal pair a b = $'(`a * `b)' + +inl pair x y = + x, y + +#!spiral + +//// test + +pair 1i32 2i32 +|> _assert_eq (1, 2) + +#!markdown + +### new_pair + +#!spiral + +inl new_pair forall a b. (a : a) (b : b) : pair a b = + $'!a, !b ' + +#!markdown + +### from_pair + +#!spiral + +inl from_pair forall a b. (pair : pair a b) : a * b = + $'let (a, b) = !pair ' + $'a', $'b' + +#!spiral + +//// test + +new_pair "a" 1i32 +|> from_pair +|> _assert_eq ("a", 1i32) + +#!spiral + +//// test + +new_pair "a" (new_pair 1i32 "b") +|> from_pair + +#!markdown + ## ref +#!markdown + +### ref + #!spiral nominal ref t = $'`t ref' #!markdown -## new_ref +### new_ref #!spiral @@ -197,7 +345,7 @@ inl new_ref forall t. (x : t) : ref t = #!markdown -## ref_value +### ref_value #!spiral @@ -206,7 +354,7 @@ inl ref_value forall t. (x : ref t) : t = #!markdown -## ref_set_value +### ref_set_value #!spiral @@ -216,35 +364,34 @@ inl ref_set_value forall t. (value : t) (ref : ref t) : ref t = #!markdown -## unbox +## target + +#!markdown + +### target_runtime #!spiral -inl unbox forall t u. (x : t) : u = - $'!x |> unbox<`u>' +union target_runtime = + | Native + | Wasm + | Contract #!markdown -## capture +### target #!spiral -inl capture forall t. (fn : () -> t) : t = - inl result = dyn true - $'let mutable _!result : `t option = None ' - $'(' - $'(fun () ->' - $'(fun () ->' - fn () |> emit_unit - $')' - $'|> fun x -> x ()' - $') () )' - $'|> fun x -> _!result <- Some x' - $'match _!result with Some x -> x | None -> failwith "base.capture / _!result=None"' +union target = + | Rust : target_runtime + | Fsharp : target_runtime + | TypeScript : target_runtime + | Python : target_runtime #!markdown -## run_target +### run_target #!spiral @@ -293,80 +440,29 @@ run_target function #!markdown -## exn - -#!spiral - -nominal exn = $'exn' - -#!markdown - -## try - -#!spiral - -inl try forall t. (fn : () -> t) (ex_fn : exn -> option t) : option t = - inl none = None : option t - inl some (s : t) = Some s - $'try !fn () |> !some with ex -> !ex_fn ex ' - -#!markdown - -## try_unit - -#!spiral - -inl try_unit forall t. (fn : () -> ()) (ex_fn : exn -> ()) : t = - $'try' - fn () - |> ignore - $'with ex ->' - ex_fn $'ex' - |> ignore - $'(*' - $'*)' - -#!markdown - -## try_finally - -#!spiral - -inl try_finally forall t. (fn : () -> ()) (finally : () -> ()) : t = - $'try' - fn () - |> ignore - $'finally' - finally () - |> ignore - $'(*' - $'*)' +## convert #!markdown -## fix_condition +### convert #!spiral -inl fix_condition x a b = - if x () - then a () |> fun x => $'(*' : () - else - $'*) else' : () - b () |> fun x => $'(*' : () - |> fun x => $'*)' : () +inl convert forall t u. (x : t) : u = + $'!x |> `u ' #!markdown -## any +### unbox #!spiral -nominal any = $'obj' +inl unbox forall t u. (x : t) : u = + $'!x |> unbox<`u>' #!markdown -## u8 +### u8 #!spiral @@ -375,7 +471,7 @@ inl u8 forall t. (x : t) : u8 = #!markdown -## u16 +### u16 #!spiral @@ -384,7 +480,7 @@ inl u16 forall t. (x : t) : u16 = #!markdown -## u64 +### u64 #!spiral @@ -393,7 +489,7 @@ inl u64 forall t. (x : t) : u64 = #!markdown -## i32 +### i32 #!spiral @@ -402,7 +498,7 @@ inl i32 forall t. (x : t) : i32 = #!markdown -## i64 +### i64 #!spiral @@ -411,7 +507,7 @@ inl i64 forall t. (x : t) : i64 = #!markdown -## f32 +### f32 #!spiral @@ -420,7 +516,7 @@ inl f32 forall t. (x : t) : f32 = #!markdown -## f64 +### f64 #!spiral @@ -429,7 +525,7 @@ inl f64 forall t. (x : t) : f64 = #!markdown -## unativeint +### unativeint #!spiral @@ -437,7 +533,7 @@ nominal unativeint = $'unativeint' #!markdown -## convert_i32 +### convert_i32 #!spiral @@ -446,7 +542,7 @@ inl convert_i32 forall t. (x : t) : i32 = #!markdown -## convert_i32_base +### convert_i32_base #!spiral @@ -455,91 +551,66 @@ inl convert_i32_base forall t. (base : i32) (x : t) : i32 = #!markdown -## convert - -#!spiral - -inl convert forall t u. (x : t) : u = - $'!x |> `u ' +## error #!markdown -## pair +### exn #!spiral -nominal pair a b = $'(`a * `b)' - -inl pair x y = - x, y +nominal exn = $'exn' #!markdown -## null +### try #!spiral -inl null forall t. () : t = - $'null |> unbox<`t>' +inl try forall t. (fn : () -> t) (ex_fn : exn -> option t) : option t = + inl none = None : option t + inl some (s : t) = Some s + $'try !fn () |> !some with ex -> !ex_fn ex ' #!markdown -## use +### try_unit #!spiral -inl use forall t. (x : t) : t = - $'use !x = !x ' : () - $'!x ' +inl try_unit forall t. (fn : () -> ()) (ex_fn : exn -> ()) : t = + $'try' + fn () + |> ignore + $'with ex ->' + ex_fn $'ex' + |> ignore + $'(*' + $'*)' #!markdown -## pair +### try_finally #!spiral -//// test - -pair 1i32 2i32 -|> _assert_eq (1, 2) +inl try_finally forall t. (fn : () -> ()) (finally : () -> ()) : t = + $'try' + fn () + |> ignore + $'finally' + finally () + |> ignore + $'(*' + $'*)' #!markdown -## new_pair - -#!spiral - -inl new_pair forall a b. (a : a) (b : b) : pair a b = - $'!a, !b ' +## reflection #!markdown -## from_pair - -#!spiral - -inl from_pair forall a b. (pair : pair a b) : a * b = - $'let (a, b) = !pair ' - $'a', $'b' - -#!spiral - -//// test - -new_pair "a" 1i32 -|> from_pair -|> _assert_eq ("a", 1i32) - -#!spiral - -//// test - -new_pair "a" (new_pair 1i32 "b") -|> from_pair - -#!markdown - -## get_union_fields +### get_union_fields #!spiral @@ -570,7 +641,7 @@ fields #!markdown -## get_union_fields_untag +### get_union_fields_untag #!spiral @@ -603,32 +674,3 @@ fields |> listm'.to_array' |> fun x => x : a i32 _ |> _assert_eq (a ;[ Native; Wasm; Contract ]) - -#!markdown - -## memoize - -#!spiral - -nominal lazy t = $'Lazy<`t>' - -inl memoize forall t. (fn : () -> t) : () -> t = - inl fn = join fn - inl result : lazy t = $'lazy !fn ()' - fun () => $'!result.Value' - -#!spiral - -//// test - -inl count = mut 0i32 -inl add = - fun () => count <- *count + 1 - |> memoize - -add () -add () -add () - -*count -|> _assert_eq 1 diff --git a/lib/spiral/base.spi b/lib/spiral/base.spi index 191e1d21..b180a05e 100644 --- a/lib/spiral/base.spi +++ b/lib/spiral/base.spi @@ -1,102 +1,101 @@ /// # base -/// ## array -inl array x = x +/// ## arithmetic -/// ## prototype -prototype append t : t -> t -> t -prototype of_string t : string -> option t -prototype to_string t : t -> string - -/// ## infer -nominal infer = $'_' - -/// ## invoke -inl invoke fn = - fn () - -/// ## not_join -inl not_join x = - join not x - -/// ## (+.) +/// ### (+.) inl (+.) forall t. (a : t) (b : t) : t = $'!a + !b ' -/// ## (-.) +/// ### (-.) inl (-.) forall t. (a : t) (b : t) : t = $'!a - !b ' -/// ## (*.) +/// ### (*.) inl (*.) forall t. (a : t) (b : t) : t = $'!a * !b ' -/// ## (/.) +/// ### (/.) inl (/.) forall t. (a : t) (b : t) : t = $'!a / !b ' -/// ## (=.) +/// ## comparison + +/// ### (=.) inl (=.) forall t. (a : t) (b : t) : bool = $'!a = !b ' -/// ## (<>.) +/// ### (<>.) inl (<>.) forall t. (a : t) (b : t) : bool = $'!a <> !b ' -/// ## (||>) -inl (||>) (arg1, arg2) fn = - arg2 |> fn arg1 +/// ## composition -/// ## (++) +/// ### append +prototype append t : t -> t -> t + +/// ### (++) inl (++) a b = b |> append a -/// ## target_runtime -union target_runtime = - | Native - | Wasm - | Contract +/// ## application -/// ## target -union target = - | Rust : target_runtime - | Fsharp : target_runtime - | TypeScript : target_runtime - | Python : target_runtime +/// ### (||>) +inl (||>) (arg1, arg2) fn = + arg2 |> fn arg1 + +/// ## logic + +/// ### not_join +inl not_join x = + join not x + +/// ### fix_condition +inl fix_condition x a b = + if x () + then a () |> fun x => $'(*' : () + else + $'*) else' : () + b () |> fun x => $'(*' : () + |> fun x => $'*)' : () -/// ## defaultof +/// ## type + +/// ### infer +nominal infer = $'_' + +/// ### any +nominal any = $'obj' + +/// ### null +inl null forall t. () : t = + $'null |> unbox<`t>' + +/// ### defaultof inl defaultof forall t. () : t = $'Unchecked.defaultof<`t>' -/// ## emit +/// ## execution + +/// ### emit inl emit forall t. (x : t) : t = $'!x ' -/// ## emit_unit +/// ### emit_unit inl emit_unit forall t. (x : t) : () = $'!x ' -/// ## ref -nominal ref t = $'`t ref' - -/// ## new_ref -inl new_ref forall t. (x : t) : ref t = - $'ref !x ' - -/// ## ref_value -inl ref_value forall t. (x : ref t) : t = - $'!x.Value' +/// ### use +inl use forall t. (x : t) : t = + $'use !x = !x ' : () + $'!x ' -/// ## ref_set_value -inl ref_set_value forall t. (value : t) (ref : ref t) : ref t = - $'!ref.Value <- !value ' - ref +/// ## function -/// ## unbox -inl unbox forall t u. (x : t) : u = - $'!x |> unbox<`u>' +/// ### invoke +inl invoke fn = + fn () -/// ## capture +/// ### capture inl capture forall t. (fn : () -> t) : t = inl result = dyn true $'let mutable _!result : `t option = None ' @@ -110,7 +109,65 @@ inl capture forall t. (fn : () -> t) : t = $'|> fun x -> _!result <- Some x' $'match _!result with Some x -> x | None -> failwith "base.capture / _!result=None"' -/// ## run_target +/// ### memoize +nominal lazy t = $'Lazy<`t>' + +inl memoize forall t. (fn : () -> t) : () -> t = + inl fn = join fn + inl result : lazy t = $'lazy !fn ()' + fun () => $'!result.Value' + +/// ## pair + +/// ### pair +nominal pair a b = $'(`a * `b)' + +inl pair x y = + x, y + +/// ### new_pair +inl new_pair forall a b. (a : a) (b : b) : pair a b = + $'!a, !b ' + +/// ### from_pair +inl from_pair forall a b. (pair : pair a b) : a * b = + $'let (a, b) = !pair ' + $'a', $'b' + +/// ## ref + +/// ### ref +nominal ref t = $'`t ref' + +/// ### new_ref +inl new_ref forall t. (x : t) : ref t = + $'ref !x ' + +/// ### ref_value +inl ref_value forall t. (x : ref t) : t = + $'!x.Value' + +/// ### ref_set_value +inl ref_set_value forall t. (value : t) (ref : ref t) : ref t = + $'!ref.Value <- !value ' + ref + +/// ## target + +/// ### target_runtime +union target_runtime = + | Native + | Wasm + | Contract + +/// ### target +union target = + | Rust : target_runtime + | Fsharp : target_runtime + | TypeScript : target_runtime + | Python : target_runtime + +/// ### run_target inl run_target forall t. (fn : target -> (() -> t)) : t = inl result = dyn true $'let mutable _!result : `t option = None ' @@ -131,119 +188,91 @@ inl run_target forall t. (fn : target -> (() -> t)) : t = $'|> fun x -> _!result <- Some x' $'match _!result with Some x -> x | None -> failwith "base.run_target / _!result=None"' -/// ## exn -nominal exn = $'exn' - -/// ## try -inl try forall t. (fn : () -> t) (ex_fn : exn -> option t) : option t = - inl none = None : option t - inl some (s : t) = Some s - $'try !fn () |> !some with ex -> !ex_fn ex ' - -/// ## try_unit -inl try_unit forall t. (fn : () -> ()) (ex_fn : exn -> ()) : t = - $'try' - fn () - |> ignore - $'with ex ->' - ex_fn $'ex' - |> ignore - $'(*' - $'*)' - -/// ## try_finally -inl try_finally forall t. (fn : () -> ()) (finally : () -> ()) : t = - $'try' - fn () - |> ignore - $'finally' - finally () - |> ignore - $'(*' - $'*)' +/// ## convert -/// ## fix_condition -inl fix_condition x a b = - if x () - then a () |> fun x => $'(*' : () - else - $'*) else' : () - b () |> fun x => $'(*' : () - |> fun x => $'*)' : () +/// ### convert +inl convert forall t u. (x : t) : u = + $'!x |> `u ' -/// ## any -nominal any = $'obj' +/// ### unbox +inl unbox forall t u. (x : t) : u = + $'!x |> unbox<`u>' -/// ## u8 +/// ### u8 inl u8 forall t. (x : t) : u8 = x |> $'uint8' -/// ## u16 +/// ### u16 inl u16 forall t. (x : t) : u16 = x |> $'uint16' -/// ## u64 +/// ### u64 inl u64 forall t. (x : t) : u64 = x |> $'uint64' -/// ## i32 +/// ### i32 inl i32 forall t. (x : t) : i32 = x |> $'int32' -/// ## i64 +/// ### i64 inl i64 forall t. (x : t) : i64 = x |> $'int64' -/// ## f32 +/// ### f32 inl f32 forall t. (x : t) : f32 = x |> $'float32' -/// ## f64 +/// ### f64 inl f64 forall t. (x : t) : f64 = x |> $'float' -/// ## unativeint +/// ### unativeint nominal unativeint = $'unativeint' -/// ## convert_i32 +/// ### convert_i32 inl convert_i32 forall t. (x : t) : i32 = x |> $'System.Convert.ToInt32' -/// ## convert_i32_base +/// ### convert_i32_base inl convert_i32_base forall t. (base : i32) (x : t) : i32 = $'System.Convert.ToInt32 (!x, !base)' -/// ## convert -inl convert forall t u. (x : t) : u = - $'!x |> `u ' +/// ## error -/// ## pair -nominal pair a b = $'(`a * `b)' - -inl pair x y = - x, y - -/// ## null -inl null forall t. () : t = - $'null |> unbox<`t>' +/// ### exn +nominal exn = $'exn' -/// ## use -inl use forall t. (x : t) : t = - $'use !x = !x ' : () - $'!x ' +/// ### try +inl try forall t. (fn : () -> t) (ex_fn : exn -> option t) : option t = + inl none = None : option t + inl some (s : t) = Some s + $'try !fn () |> !some with ex -> !ex_fn ex ' -/// ## pair +/// ### try_unit +inl try_unit forall t. (fn : () -> ()) (ex_fn : exn -> ()) : t = + $'try' + fn () + |> ignore + $'with ex ->' + ex_fn $'ex' + |> ignore + $'(*' + $'*)' -/// ## new_pair -inl new_pair forall a b. (a : a) (b : b) : pair a b = - $'!a, !b ' +/// ### try_finally +inl try_finally forall t. (fn : () -> ()) (finally : () -> ()) : t = + $'try' + fn () + |> ignore + $'finally' + finally () + |> ignore + $'(*' + $'*)' -/// ## from_pair -inl from_pair forall a b. (pair : pair a b) : a * b = - $'let (a, b) = !pair ' - $'a', $'b' +/// ## reflection -/// ## get_union_fields +/// ### get_union_fields inl get_union_fields forall union_type. () : list union_type = real real_core.union_to_record @@ -257,7 +286,7 @@ inl get_union_fields forall union_type. () : list union_type = (Nil `union_type) `union_record_type -/// ## get_union_fields_untag +/// ### get_union_fields_untag inl get_union_fields_untag forall union_type. () : list union_type = real real_core.union_to_record @@ -276,11 +305,3 @@ inl get_union_fields_untag forall union_type. () : list union_type = (Nil `union_type, 0i32) inl result = fst `(list union_type) `i32 result listm.rev `union_type result - -/// ## memoize -nominal lazy t = $'Lazy<`t>' - -inl memoize forall t. (fn : () -> t) : () -> t = - inl fn = join fn - inl result : lazy t = $'lazy !fn ()' - fun () => $'!result.Value' diff --git a/lib/spiral/common.py b/lib/spiral/common.py index e71485fe..a4ee59d2 100644 --- a/lib/spiral/common.py +++ b/lib/spiral/common.py @@ -99,7 +99,7 @@ class Mut3(Record): Mut3_reflection = _expr15 -def _expr17() -> TypeInfo: +def _expr18() -> TypeInfo: return union_type("Common.US1", [], US1, lambda: [[("f0_0", int64_type)], []]) @@ -115,7 +115,7 @@ def cases() -> list[str]: return ["US1_0", "US1_1"] -US1_reflection = _expr17 +US1_reflection = _expr18 def _expr19() -> TypeInfo: return union_type("Common.US2", [], US2, lambda: [[("f0_0", US0_reflection())], []]) @@ -171,7 +171,7 @@ def cases() -> list[str]: US4_reflection = _expr21 -def _expr22() -> TypeInfo: +def _expr24() -> TypeInfo: return union_type("Common.US5", [], US5, lambda: [[("f0_0", US4_reflection())], []]) @@ -187,7 +187,7 @@ def cases() -> list[str]: return ["US5_0", "US5_1"] -US5_reflection = _expr22 +US5_reflection = _expr24 def US0__get_IsUS0_0(this: FSharpRef[US0], unit_arg: None) -> bool: if this.tag == 0: @@ -454,11 +454,11 @@ def x_1(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_ _v93.contents = x_2 v98: US1 = default_arg(_v93.contents, US1(1)) - def _arrow40(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> Any: + def _arrow44(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> Any: v105: Any = create(op_subtraction(ticks_1(now()), v98.fields[0])) return create_1(1, 1, 1, hours(v105), minutes(v105), seconds(v105), milliseconds(v105)) - x_3: str = to_string(_arrow40() if (v98.tag == 0) else now(), method10()) + x_3: str = to_string(_arrow44() if (v98.tag == 0) else now(), method10()) _v10 = x_3 v147: str if _v10 is None: @@ -471,10 +471,10 @@ def _arrow40(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, _v161: str | None = None x_5: str = pad_left(v157.lower(), 7, " ") _v161 = x_5 - def _arrow47(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> str: + def _arrow51(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> str: raise Exception("base.run_target / _v161=None") - return trim_end(trim_start(((((((((("" + v147) + " ") + (_arrow47() if (_v161 is None) else _v161)) + " #") + str(pattern_input[0].l0)) + " ") + v1_1(None)) + " / ") + v2_1(None)) + ""), " ", "/") + return trim_end(trim_start(((((((((("" + v147) + " ") + (_arrow51() if (_v161 is None) else _v161)) + " #") + str(pattern_input[0].l0)) + " ") + v1_1(None)) + " / ") + v2_1(None)) + ""), " ", "/") def method11(v0_1: US0, v1_1: Callable[[], str]) -> None: diff --git a/lib/spiral/file_system.dib b/lib/spiral/file_system.dib index 93aa9cce..9e87f7e7 100644 --- a/lib/spiral/file_system.dib +++ b/lib/spiral/file_system.dib @@ -1565,7 +1565,7 @@ let rec trace_file text = inl file_name = $'$"{!assembly_name}_{!guid}.txt"' inl workspace_root = get_workspace_root () - inl trace_dir = workspace_root "target/polyglot/trace" + inl trace_dir = workspace_root "target/trace" trace_dir |> create_directory |> ignore inl path = trace_dir file_name text |> write_all_text_async path |> async.run_synchronously @@ -1582,7 +1582,7 @@ inl get_count dir : i64 = a files |> am'.length types () -inl trace_dir = file_system.get_workspace_root () "target/polyglot/trace" +inl trace_dir = file_system.get_workspace_root () "target/trace" trace_dir |> file_system.create_directory |> ignore inl count = get_count trace_dir diff --git a/lib/spiral/file_system.fsx b/lib/spiral/file_system.fsx index b34021d6..4cf39995 100644 --- a/lib/spiral/file_system.fsx +++ b/lib/spiral/file_system.fsx @@ -10868,7 +10868,7 @@ and method49 (v0 : string) : unit = let v11 : string = method28(v9, v10) let v12 : string = method47(v11, v8) let v13 : string = method28(v12, v9) - let v14 : string = "target/polyglot/trace" + let v14 : string = "target/trace" let v15 : string = method28(v13, v14) let v16 : bool = true let mutable _v16 : System.IO.DirectoryInfo option = None diff --git a/lib/spiral/file_system.py b/lib/spiral/file_system.py index dd036786..64d449a8 100644 --- a/lib/spiral/file_system.py +++ b/lib/spiral/file_system.py @@ -799,11 +799,11 @@ def x_1(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_ _v93.contents = x_2 v98: US1 = default_arg(_v93.contents, US1(1)) - def _arrow236(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> Any: + def _arrow227(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> Any: v105: Any = create(op_subtraction(ticks_1(now()), v98.fields[0])) return create_1(1, 1, 1, hours(v105), minutes(v105), seconds(v105), milliseconds(v105)) - x_3: str = to_string(_arrow236() if (v98.tag == 0) else now(), method12()) + x_3: str = to_string(_arrow227() if (v98.tag == 0) else now(), method12()) _v10 = x_3 v147: str if _v10 is None: @@ -816,10 +816,10 @@ def _arrow236(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, _v161: str | None = None x_5: str = pad_left(v157.lower(), 7, " ") _v161 = x_5 - def _arrow237(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> str: + def _arrow228(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, unit_var: Any=unit_var) -> str: raise Exception("base.run_target / _v161=None") - return trim_end(trim_start(((((((((("" + v147) + " ") + (_arrow237() if (_v161 is None) else _v161)) + " #") + str(pattern_input[0].l0)) + " ") + v1_1(None)) + " / ") + v2_1(None)) + ""), " ", "/") + return trim_end(trim_start(((((((((("" + v147) + " ") + (_arrow228() if (_v161 is None) else _v161)) + " #") + str(pattern_input[0].l0)) + " ") + v1_1(None)) + " / ") + v2_1(None)) + ""), " ", "/") def method13(v0_1: US0, v1_1: Callable[[], str]) -> None: @@ -836,17 +836,17 @@ def v2_1(v: US0, v0_1: Any=v0_1, v1_1: Any=v1_1) -> tuple[Mut0, Mut1, Mut2, int6 pattern_input_1: tuple[Mut0, Mut1, Mut2, int64 | None, Mut3] = value_4(State_trace_state()) v15_1: US0 = pattern_input_1[2].l0 - class ObjectExpr238: + class ObjectExpr229: @property def Compare(self) -> Callable[[US0, US0], int]: return compare - class ObjectExpr239: + class ObjectExpr230: @property def Compare(self) -> Callable[[US0, US0], int]: return compare - if False if (pattern_input_1[1].l0 == False) else (find(v0_1, of_seq(to_enumerable([(US0(0), 0), (US0(1), 1), (US0(2), 2), (US0(3), 3), (US0(4), 4)]), ObjectExpr238())) >= find(v15_1, of_seq(to_enumerable([(US0(0), 0), (US0(1), 1), (US0(2), 2), (US0(3), 3), (US0(4), 4)]), ObjectExpr239()))): + if False if (pattern_input_1[1].l0 == False) else (find(v0_1, of_seq(to_enumerable([(US0(0), 0), (US0(1), 1), (US0(2), 2), (US0(3), 3), (US0(4), 4)]), ObjectExpr229())) >= find(v15_1, of_seq(to_enumerable([(US0(0), 0), (US0(1), 1), (US0(2), 2), (US0(3), 3), (US0(4), 4)]), ObjectExpr230()))): v23: int64 = op_addition(v4_1.l0, int64(1)) v4_1.l0 = v23 v24: str = ("" + v1_1(None)) + "" @@ -923,10 +923,10 @@ def closure9(v0_1: US6, v1_1: str) -> Async[int64]: def closure8(unit_var: None, v0_1: US6) -> Callable[[str], Async[int64]]: - def _arrow240(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[int64]: + def _arrow231(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[int64]: return closure9(v0_1, v) - return _arrow240 + return _arrow231 def method15(v0_1: str, v1_1: int64) -> Async[int64]: @@ -985,10 +985,10 @@ def closure15(v0_1: str, v1_1: str) -> Async[bool]: def closure14(unit_var: None, v0_1: str) -> Callable[[str], Async[bool]]: - def _arrow241(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[bool]: + def _arrow232(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[bool]: return closure15(v0_1, v) - return _arrow241 + return _arrow232 def closure17(v0_1: str, v1_1: str) -> Async[None]: @@ -1003,10 +1003,10 @@ def closure17(v0_1: str, v1_1: str) -> Async[None]: def closure16(unit_var: None, v0_1: str) -> Callable[[str], Async[None]]: - def _arrow242(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[None]: + def _arrow233(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[None]: return closure17(v0_1, v) - return _arrow242 + return _arrow233 def closure19(v0_1: str, v1_1: str) -> Async[None]: @@ -1021,10 +1021,10 @@ def closure19(v0_1: str, v1_1: str) -> Async[None]: def closure18(unit_var: None, v0_1: str) -> Callable[[str], Async[None]]: - def _arrow243(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[None]: + def _arrow234(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[None]: return closure19(v0_1, v) - return _arrow243 + return _arrow234 def closure21(unit_var: None, unit_var_1: None) -> str: @@ -1111,10 +1111,10 @@ def closure24(v0_1: str, v1_1: str) -> Async[int64]: def closure23(unit_var: None, v0_1: str) -> Callable[[str], Async[int64]]: - def _arrow244(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[int64]: + def _arrow235(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Async[int64]: return closure24(v0_1, v) - return _arrow244 + return _arrow235 def closure28(unit_var: None, v0_1: int64) -> US9: @@ -1219,10 +1219,10 @@ def method21(v0_1: str, v1_1: Any) -> str: _v304: str | None = None x_4: str = to_string_1(v297, "c", {}) _v304 = x_4 - def _arrow245(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: + def _arrow236(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: raise Exception("base.run_target / _v304=None") - v312: str = ((("" + str(v302)) + "") + (_arrow245() if (_v304 is None) else _v304)) + "" + v312: str = ((("" + str(v302)) + "") + (_arrow236() if (_v304 is None) else _v304)) + "" v314: str = str(v0_1) x_6: str = parse(((((("" + v260) + "") + v312) + "") + v314[len(v260) + len(v312):len(v314)]) + "") _v2 = x_6 @@ -1283,10 +1283,10 @@ def closure35(unit_var: None, unit_var_1: None) -> str: x: str raise Exception(("file_system.get_temp_path / target: " + str(US5(3, US4(0)))) + "") _v767 = x - def _arrow246(__unit: None=None, unit_var: Any=unit_var, unit_var_1: Any=unit_var_1) -> str: + def _arrow237(__unit: None=None, unit_var: Any=unit_var, unit_var_1: Any=unit_var_1) -> str: raise Exception("base.run_target / _v767=None") - x_2: str = method28(method28(method28(_arrow246() if (_v767 is None) else _v767, method27()), method31()), str(method21(new_guid(), now()))) + x_2: str = method28(method28(method28(_arrow237() if (_v767 is None) else _v767, method27()), method31()), str(method21(new_guid(), now()))) _v642 = x_2 x_4: str if _v642 is None: @@ -1320,10 +1320,10 @@ def closure37(unit_var: None, v0_1: std_io_Error) -> std_string_String: def method35(__unit: None=None) -> Callable[[std_io_Error], std_string_String]: - def _arrow247(v: std_io_Error) -> std_string_String: + def _arrow238(v: std_io_Error) -> std_string_String: return closure37(None, v) - return _arrow247 + return _arrow238 def closure38(unit_var: None, unit_var_1: None) -> US12: @@ -1355,17 +1355,17 @@ def closure44(v0_1: str, unit_var: None) -> None: def method36(v0_1: str) -> Callable[[], None]: - def _arrow248(__unit: None=None, v0_1: Any=v0_1) -> None: + def _arrow239(__unit: None=None, v0_1: Any=v0_1) -> None: closure44(v0_1, None) - return _arrow248 + return _arrow239 def method37(v0_1: str) -> Callable[[], None]: - def _arrow249(__unit: None=None, v0_1: Any=v0_1) -> None: + def _arrow240(__unit: None=None, v0_1: Any=v0_1) -> None: closure44(v0_1, None) - return _arrow249 + return _arrow240 def closure45(unit_var: None, unit_var_1: None) -> str: @@ -1406,17 +1406,17 @@ def closure47(v0_1: str, unit_var: None) -> None: def method38(v0_1: str) -> Callable[[], None]: - def _arrow250(__unit: None=None, v0_1: Any=v0_1) -> None: + def _arrow241(__unit: None=None, v0_1: Any=v0_1) -> None: closure47(v0_1, None) - return _arrow250 + return _arrow241 def method39(v0_1: str) -> Callable[[], None]: - def _arrow251(__unit: None=None, v0_1: Any=v0_1) -> None: + def _arrow242(__unit: None=None, v0_1: Any=v0_1) -> None: closure47(v0_1, None) - return _arrow251 + return _arrow242 def method33(v0_1: str) -> IDisposable: @@ -1442,11 +1442,11 @@ def method33(v0_1: str) -> IDisposable: if v91 == False: _v93: Any | None = None _v93 = None - def _arrow252(__unit: None=None, v0_1: Any=v0_1) -> Any: + def _arrow243(__unit: None=None, v0_1: Any=v0_1) -> Any: raise Exception("base.run_target / _v93=None") v102: str = to_text(interpolate("%A%P()", [{ - "CreationTime": _arrow252() if (_v93 is None) else _v93, + "CreationTime": _arrow243() if (_v93 is None) else _v93, "Exists": v91 }])) def v104(__unit: None=None, v0_1: Any=v0_1) -> str: @@ -1482,10 +1482,10 @@ def closure36(unit_var: None, unit_var_1: None) -> tuple[str, IDisposable]: x: str raise Exception(("file_system.get_temp_path / target: " + str(US5(3, US4(0)))) + "") _v767 = x - def _arrow253(__unit: None=None, unit_var: Any=unit_var, unit_var_1: Any=unit_var_1) -> str: + def _arrow244(__unit: None=None, unit_var: Any=unit_var, unit_var_1: Any=unit_var_1) -> str: raise Exception("base.run_target / _v767=None") - x_2: str = method28(method28(method28(_arrow253() if (_v767 is None) else _v767, method27()), method31()), str(method21(new_guid(), now()))) + x_2: str = method28(method28(method28(_arrow244() if (_v767 is None) else _v767, method27()), method31()), str(method21(new_guid(), now()))) _v642 = x_2 x_4: str if _v642 is None: @@ -1515,13 +1515,13 @@ def closure48(unit_var: None, v0_1: str) -> tuple[str, IDisposable]: x_2: str raise Exception(("file_system.get_temp_path / target: " + str(US5(3, US4(0)))) + "") _v139 = x_2 - def _arrow254(__unit: None=None, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: + def _arrow245(__unit: None=None, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: raise Exception("base.run_target / _v139=None") - def _arrow255(__unit: None=None, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: + def _arrow246(__unit: None=None, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: raise Exception("base.run_target / _v1=None") - x_4: str = method28(method28(method28(_arrow254() if (_v139 is None) else _v139, method27()), method31()), str(_arrow255() if (_v1 is None) else _v1)) + x_4: str = method28(method28(method28(_arrow245() if (_v139 is None) else _v139, method27()), method31()), str(_arrow246() if (_v1 is None) else _v1)) _v14 = x_4 v221: str if _v14 is None: @@ -1568,22 +1568,22 @@ def closure55(unit_var: None, v0_1: str) -> str | None: def method41(__unit: None=None) -> Callable[[str], str | None]: - def _arrow256(v: str) -> str | None: + def _arrow247(v: str) -> str | None: return closure55(None, v) - return _arrow256 + return _arrow247 def method43(v0_1_mut: str, v1_1_mut: bool, v2_1_mut: str, v3_1_mut: str) -> str: while True: (v0_1, v1_1, v2_1, v3_1) = (v0_1_mut, v1_1_mut, v2_1_mut, v3_1_mut) - def _arrow257(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, v3_1: Any=v3_1) -> bool: + def _arrow248(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, v3_1: Any=v3_1) -> bool: return closure53(None, v) - def _arrow258(v_1: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, v3_1: Any=v3_1) -> bool: + def _arrow249(v_1: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, v3_1: Any=v3_1) -> bool: return closure54(None, v_1) - if (_arrow257 if v1_1 else _arrow258)(method28(v3_1, v0_1)): + if (_arrow248 if v1_1 else _arrow249)(method28(v3_1, v0_1)): return v3_1 else: @@ -1617,13 +1617,13 @@ def x_1(__unit: None=None, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1, v3_1: def method40(v0_1: str, v1_1: bool, v2_1: str) -> str: - def _arrow259(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1) -> bool: + def _arrow250(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1) -> bool: return closure53(None, v) - def _arrow260(v_1: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1) -> bool: + def _arrow251(v_1: str, v0_1: Any=v0_1, v1_1: Any=v1_1, v2_1: Any=v2_1) -> bool: return closure54(None, v_1) - if (_arrow259 if v1_1 else _arrow260)(method28(v2_1, v0_1)): + if (_arrow250 if v1_1 else _arrow251)(method28(v2_1, v0_1)): return v2_1 else: @@ -1656,17 +1656,17 @@ def closure52(v0_1: str, v1_1: bool, v2_1: str) -> str: def closure51(v0_1: str, v1_1: bool) -> Callable[[str], str]: - def _arrow261(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: + def _arrow252(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: return closure52(v0_1, v1_1, v) - return _arrow261 + return _arrow252 def closure50(unit_var: None, v0_1: str) -> Callable[[bool, str], str]: - def _arrow262(v: bool, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Callable[[str], str]: + def _arrow253(v: bool, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Callable[[str], str]: return closure51(v0_1, v) - return _arrow262 + return _arrow253 def method44(__unit: None=None) -> str: @@ -1692,11 +1692,11 @@ def closure56(unit_var: None, v0_1: str) -> str: else: v21_1 = _v2 - def _arrow263(__unit: None=None, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: + def _arrow254(__unit: None=None, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: _arg: str = v21_1[0] return _arg.lower() - return replace(((("" + _arrow263()) + "") + v21_1[1:len(v21_1)]) + "", "\\", "/") + return replace(((("" + _arrow254()) + "") + v21_1[1:len(v21_1)]) + "", "\\", "/") def closure57(unit_var: None, v0_1: str) -> str: @@ -1791,13 +1791,13 @@ def closure59(unit_var: None, v0_1: bool) -> None: State_trace_state(closure0(None, US0(0))) pattern_input: tuple[Mut0, Mut1, Mut2, int64 | None, Mut3] = value_4(State_trace_state()) - def _arrow264(v_1: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> None: + def _arrow255(v_1: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> None: closure60(None, v_1) - def _arrow265(v_2: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> None: + def _arrow256(v_2: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> None: closure1(None, v_2) - v10_1: Callable[[str], None] = _arrow264 if v0_1 else _arrow265 + v10_1: Callable[[str], None] = _arrow255 if v0_1 else _arrow256 pattern_input[4].l0 = v10_1 @@ -1806,17 +1806,17 @@ def closure62(v0_1: str, v1_1: str) -> str: def closure61(unit_var: None, v0_1: str) -> Callable[[str], str]: - def _arrow266(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: + def _arrow257(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> str: return closure62(v0_1, v) - return _arrow266 + return _arrow257 -def _arrow267(v: US0) -> tuple[Mut0, Mut1, Mut2, int64 | None, Mut3]: +def _arrow258(v: US0) -> tuple[Mut0, Mut1, Mut2, int64 | None, Mut3]: return closure0(None, v) -v0: Callable[[US0], tuple[Mut0, Mut1, Mut2, int64 | None, Mut3]] = _arrow267 +v0: Callable[[US0], tuple[Mut0, Mut1, Mut2, int64 | None, Mut3]] = _arrow258 v1: US0 = US0(0) @@ -1825,201 +1825,201 @@ def _arrow267(v: US0) -> tuple[Mut0, Mut1, Mut2, int64 | None, Mut3]: State_trace_state(v0(v1)) -def _arrow268(v: str) -> Async[int64]: +def _arrow259(v: str) -> Async[int64]: return closure2(None, v) -v2: Callable[[str], Async[int64]] = _arrow268 +v2: Callable[[str], Async[int64]] = _arrow259 def delete_directory_async(x: str) -> Async[int64]: return v2(x) -def _arrow269(v: US6) -> Callable[[str], Async[int64]]: +def _arrow260(v: US6) -> Callable[[str], Async[int64]]: return closure8(None, v) -v3: Callable[[US6, str], Async[int64]] = _arrow269 +v3: Callable[[US6, str], Async[int64]] = _arrow260 def wait_for_file_access(x: US6) -> Callable[[str], Async[int64]]: return v3(x) -def _arrow270(v: str) -> Async[int64]: +def _arrow261(v: str) -> Async[int64]: return closure12(None, v) -v4: Callable[[str], Async[int64]] = _arrow270 +v4: Callable[[str], Async[int64]] = _arrow261 def wait_for_file_access_read(x: str) -> Async[int64]: return v4(x) -def _arrow271(v: str) -> Async[str]: +def _arrow262(v: str) -> Async[str]: return closure13(None, v) -v5: Callable[[str], Async[str]] = _arrow271 +v5: Callable[[str], Async[str]] = _arrow262 def read_all_text_async(x: str) -> Async[str]: return v5(x) -def _arrow272(v: str) -> Callable[[str], Async[bool]]: +def _arrow263(v: str) -> Callable[[str], Async[bool]]: return closure14(None, v) -v6: Callable[[str, str], Async[bool]] = _arrow272 +v6: Callable[[str, str], Async[bool]] = _arrow263 def file_exists_content(x: str) -> Callable[[str], Async[bool]]: return v6(x) -def _arrow273(v: str) -> Callable[[str], Async[None]]: +def _arrow264(v: str) -> Callable[[str], Async[None]]: return closure16(None, v) -v7: Callable[[str, str], Async[None]] = _arrow273 +v7: Callable[[str, str], Async[None]] = _arrow264 def write_all_text_async(x: str) -> Callable[[str], Async[None]]: return v7(x) -def _arrow274(v: str) -> Callable[[str], Async[None]]: +def _arrow265(v: str) -> Callable[[str], Async[None]]: return closure18(None, v) -v8: Callable[[str, str], Async[None]] = _arrow274 +v8: Callable[[str, str], Async[None]] = _arrow265 def write_all_text_exists(x: str) -> Callable[[str], Async[None]]: return v8(x) -def _arrow275(v: str) -> Async[int64]: +def _arrow266(v: str) -> Async[int64]: return closure20(None, v) -v9: Callable[[str], Async[int64]] = _arrow275 +v9: Callable[[str], Async[int64]] = _arrow266 def delete_file_async(x: str) -> Async[int64]: return v9(x) -def _arrow276(v: str) -> Callable[[str], Async[int64]]: +def _arrow267(v: str) -> Callable[[str], Async[int64]]: return closure23(None, v) -v10: Callable[[str, str], Async[int64]] = _arrow276 +v10: Callable[[str, str], Async[int64]] = _arrow267 def move_file_async(x: str) -> Callable[[str], Async[int64]]: return v10(x) -def _arrow277(v: str) -> Async[str | None]: +def _arrow268(v: str) -> Async[str | None]: return closure27(None, v) -v11: Callable[[str], Async[str | None]] = _arrow277 +v11: Callable[[str], Async[str | None]] = _arrow268 def read_all_text_retry_async(x: str) -> Async[str | None]: return v11(x) -def _arrow278(__unit: None=None) -> str: +def _arrow269(__unit: None=None) -> str: return closure35(None, None) -v12: Callable[[], str] = _arrow278 +v12: Callable[[], str] = _arrow269 def create_temp_path(__unit: None=None) -> str: return v12(None) -def _arrow279(__unit: None=None) -> tuple[str, IDisposable]: +def _arrow270(__unit: None=None) -> tuple[str, IDisposable]: return closure36(None, None) -v13: Callable[[], tuple[str, IDisposable]] = _arrow279 +v13: Callable[[], tuple[str, IDisposable]] = _arrow270 def create_temp_dir(__unit: None=None) -> tuple[str, IDisposable]: return v13(None) -def _arrow280(v: str) -> tuple[str, IDisposable]: +def _arrow271(v: str) -> tuple[str, IDisposable]: return closure48(None, v) -v14: Callable[[str], tuple[str, IDisposable]] = _arrow280 +v14: Callable[[str], tuple[str, IDisposable]] = _arrow271 def create_temp_dir_0027(x: str) -> tuple[str, IDisposable]: return v14(x) -def _arrow281(__unit: None=None) -> str: +def _arrow272(__unit: None=None) -> str: return closure49(None, None) -v15: Callable[[], str] = _arrow281 +v15: Callable[[], str] = _arrow272 def get_source_directory(__unit: None=None) -> str: return v15(None) -def _arrow282(v: str) -> Callable[[bool, str], str]: +def _arrow274(v: str) -> Callable[[bool, str], str]: return closure50(None, v) -v16: Callable[[str, bool, str], str] = _arrow282 +v16: Callable[[str, bool, str], str] = _arrow274 def find_parent(x: str) -> Callable[[bool, str], str]: return v16(x) -def _arrow283(v: str) -> str: +def _arrow275(v: str) -> str: return closure56(None, v) -v17: Callable[[str], str] = _arrow283 +v17: Callable[[str], str] = _arrow275 def normalize_path(x: str) -> str: return v17(x) -def _arrow284(v: str) -> str: +def _arrow276(v: str) -> str: return closure57(None, v) -v18: Callable[[str], str] = _arrow284 +v18: Callable[[str], str] = _arrow276 def new_file_uri(x: str) -> str: return v18(x) -def _arrow285(__unit: None=None) -> str: +def _arrow277(__unit: None=None) -> str: return closure58(None, None) -v19: Callable[[], str] = _arrow285 +v19: Callable[[], str] = _arrow277 def get_workspace_root(__unit: None=None) -> str: return v19(None) -def _arrow286(v: bool) -> None: +def _arrow278(v: bool) -> None: closure59(None, v) -v20: Callable[[bool], None] = _arrow286 +v20: Callable[[bool], None] = _arrow278 def init_trace_file(x: bool) -> None: v20(x) -def _arrow287(v: str) -> Callable[[str], str]: +def _arrow279(v: str) -> Callable[[str], str]: return closure61(None, v) -v21: Callable[[str, str], str] = _arrow287 +v21: Callable[[str, str], str] = _arrow279 def op_less_divide_greater(x: str) -> Callable[[str], str]: return v21(x) diff --git a/lib/spiral/file_system.spi b/lib/spiral/file_system.spi index c4c6fb74..93b20ade 100644 --- a/lib/spiral/file_system.spi +++ b/lib/spiral/file_system.spi @@ -840,7 +840,7 @@ let rec trace_file text = inl file_name = $'$"{!assembly_name}_{!guid}.txt"' inl workspace_root = get_workspace_root () - inl trace_dir = workspace_root "target/polyglot/trace" + inl trace_dir = workspace_root "target/trace" trace_dir |> create_directory |> ignore inl path = trace_dir file_name text |> write_all_text_async path |> async.run_synchronously diff --git a/lib/spiral/iter.dib b/lib/spiral/iter.dib index f0b73438..74d4b7e9 100644 --- a/lib/spiral/iter.dib +++ b/lib/spiral/iter.dib @@ -14,7 +14,6 @@ open testing #!spiral -open iter_prototypes open rust_operators #!markdown @@ -85,7 +84,7 @@ inl enumerate forall dim {int; number} t. (ar : a dim t) : a dim (unativeint * t |> am'.to_vec |> into_iter |> iter_enumerate - |> iter_prototypes.iter_collect + |> iter_collect |> am'.vec_map' from_pair |> am'.from_vec diff --git a/lib/spiral/iter.spi b/lib/spiral/iter.spi index 37c774e4..8fff30cb 100644 --- a/lib/spiral/iter.spi +++ b/lib/spiral/iter.spi @@ -1,5 +1,4 @@ /// # iter -open iter_prototypes open rust_operators /// ## types @@ -35,6 +34,6 @@ inl enumerate forall dim {int; number} t. (ar : a dim t) : a dim (unativeint * t |> am'.to_vec |> into_iter |> iter_enumerate - |> iter_prototypes.iter_collect + |> iter_collect |> am'.vec_map' from_pair |> am'.from_vec diff --git a/lib/spiral/lib.ps1 b/lib/spiral/lib.ps1 index 19e6ac7a..f214a4c9 100644 --- a/lib/spiral/lib.ps1 +++ b/lib/spiral/lib.ps1 @@ -127,7 +127,7 @@ function GetTargetDir { [string] $ProjectName ) $root = "$PSScriptRoot/../.." - $result = (Resolve-Path "$root/target/polyglot/builder/$ProjectName").Path + $result = (Resolve-Path "$root/target/Builder/$ProjectName").Path Write-Host "targetDir: $result" $result } diff --git a/lib/spiral/package.spiproj b/lib/spiral/package.spiproj index 2c8afa68..808cc105 100644 --- a/lib/spiral/package.spiproj +++ b/lib/spiral/package.spiproj @@ -1,6 +1,7 @@ packages: |core- modules: + am'_prototypes- base- rust rust_operators @@ -13,12 +14,13 @@ modules: resultm console listm' - iter_prototypes + iter_prototypes- am' seq math mapm iter + sm'_prototypes- sm' sm'_operators guid diff --git a/lib/spiral/runtime.dib b/lib/spiral/runtime.dib index cdf76f69..d597ef47 100644 --- a/lib/spiral/runtime.dib +++ b/lib/spiral/runtime.dib @@ -1169,8 +1169,13 @@ let execute_with_options (options : execution_options) : i32 * string = output |> process_output_status |> process_exit_status_code - |> optionm'.unwrap - exit_code, None, Some channel_receiver' + |> optionm'.unbox + match exit_code with + | Some exit_code => exit_code, None, Some channel_receiver' + | None => + -1, + ("runtime.execute_with_options / exit_code=None" |> sm'.to_std_string |> Some), + Some channel_receiver' | Error error => trace Critical fun () => $'$"runtime.execute_with_options / output error"' @@ -1191,7 +1196,7 @@ let execute_with_options (options : execution_options) : i32 * string = |> threading.arc_mutex_lock |> resultm.unwrap' |> iter.iter - |> iter_prototypes.iter_collect'' + |> iter_collect'' |> am'.vec_map sm'.from_std_string |> am'.from_vec |> fun x => x : _ i32 _ diff --git a/lib/spiral/runtime.spi b/lib/spiral/runtime.spi index 6f3fbaf8..026e533a 100644 --- a/lib/spiral/runtime.spi +++ b/lib/spiral/runtime.spi @@ -684,8 +684,13 @@ let execute_with_options (options : execution_options) : i32 * string = output |> process_output_status |> process_exit_status_code - |> optionm'.unwrap - exit_code, None, Some channel_receiver' + |> optionm'.unbox + match exit_code with + | Some exit_code => exit_code, None, Some channel_receiver' + | None => + -1, + ("runtime.execute_with_options / exit_code=None" |> sm'.to_std_string |> Some), + Some channel_receiver' | Error error => trace Critical fun () => $'$"runtime.execute_with_options / output error"' @@ -706,7 +711,7 @@ let execute_with_options (options : execution_options) : i32 * string = |> threading.arc_mutex_lock |> resultm.unwrap' |> iter.iter - |> iter_prototypes.iter_collect'' + |> iter_collect'' |> am'.vec_map sm'.from_std_string |> am'.from_vec |> fun x => x : _ i32 _ diff --git a/lib/spiral/sm'_prototypes.spi b/lib/spiral/sm'_prototypes.spi new file mode 100644 index 00000000..3636fbbd --- /dev/null +++ b/lib/spiral/sm'_prototypes.spi @@ -0,0 +1,2 @@ +prototype of_string t : string -> option t +prototype to_string t : t -> string diff --git a/lib/spiral/sm.py b/lib/spiral/sm.py index 9c6eeed4..0139a03d 100644 --- a/lib/spiral/sm.py +++ b/lib/spiral/sm.py @@ -141,10 +141,10 @@ def _arrow16(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: def closure13(unit_var: None, v0_1: str) -> Callable[[str, str], str]: - def _arrow18(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Callable[[str], str]: + def _arrow17(v: str, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Callable[[str], str]: return closure14(v0_1, v) - return _arrow18 + return _arrow17 def closure18(v0_1: int, v1_1: int, v2_1: str) -> str: @@ -152,17 +152,17 @@ def closure18(v0_1: int, v1_1: int, v2_1: str) -> str: def closure17(v0_1: int, v1_1: int) -> Callable[[str], str]: - def _arrow23(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: + def _arrow22(v: str, v0_1: Any=v0_1, v1_1: Any=v1_1) -> str: return closure18(v0_1, v1_1, v) - return _arrow23 + return _arrow22 def closure16(unit_var: None, v0_1: int) -> Callable[[int, str], str]: - def _arrow24(v: int, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Callable[[str], str]: + def _arrow23(v: int, unit_var: Any=unit_var, v0_1: Any=v0_1) -> Callable[[str], str]: return closure17(v0_1, v) - return _arrow24 + return _arrow23 def closure20(v0_1: str, v1_1: str) -> Array[str]: @@ -412,41 +412,41 @@ def pad_left(x: int) -> Callable[[str, str], str]: return v2(x) -def _arrow41(v: int) -> Callable[[str, str], str]: +def _arrow40(v: int) -> Callable[[str, str], str]: return closure7(None, v) -v3: Callable[[int, str, str], str] = _arrow41 +v3: Callable[[int, str, str], str] = _arrow40 def pad_right(x: int) -> Callable[[str, str], str]: return v3(x) -def _arrow42(v: str) -> Callable[[str, str], str]: +def _arrow41(v: str) -> Callable[[str, str], str]: return closure10(None, v) -v4: Callable[[str, str, str], str] = _arrow42 +v4: Callable[[str, str, str], str] = _arrow41 def replace(x: str) -> Callable[[str, str], str]: return v4(x) -def _arrow43(v: str) -> Callable[[str, str], str]: +def _arrow42(v: str) -> Callable[[str, str], str]: return closure13(None, v) -v5: Callable[[str, str, str], str] = _arrow43 +v5: Callable[[str, str, str], str] = _arrow42 def replace_regex(x: str) -> Callable[[str, str], str]: return v5(x) -def _arrow44(v: int) -> Callable[[int, str], str]: +def _arrow43(v: int) -> Callable[[int, str], str]: return closure16(None, v) -v6: Callable[[int, int, str], str] = _arrow44 +v6: Callable[[int, int, str], str] = _arrow43 def slice(x: int) -> Callable[[int, str], str]: return v6(x) @@ -472,41 +472,41 @@ def split_string(x: Array[str]) -> Callable[[str], Array[str]]: return v8(x) -def _arrow48(v: str) -> Callable[[str], bool]: +def _arrow47(v: str) -> Callable[[str], bool]: return closure23(None, v) -v9: Callable[[str, str], bool] = _arrow48 +v9: Callable[[str, str], bool] = _arrow47 def starts_with(x: str) -> Callable[[str], bool]: return v9(x) -def _arrow49(v: int) -> Callable[[int, str], str]: +def _arrow48(v: int) -> Callable[[int, str], str]: return closure25(None, v) -v10: Callable[[int, int, str], str] = _arrow49 +v10: Callable[[int, int, str], str] = _arrow48 def substring(x: int) -> Callable[[int, str], str]: return v10(x) -def _arrow50(v: str) -> str: +def _arrow49(v: str) -> str: return closure28(None, v) -v11: Callable[[str], str] = _arrow50 +v11: Callable[[str], str] = _arrow49 def to_lower(x: str) -> str: return v11(x) -def _arrow51(v: str) -> str: +def _arrow50(v: str) -> str: return closure29(None, v) -v12: Callable[[str], str] = _arrow51 +v12: Callable[[str], str] = _arrow50 def to_upper(x: str) -> str: return v12(x)