├── .DS_Store ├── .github ├── FUNDING.yml └── workflows │ ├── fbp.yml │ ├── graph.yml │ └── runtime.yml ├── .gitignore ├── .rustfmt ├── .vscode └── settings.json ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── crates ├── fbp │ ├── Cargo.toml │ ├── LICENSE │ ├── README.md │ ├── lib.rs │ └── types.rs ├── zflow_graph │ ├── Cargo.toml │ ├── LICENSE │ ├── README.md │ ├── graph.rs │ ├── graph_test.rs │ ├── internal │ │ ├── event_manager.rs │ │ ├── mod.rs │ │ └── utils.rs │ ├── journal.rs │ ├── lib.rs │ ├── types.rs │ └── wasm_types.rs ├── zflow_js_runner │ ├── .DS_Store │ ├── .cargo │ │ └── config.toml │ ├── Cargo.toml │ ├── bin │ │ ├── .rustc_info.json │ │ ├── CACHEDIR.TAG │ │ └── libzflow_js_runner.dylib │ ├── build │ └── src │ │ ├── lib.rs │ │ ├── std_lib │ │ └── mod.rs │ │ └── utils.rs ├── zflow_plugin │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── zflow_runtime │ ├── .cargo │ │ └── config.toml │ ├── Cargo.toml │ ├── LICENSE │ ├── README.md │ ├── build.rs │ ├── component.rs │ ├── component_test.rs │ ├── deno │ │ ├── mod.rs │ │ ├── snapshot.rs │ │ └── transpiler.rs │ ├── errors.rs │ ├── extern_provider.rs │ ├── go │ │ ├── .DS_Store │ │ ├── go_std.rs │ │ ├── mod.rs │ │ ├── std.zip │ │ ├── std │ │ │ ├── bytes │ │ │ │ ├── .DS_Store │ │ │ │ ├── buffer.go │ │ │ │ ├── bytes.go │ │ │ │ └── reader.go │ │ │ ├── errors │ │ │ │ └── errors.gos │ │ │ ├── fmt │ │ │ │ ├── .DS_Store │ │ │ │ ├── doc.go │ │ │ │ ├── format.go │ │ │ │ ├── print.go │ │ │ │ └── scan.go │ │ │ ├── fmt2 │ │ │ │ └── fmt2.gos │ │ │ ├── internal │ │ │ │ ├── bytealg │ │ │ │ │ └── bytealg.gos │ │ │ │ └── fmtsort │ │ │ │ │ └── sort.go │ │ │ ├── io │ │ │ │ ├── .DS_Store │ │ │ │ ├── io.go │ │ │ │ ├── ioutil │ │ │ │ │ ├── .DS_Store │ │ │ │ │ ├── ioutil.go │ │ │ │ │ └── tempfile.go │ │ │ │ ├── multi.go │ │ │ │ └── pipe.go │ │ │ ├── math │ │ │ │ ├── .DS_Store │ │ │ │ ├── abs.go │ │ │ │ ├── acosh.go │ │ │ │ ├── asin.go │ │ │ │ ├── asinh.go │ │ │ │ ├── atan.go │ │ │ │ ├── atan2.go │ │ │ │ ├── atanh.go │ │ │ │ ├── bits.go │ │ │ │ ├── bits │ │ │ │ │ ├── .DS_Store │ │ │ │ │ ├── bits.go │ │ │ │ │ └── bits_tables.go │ │ │ │ ├── cbrt.go │ │ │ │ ├── cmplx │ │ │ │ │ ├── .DS_Store │ │ │ │ │ ├── abs.go │ │ │ │ │ ├── asin.go │ │ │ │ │ ├── conj.go │ │ │ │ │ ├── exp.go │ │ │ │ │ ├── isinf.go │ │ │ │ │ ├── isnan.go │ │ │ │ │ ├── log.go │ │ │ │ │ ├── phase.go │ │ │ │ │ ├── polar.go │ │ │ │ │ ├── pow.go │ │ │ │ │ ├── rect.go │ │ │ │ │ ├── sin.go │ │ │ │ │ ├── sqrt.go │ │ │ │ │ └── tan.go │ │ │ │ ├── const.go │ │ │ │ ├── copysign.go │ │ │ │ ├── dim.go │ │ │ │ ├── erf.go │ │ │ │ ├── erfinv.go │ │ │ │ ├── exp.go │ │ │ │ ├── expm1.go │ │ │ │ ├── floor.go │ │ │ │ ├── frexp.go │ │ │ │ ├── gamma.go │ │ │ │ ├── hypot.go │ │ │ │ ├── j0.go │ │ │ │ ├── j1.go │ │ │ │ ├── jn.go │ │ │ │ ├── ldexp.go │ │ │ │ ├── lgamma.go │ │ │ │ ├── log.go │ │ │ │ ├── log10.go │ │ │ │ ├── log1p.go │ │ │ │ ├── logb.go │ │ │ │ ├── mod.go │ │ │ │ ├── modf.go │ │ │ │ ├── nextafter.go │ │ │ │ ├── pow.go │ │ │ │ ├── pow10.go │ │ │ │ ├── rand │ │ │ │ │ ├── .DS_Store │ │ │ │ │ ├── exp.go │ │ │ │ │ ├── normal.go │ │ │ │ │ ├── rand.go │ │ │ │ │ ├── rng.go │ │ │ │ │ └── zipf.go │ │ │ │ ├── remainder.go │ │ │ │ ├── signbit.go │ │ │ │ ├── sin.go │ │ │ │ ├── sincos.go │ │ │ │ ├── sinh.go │ │ │ │ ├── sqrt.go │ │ │ │ ├── tan.go │ │ │ │ ├── tanh.go │ │ │ │ ├── trig_reduce.go │ │ │ │ └── unsafe.go │ │ │ ├── os │ │ │ │ └── file.gos │ │ │ ├── path │ │ │ │ ├── .DS_Store │ │ │ │ ├── filepath │ │ │ │ │ ├── .DS_Store │ │ │ │ │ ├── match.go │ │ │ │ │ └── path.go │ │ │ │ ├── match.go │ │ │ │ └── path.go │ │ │ ├── reflect │ │ │ │ ├── .DS_Store │ │ │ │ ├── deepequal.go │ │ │ │ ├── makefunc.go │ │ │ │ ├── swapper.go │ │ │ │ ├── type.go │ │ │ │ └── value.go │ │ │ ├── runtime │ │ │ │ └── runtime.gos │ │ │ ├── sort │ │ │ │ ├── search.go │ │ │ │ ├── slice.go │ │ │ │ ├── sort.go │ │ │ │ └── zfuncversion.go │ │ │ ├── strconv │ │ │ │ ├── .DS_Store │ │ │ │ ├── atob.go │ │ │ │ ├── atof.go │ │ │ │ ├── atoi.go │ │ │ │ ├── decimal.go │ │ │ │ ├── doc.go │ │ │ │ ├── extfloat.go │ │ │ │ ├── ftoa.go │ │ │ │ ├── isprint.go │ │ │ │ ├── itoa.go │ │ │ │ └── quote.go │ │ │ ├── strings │ │ │ │ ├── .DS_Store │ │ │ │ ├── builder.go │ │ │ │ ├── compare.go │ │ │ │ ├── reader.go │ │ │ │ ├── replace.go │ │ │ │ ├── search.go │ │ │ │ └── strings.go │ │ │ ├── sync │ │ │ │ ├── atomic │ │ │ │ │ └── value.gos │ │ │ │ ├── map.gos │ │ │ │ ├── once.gos │ │ │ │ ├── pool.gos │ │ │ │ └── sync.gos │ │ │ ├── syscall │ │ │ │ └── syscall.gos │ │ │ ├── time │ │ │ │ ├── .DS_Store │ │ │ │ ├── format.go │ │ │ │ ├── sleep.go │ │ │ │ ├── tick.go │ │ │ │ ├── time.go │ │ │ │ └── zoneinfo.go │ │ │ ├── unicode │ │ │ │ ├── .DS_Store │ │ │ │ ├── casetables.go │ │ │ │ ├── digit.go │ │ │ │ ├── graphic.go │ │ │ │ ├── letter.go │ │ │ │ ├── tables.go │ │ │ │ ├── utf16 │ │ │ │ │ ├── .DS_Store │ │ │ │ │ └── utf16.go │ │ │ │ └── utf8 │ │ │ │ │ ├── .DS_Store │ │ │ │ │ └── utf8.go │ │ │ └── zflow │ │ │ │ └── process.gos │ │ └── utils.rs │ ├── ip.rs │ ├── js │ │ └── mod.rs │ ├── lib.rs │ ├── lua │ │ └── mod.rs │ ├── network.rs │ ├── network_manager.rs │ ├── network_test.rs │ ├── port.rs │ ├── port_test.rs │ ├── process.rs │ ├── provider.rs │ ├── registry.rs │ ├── runner.rs │ ├── sockets.rs │ ├── wasm │ │ └── mod.rs │ ├── websocket │ │ └── mod.rs │ └── wren │ │ └── mod.rs └── zflow_server │ ├── Cargo.toml │ └── src │ └── main.rs ├── rust-toolchain.toml ├── test_components ├── add_go │ ├── add.gos │ └── zflow.json ├── add_js │ ├── add.js │ ├── runner │ │ └── libzflow_runner_js.dylib │ └── zflow.json ├── add_lua │ ├── add.lua │ └── zflow.json ├── add_wasm │ ├── Cargo.toml │ ├── add_wasm.wasm │ ├── lib.rs │ └── zflow.json └── add_wren │ ├── main.wren │ └── zflow.json └── test_providers └── maths_provider ├── .cargo └── config.toml ├── Cargo.toml ├── bin ├── .rustc_info.json ├── CACHEDIR.TAG ├── maths_provider.wasm └── wasm32-wasi │ └── CACHEDIR.TAG ├── build ├── lib.rs ├── math.js ├── math.ts └── zflow.provider.json /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/.DS_Store -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: darmie 4 | patreon: dami476 5 | # open_collective: # Replace with a single Open Collective username 6 | # ko_fi: # Replace with a single Ko-fi username 7 | # tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | # community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | # liberapay: # Replace with a single Liberapay username 10 | # issuehunt: # Replace with a single IssueHunt username 11 | # otechie: # Replace with a single Otechie username 12 | # lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | # custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.github/workflows/fbp.yml: -------------------------------------------------------------------------------- 1 | name: FBP 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Run .fbp specification tests 20 | run: cd crates/fbp && cargo test --verbose 21 | -------------------------------------------------------------------------------- /.github/workflows/graph.yml: -------------------------------------------------------------------------------- 1 | name: zflow_graph 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Run graph tests 20 | run: cd crates/zflow_graph && cargo test --verbose 21 | - name: Install wasm-pack 22 | run: cargo install wasm-pack 23 | - name: Build the Zflow Graph Javascript Library 24 | run: cd crates/zflow_graph && wasm-pack build --release --target web --features build_wasm 25 | -------------------------------------------------------------------------------- /.github/workflows/runtime.yml: -------------------------------------------------------------------------------- 1 | name: zflow_runtime 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Setup protoc 19 | uses: arduino/setup-protoc@v3 20 | - name: Setup actions 21 | uses: actions/checkout@v3 22 | - name: Build quickjs runner 23 | run: cd crates/zflow_js_runner && cargo build --release && cp ./bin/release/libzflow_js_runner.so ./bin/libzflow_js_runner.so 24 | - name: Run runtime tests 25 | run: ZFLOW_QUICKJS_RUNNER_LIB=../zflow_js_runner/bin/libzflow_js_runner.so cargo test --package zflow_runtime --verbose -- --skip network_test 26 | - name: Run network tests 27 | run: ZFLOW_QUICKJS_RUNNER_LIB=../zflow_js_runner/bin/libzflow_js_runner.so cargo test --package zflow_runtime --verbose --lib -- 'network_test::tests::test_network' 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/target 2 | **/bin/**/release 3 | **/bin/**/debug 4 | -------------------------------------------------------------------------------- /.rustfmt: -------------------------------------------------------------------------------- 1 | max_width = 80 2 | tab_spaces = 2 3 | edition = "2021" -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.linkedProjects": [ 3 | "./crates/zflow_graph/Cargo.toml", 4 | "./crates/fbp/Cargo.toml", 5 | "./Cargo.toml", 6 | "./crates/zflow_runtime/Cargo.toml", 7 | ] 8 | } -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = [ 4 | "crates/*", 5 | "test_components/add_wasm", 6 | "test_providers/maths_provider" 7 | ] 8 | [workspace.dependencies] 9 | extism-pdk = "1.0.0" 10 | serde_json = "1.0" 11 | serde = { version = "1.0", features = ["derive"] } 12 | anyhow = "1.0.71" 13 | log = "0.4" 14 | foreach = "0.3.0" 15 | nuid = "0.3.2" 16 | beady = "0.6.0" 17 | assert-json-diff = "2.0.2" 18 | cast_trait_object = "0.1.3" 19 | async-trait = "0.1.60" 20 | regex-lexer = "0.2.0" 21 | regex = "1.8.1" 22 | fp_rust = {version = "0.3.5", features = ["for_futures"]} 23 | rayon = "1.7.0" 24 | futures = {version = "0.3.25", features = ["thread-pool"] } 25 | futures-lite = "1.12.0" 26 | simple_logger = "4.3.3" 27 | base64 = "0.21.7" 28 | is-url = "1.0.4" 29 | tokio = {version="1", features=["full"]} 30 | chrono = {version="0.4.34", default-features = false, features = ["clock"]} 31 | tempdir = "0.3.7" 32 | array_tool = "1.0.3" 33 | dyn-clone = "1.0.11" 34 | bincode = "1.3.3" 35 | once_cell = "1.18.0" 36 | bytes = "1.4.0" 37 | reqwest = { version = "0.11.20", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli", "socks", "json"] } 38 | 39 | # Enable a small amount of optimization in debug mode 40 | [profile.dev] 41 | opt-level = 1 42 | 43 | # Enable high optimizations for dependencies but not for our code: 44 | [profile.dev.package."*"] 45 | opt-level = 3 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 'Damilare Darmie Akinlaja 4 | Copyright (c) 2013-2020 Flowhub UG 5 | Copyright (c) 2011-2012 Henri Bergius, Nemein 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /crates/fbp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fbp" 3 | version = "0.1.0" 4 | edition = "2021" 5 | repository = "https://github.com/zflow-dev/zflow" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | regex-lexer= {workspace = true} 11 | regex= {workspace = true} 12 | serde_json= {workspace = true} 13 | serde= {workspace = true} 14 | 15 | [lib] 16 | path = "lib.rs" 17 | -------------------------------------------------------------------------------- /crates/fbp/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 'Damilare Darmie Akinlaja 4 | Copyright (c) 2013-2020 Flowhub UG 5 | Copyright (c) 2011-2012 Henri Bergius, Nemein 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /crates/fbp/README.md: -------------------------------------------------------------------------------- 1 | ![FBP](https://github.com/darmie/zflow/actions/workflows/fbp.yml/badge.svg) 2 | 3 | # The FBP Flow Definition Language Specification 4 | The fbp library provides a parser for a domain-specific language for flow-based-programming (FBP), used for defining graphs for FBP programming environments like [ZFlow](https://github.com/darmie/zflow) 5 | 6 | 7 | ### Usage 8 | You can use the FBP parser in your Haxe code with the following: 9 | ```rs 10 | let source = r"'hello, world!' -> IN Display(Output)"; 11 | let mut graph = FBP::parse(fbpData, "my fbp graph", false); // this will produce a ZFlow graph 12 | ``` 13 | 14 | ## Language for Flow-Based Programming 15 | 16 | FBP is a Domain-Specific Language (DSL) for easy graph definition. The syntax is the following: 17 | 18 | * `'somedata' -> PORT Process(Component)` sends initial data _somedata_ to port _PORT_ of process _Process_ that runs component _Component_ 19 | * `A(Component1) X -> Y B(Component2)` sets up a connection between port _X_ of process _A_ that runs component _Component1_ and port _Y_ of process _B_ that runs component _Component2_ 20 | 21 | You can connect multiple components and ports together on one line, and separate connection definitions with a newline or a comma (`,`). 22 | 23 | Components only have to be specified the first time you mention a new process. Afterwards, simply use the process name. 24 | 25 | Example: 26 | 27 | ```js 28 | 'somefile.txt' -> SOURCE Read(ReadFile) OUT -> IN Split(SplitStr) 29 | Split OUT -> IN Count(Counter) COUNT -> IN Display(Output) 30 | Read ERROR -> IN Display 31 | ``` 32 | 33 | The syntax also supports blank lines and comments. Comments start with the `#` character. 34 | 35 | Example with the same graph than above : 36 | 37 | ```js 38 | # Read the content of "somefile.txt" and split it by line 39 | 'somefile.txt' -> SOURCE Read(ReadFile) OUT -> IN Split(SplitStr) 40 | 41 | # Count the lines and display the result 42 | Split() OUT -> IN Count(Counter) COUNT -> IN Display(Output) 43 | 44 | # The read errors are also displayed 45 | Read() ERROR -> IN Display() 46 | ``` 47 | 48 | ### Exporting ports 49 | 50 | When FBP-defined graphs are used as subgraphs in other flows, it is often desirable to give more user-friendly names to their available ports. In the FBP language this is done by `INPORT` and `OUTPORT` statements. 51 | 52 | Example: 53 | 54 | ```js 55 | INPORT=Read.IN:FILENAME 56 | Read(ReadFile) OUT -> IN Display(Output) 57 | ``` 58 | 59 | This line would export the *IN* port of the *Read* node as *FILENAME*. 60 | 61 | ### Node metadata 62 | 63 | It is possible to append metadata to Nodes when declaring them by adding the metadata string to the Component part after a colon (`:`). 64 | 65 | Example: 66 | 67 | ```js 68 | 'somefile.txt' -> SOURCE Read(ReadFile:main) 69 | Read() OUT -> IN Split(SplitStr:main) 70 | Split() OUT -> IN Count(Counter:main) 71 | Count() COUNT -> IN Display(Output:main) 72 | Read() ERROR -> IN Display() 73 | ``` 74 | 75 | In this case the route leading from *Read* to *Display* through *Split* and *Count* would be identified with the string *main*. You can also provide arbitrary metadata keys with the `=` syntax: 76 | 77 | ```js 78 | Read() OUT -> IN Split(SplitStr:foo=bar,baz=123) 79 | ``` 80 | 81 | In this case the *Split* node would contain the metadata keys `foo` and `baz` with values `bar` and `123`. 82 | 83 | ### Annotations 84 | 85 | FBP graphs also support annotations for specifying things like graph name, description, icon, or the FBP runtime to be used for executing the graph. 86 | 87 | The syntax for annotations is `# @name value`, for example: 88 | 89 | ```js 90 | # @runtime noflo-nodejs 91 | # @name ReadSomefile 92 | 'somefile' -> SOURCE Read(ReadFile) 93 | ``` -------------------------------------------------------------------------------- /crates/fbp/types.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use serde::{Deserialize, Serialize}; 4 | use serde_json::{Value, Map}; 5 | 6 | pub type Spanned = Result<(Loc, Token, Loc), Error>; 7 | 8 | #[derive(Clone, Debug)] 9 | pub struct NodeInfo { 10 | pub name: String, 11 | pub port: Option, 12 | } 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct PortInfo { 16 | pub name: String, 17 | pub index: Option, 18 | } 19 | 20 | #[derive(Clone, Debug)] 21 | pub enum FBPToken { 22 | Inport(NodeInfo, PortInfo), 23 | Outport(NodeInfo, PortInfo), 24 | Port(PortInfo), 25 | LongSpace, 26 | ShortSpace, 27 | IIPChar(String), 28 | Ap, 29 | AnyChar(String), 30 | Node(NodeInfo, Option>), 31 | At, 32 | Annotation(String, String), 33 | Doc(String), 34 | Index(usize), 35 | BkOpen, 36 | BkClose, 37 | BrOpen, 38 | BrClose, 39 | Col, 40 | Comma, 41 | Dot, 42 | Hash, 43 | Eof, 44 | NewLine, 45 | Arrow, 46 | Component(String, String), 47 | } 48 | 49 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] 50 | pub enum Kind { 51 | InPortOutPort, 52 | Outport, 53 | Inport, 54 | LongSpace, 55 | ShortSpace, 56 | StartIIP, 57 | CloseIIP, 58 | IIPChar, 59 | Ap, 60 | AnyChar, 61 | Node, 62 | NodeName, 63 | At, 64 | AnnotationKey, 65 | AnnotationValue, 66 | Doc, 67 | Index, 68 | BkOpen, 69 | BkClose, 70 | BrOpen, 71 | BrClose, 72 | Col, 73 | Comma, 74 | Dot, 75 | Hash, 76 | Eof, 77 | NewLine, 78 | Arrow, 79 | Component, 80 | Name, 81 | CompMeta, 82 | CompName, 83 | Port, 84 | LeftRightPort, 85 | PortIndex, 86 | } 87 | 88 | #[derive(Clone, Serialize, Deserialize, Debug, Default)] 89 | pub struct GraphLeafJson { 90 | pub port: String, 91 | pub process: String, 92 | pub index: Option, 93 | } 94 | 95 | #[derive(Clone, Serialize, Deserialize, Debug, Default)] 96 | pub struct GraphEdgeJson { 97 | pub src: Option, 98 | pub tgt: Option, 99 | pub data: Option, 100 | pub metadata: Option>, 101 | } 102 | 103 | #[derive(Clone, Serialize, Deserialize, Debug, Default)] 104 | pub struct GraphNodeJson { 105 | pub component: String, 106 | pub metadata: Option>, 107 | } 108 | 109 | #[derive(Clone, Serialize, Deserialize, Debug, Default)] 110 | pub struct GraphExportedPort { 111 | pub process: String, 112 | pub port: String, 113 | pub metadata: Option>, 114 | } 115 | 116 | #[derive(Clone, Serialize, Deserialize, Debug, Default)] 117 | pub struct GraphGroup { 118 | pub name: String, 119 | pub nodes: Vec, 120 | pub metadata: Option>, 121 | } 122 | 123 | #[derive(Serialize, Deserialize, Clone, Debug, Default)] 124 | #[serde(rename_all = "camelCase")] 125 | pub struct GraphJson { 126 | pub case_sensitive: bool, 127 | pub properties: Map, 128 | pub inports: HashMap, 129 | pub outports: HashMap, 130 | pub groups: Vec, 131 | pub processes: HashMap, 132 | pub connections: Vec, 133 | } -------------------------------------------------------------------------------- /crates/zflow_graph/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zflow_graph" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Damilare Akinlaja "] 6 | license = "MIT" 7 | description = "Flow-based Programming Graph Specification" 8 | keywords = ["fbp", "DAG", "flowbased", "low-code", "no-code", "visual-programming"] 9 | repository = "https://github.com/zflow-dev/zflow" 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | [dependencies] 14 | log= {workspace = true} 15 | foreach= {workspace = true} 16 | # nuid= {workspace = true} 17 | serde_json= {workspace = true} 18 | serde= {workspace = true} 19 | beady= {workspace = true} 20 | assert-json-diff= {workspace = true} 21 | cast_trait_object= {workspace = true} 22 | async-trait= {workspace = true} 23 | fbp = {path = '../fbp'} 24 | anyhow={workspace=true} 25 | tsify = {version="0.4.5",features = ["js"], optional = true} 26 | wasm-bindgen = { version = "0.2.86", optional = true} 27 | gloo-utils = { version = "0.1", features = ["serde"], optional = true } 28 | gloo-events = { version = "0.2.0", optional = true } 29 | web-sys = {version="0.3.69", optional = true} 30 | 31 | 32 | [lib] 33 | crate-type = ["cdylib", "rlib"] 34 | path = "lib.rs" 35 | doctest = false 36 | 37 | [features] 38 | build_wasm = [ 39 | "dep:tsify","dep:wasm-bindgen", "dep:gloo-utils", "dep:web-sys", "dep:gloo-events" 40 | ] 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /crates/zflow_graph/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 'Damilare Darmie Akinlaja 4 | Copyright (c) 2013-2020 Flowhub UG 5 | Copyright (c) 2011-2012 Henri Bergius, Nemein 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /crates/zflow_graph/README.md: -------------------------------------------------------------------------------- 1 | ![Graph](https://github.com/darmie/zflow/actions/workflows/graph.yml/badge.svg) 2 | 3 | # The FBP Graph Specification 4 | An implementation of the [Flow-Based Programming](https://flow-based.org/) graph specification. 5 | ## Graph Usage (Rust) 6 | ```rust 7 | let mut g = Graph::new("Foo bar", true); 8 | // listen to the graph add_node event 9 | g.connect("add_node", |this, data|{ 10 | if let Ok(node) = GraphNode::deserialize(data){ 11 | assert_eq!(node.id, "Foo"); 12 | assert_eq!(node.component, "Bar"); 13 | } 14 | }, true); 15 | // add a node 16 | g.add_node("Foo", "Bar", None); 17 | 18 | // listen to the add_edge event 19 | g.connect("add_edge", |this, data|{ 20 | if let Ok(edge) = GraphEdge::deserialize(data){ 21 | assert_eq!(edge.from.node_id, "Foo"); 22 | assert_eq!(edge.to.port, "In"); 23 | } 24 | }); 25 | 26 | // add node with ID `Foo` and Component named `foo` 27 | g.add_node("Foo", "foo", None); 28 | // add node with ID `Bar` and Component named `bar` 29 | g.add_node("Bar", "bar", None); 30 | // add a connection between `Foo` and `Bar` by their output port and input ports respectively. 31 | g.add_edge("Foo", "Out", "Bar", "In", None); 32 | ``` 33 | ## Graph Usage (Javascript/Typescript) 34 | ```ts 35 | const g = new Graph("Foo bar", true); 36 | // listen to the graph add_node event 37 | g.connect("add_node", (ctx, node)=>{ 38 | console.log(node.id); // Foo 39 | console.log(node.component); // Bar 40 | }, true); 41 | // add a node 42 | g.addNode("Foo", "Bar"); 43 | 44 | // listen to the add_edge event 45 | g.connect("add_edge", (ctx, edge)=>{ 46 | console.log(edge.from.node_id); // Foo 47 | console.log(edge.to.port); // "In" 48 | }); 49 | 50 | // add node with ID `Foo` and Component named `foo` 51 | g.addNode("Foo", "foo"); 52 | // add node with ID `Bar` and Component named `bar` 53 | g.addNode("Bar", "bar"); 54 | // add a connection between `Foo` and `Bar` by their output port and input ports respectively. 55 | g.addEdge("Foo", "Out", "Bar", "In"); 56 | ``` 57 | See [graph_test.rs](https://github.com/darmie/zflow/blob/main/zflow_graph/src/graph_test.rs) for more usage examples 58 | 59 | ## Journal Usage (Rust) 60 | ```rs 61 | let mut graph = Graph::new("", false); 62 | // start recording events in the graph to the memory journal 63 | graph.start_journal(None); 64 | graph.add_node("Foo", "Bar", None); 65 | graph.add_node("Baz", "Foo", None); 66 | graph.add_edge("Foo", "out", "Baz", "in", None); 67 | graph.add_initial(json!(42), "Foo", "in", None); 68 | graph.remove_node("Foo"); 69 | 70 | // move to initial state in journal history 71 | graph.move_to_revision(0); 72 | // move to second revision in journal history 73 | graph.move_to_revision(2); 74 | // move to fifth revision in journal history 75 | graph.move_to_revision(5); 76 | ``` 77 | See [journal.rs](https://github.com/darmie/zflow/blob/main/zflow_graph/src/journal.rs#L1013) for more usage examples -------------------------------------------------------------------------------- /crates/zflow_graph/internal/event_manager.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Debug; 2 | use std::sync::{Arc, Mutex}; 3 | 4 | use serde_json::Value; 5 | 6 | 7 | pub(crate) type TypeFn = Arc () + Send + Sync + 'static)>>; 8 | #[derive(Clone)] 9 | pub struct EventActor { 10 | pub once: bool, 11 | pub callback: TypeFn, 12 | } 13 | 14 | impl Debug for EventActor { 15 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 16 | f.debug_struct("EventActor") 17 | .field("once", &self.once) 18 | .field("callback", &"[CallbackFn]") 19 | .finish() 20 | } 21 | } 22 | 23 | pub trait EventManager { 24 | /// Send event 25 | fn emit(&mut self, name: &'static str, data: Value); 26 | 27 | /// Remove listeners from event 28 | fn disconnect(&mut self, name: &'static str); 29 | /// Check if we have events 30 | fn has_event(&self, name: &'static str) -> bool; 31 | } 32 | 33 | pub trait EventListener { 34 | /// Attach listener to an event 35 | fn connect( 36 | &mut self, 37 | name: &'static str, 38 | rec: impl FnMut(&mut Self, Value) -> () + Send + Sync + 'static, 39 | once: bool, 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /crates/zflow_graph/internal/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod event_manager; 2 | pub mod utils; 3 | -------------------------------------------------------------------------------- /crates/zflow_graph/internal/utils.rs: -------------------------------------------------------------------------------- 1 | // pub fn guid() -> String { 2 | // nuid::next() 3 | // } 4 | -------------------------------------------------------------------------------- /crates/zflow_graph/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod graph; 2 | 3 | pub mod graph_test; 4 | pub mod journal; 5 | pub mod types; 6 | pub mod internal; 7 | 8 | #[cfg(feature = "build_wasm")] 9 | pub mod wasm_types; 10 | 11 | 12 | pub use graph::Graph; 13 | #[cfg(not(feature="build_wasm"))] 14 | pub use journal::Journal; 15 | -------------------------------------------------------------------------------- /crates/zflow_js_runner/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_js_runner/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_js_runner/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target-dir = "bin" 3 | -------------------------------------------------------------------------------- /crates/zflow_js_runner/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zflow_js_runner" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Damilare Akinlaja "] 6 | license = "MIT" 7 | description = "ZFlow Runner for Javascript node components" 8 | keywords = ["fbp", "flowbased", "low-code", "no-code", "visual-programming", "runner", "javascript"] 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | bench = false 13 | path = "src/lib.rs" 14 | 15 | [dependencies] 16 | serde_json={workspace = true} 17 | serde={workspace = true} 18 | rquickjs = {version = "0.1.7", features = ["full"]} 19 | zflow_runtime = {version="0.1.0", path = "../zflow_runtime", default-features = false} 20 | anyhow={workspace = true} 21 | libloading = {version = "0.8.1"} 22 | 23 | -------------------------------------------------------------------------------- /crates/zflow_js_runner/bin/.rustc_info.json: -------------------------------------------------------------------------------- 1 | {"rustc_fingerprint":2635327901679194958,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.77.0-nightly (88189a71e 2024-01-19)\nbinary: rustc\ncommit-hash: 88189a71e4e4376eea82ac61db6a539612eb200a\ncommit-date: 2024-01-19\nhost: aarch64-apple-darwin\nrelease: 1.77.0-nightly\nLLVM version: 17.0.6\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/amaterasu/.rustup/toolchains/nightly-aarch64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"v8.1a\"\ntarget_feature=\"v8.2a\"\ntarget_feature=\"v8.3a\"\ntarget_feature=\"v8.4a\"\ntarget_feature=\"vh\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"128\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}} -------------------------------------------------------------------------------- /crates/zflow_js_runner/bin/CACHEDIR.TAG: -------------------------------------------------------------------------------- 1 | Signature: 8a477f597d28d172789f06886806bc55 2 | # This file is a cache directory tag created by cargo. 3 | # For information about cache directory tags see https://bford.info/cachedir/ 4 | -------------------------------------------------------------------------------- /crates/zflow_js_runner/bin/libzflow_js_runner.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_js_runner/bin/libzflow_js_runner.dylib -------------------------------------------------------------------------------- /crates/zflow_js_runner/build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cargo build --release 4 | 5 | cp ./bin/release/libzflow_js_runner.dylib ./bin/libzflow_js_runner.dylib -------------------------------------------------------------------------------- /crates/zflow_js_runner/src/std_lib/mod.rs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_js_runner/src/std_lib/mod.rs -------------------------------------------------------------------------------- /crates/zflow_js_runner/src/utils.rs: -------------------------------------------------------------------------------- 1 | use rquickjs::Ctx; 2 | use serde_json::{json, Map}; 3 | use zflow_runtime::process::ProcessError; 4 | 5 | 6 | 7 | 8 | pub fn js_value_to_json_value(value: rquickjs::Value) -> Result { 9 | if let Some(v) = value.as_string() { 10 | return Ok(json!(v 11 | .to_string() 12 | .expect("expected to read javascript string value"))); 13 | } 14 | 15 | if let Some(v) = value.as_int() { 16 | return Ok(json!(v)); 17 | } 18 | 19 | if let Some(v) = value.as_float() { 20 | return Ok(json!(v)); 21 | } 22 | if let Some(v) = value.as_number() { 23 | return Ok(json!(v)); 24 | } 25 | 26 | if let Some(v) = value.as_array() { 27 | let mut arr = Vec::new(); 28 | for val in v.clone().into_iter() { 29 | if let Ok(val) = val { 30 | arr.push(js_value_to_json_value(val)?); 31 | } 32 | } 33 | return Ok(json!(arr)); 34 | } 35 | 36 | if let Some(v) = value.as_bool() { 37 | return Ok(json!(v)); 38 | } 39 | 40 | if let Some(v) = value.as_object() { 41 | let mut arr = Map::new(); 42 | for val in v.clone().into_iter() { 43 | if let Ok((k, v)) = val { 44 | arr.insert( 45 | k.to_string() 46 | .expect("expected to read key from javascript object"), 47 | js_value_to_json_value(v)?, 48 | ); 49 | } 50 | } 51 | return Ok(json!(arr)); 52 | } 53 | 54 | Ok(json!(null)) 55 | } 56 | 57 | pub fn json_value_to_js_value<'js>( 58 | ctx: Ctx<'js>, 59 | value: serde_json::Value, 60 | ) -> Result, ProcessError> { 61 | if let Some(v) = value.as_str() { 62 | return Ok(rquickjs::String::from_str(ctx, v) 63 | .expect("expected to convert value to js value") 64 | .into()); 65 | } 66 | 67 | if let Some(v) = value.as_i64() { 68 | let value = rquickjs::Value::new_number(ctx, v as f64); 69 | return Ok(value); 70 | } 71 | 72 | if let Some(v) = value.as_f64() { 73 | let value = rquickjs::Value::new_number(ctx, v); 74 | return Ok(value); 75 | } 76 | if let Some(v) = value.as_u64() { 77 | let value = rquickjs::Value::new_number(ctx, v as f64); 78 | return Ok(value); 79 | } 80 | 81 | if let Some(v) = value.as_array() { 82 | if let Ok(arr) = rquickjs::Array::new(ctx).as_mut() { 83 | for (i, val) in v.clone().into_iter().enumerate() { 84 | arr.set(i, json_value_to_js_value(ctx, val)?).expect(""); 85 | } 86 | return Ok(arr.as_value().clone()); 87 | } 88 | } 89 | 90 | if let Some(v) = value.as_bool() { 91 | if v { 92 | return Ok(rquickjs::Value::new_bool(ctx, v)); 93 | } 94 | } 95 | 96 | if let Some(v) = value.as_object() { 97 | if let Ok(obj) = rquickjs::Object::new(ctx).as_mut() { 98 | for (k, val) in v.clone().into_iter() { 99 | obj.set(k, json_value_to_js_value(ctx, val)?).expect(""); 100 | } 101 | return Ok(obj.as_value().clone()); 102 | } 103 | } 104 | 105 | Ok(rquickjs::Value::new_undefined(ctx)) 106 | } -------------------------------------------------------------------------------- /crates/zflow_plugin/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zflow_plugin" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Damilare Akinlaja "] 6 | license = "MIT" 7 | description = "ZFlow FBP Graph Runtime" 8 | keywords = ["fbp", "flowbased", "low-code", "no-code", "visual-programming"] 9 | 10 | [dependencies] 11 | extism-pdk = {workspace = true} 12 | serde_json= {workspace = true} 13 | serde= {workspace = true} 14 | 15 | # [lib] 16 | # path = "src/lib.rs" -------------------------------------------------------------------------------- /crates/zflow_runtime/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [env] 2 | ZFLOW_WASM_RUNNER_LIB = {value="../../zflow_wasm_runner/bin/libzflow_wasm_runner.dylib", relative=true} 3 | ZFLOW_QUICKJS_RUNNER_LIB = {value="../../zflow_js_runner/bin/libzflow_js_runner.dylib", relative=true} 4 | 5 | -------------------------------------------------------------------------------- /crates/zflow_runtime/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 'Damilare Darmie Akinlaja 4 | Copyright (c) 2013-2020 Flowhub UG 5 | Copyright (c) 2011-2012 Henri Bergius, Nemein 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /crates/zflow_runtime/README.md: -------------------------------------------------------------------------------- 1 | ![Runtime](https://github.com/darmie/zflow/actions/workflows/runtime.yml/badge.svg) 2 | 3 | # ZFlow Process Runtime 4 | 5 | The main runtime for the execution of the directed acyclic graph 6 | 7 | ## Runtime example 8 | 9 | Some details may be hidden for brevity 10 | 11 | A simple component 12 | 13 | ```rs 14 | // Create a component 15 | let mut my_component = Component::new(ComponentOptions { 16 | forward_brackets:HashMap::new(), 17 | // set input port `in` 18 | in_ports: HashMap::from([( 19 | "in".to_string(), 20 | InPort::default(), 21 | )]), 22 | // set output port `out` 23 | out_ports: HashMap::from([( 24 | "out".to_string(), 25 | OutPort::default(), 26 | )]), 27 | process: Box::new(move |this| { 28 | if let Ok(handle) = this.try_lock().as_mut() { 29 | // get something from input port 30 | if let Some(input_data) = handle.input().get("in") { 31 | // 32 | } 33 | // send output 34 | handle.output().send(&("out", json!("Hello World!"))); 35 | } 36 | Ok(ProcessResult::default()) 37 | }), 38 | ..ComponentOptions::default() 39 | }); 40 | ``` 41 | 42 | Connect another component to `my_component` and run the network 43 | 44 | ```rs 45 | // another component 46 | let mut second_component = Component::new(ComponentOptions {...}); 47 | 48 | // setup the fbp graph 49 | let mut graph = Graph::new("", false); 50 | g.add_node("first_component", "first_component_process", None) 51 | .add_node("second_component", "second_component_process", None) 52 | // trigger the first component with an initial packet 53 | .add_initial(json!("start"), "first_component", "in", None) 54 | // send the output of `first_component` to the input of the `second_component` 55 | .add_edge("first_component", "out", "second_component", "in", None); 56 | 57 | // create a network to run this graph 58 | let mut network = Network::create(graph.clone(), NetworkOptions { 59 | subscribe_graph: false, 60 | delay: true, 61 | base_dir: "/".to_string(), 62 | ..Default::default() 63 | }); 64 | 65 | // register the components to the node ids 66 | let loader = network.get_loader(); 67 | loader.register_component("first_component", "first_component_process", my_component).unwrap(); 68 | loader.register_component("second_component", "second_component_process", second_component).unwrap(); 69 | 70 | // sync graph with network 71 | if let Ok(nw) = network.connect().unwrap().try_lock() { 72 | // start the network 73 | nw.start().unwrap(); 74 | } 75 | ``` 76 | 77 | See [full example](https://github.com/darmie/zflow/blob/main/zflow_runtime/src/component_test.rs#L396) that demonstrates generation of an HTML code using ZFlow. 78 | -------------------------------------------------------------------------------- /crates/zflow_runtime/build.rs: -------------------------------------------------------------------------------- 1 | use std::{env, path::PathBuf}; 2 | 3 | fn main(){ 4 | let o = PathBuf::from(env::var_os("OUT_DIR").unwrap()); 5 | let runtime_snapshot_path = o.join("DENO_RUNTIME_SNAPSHOT.bin"); 6 | #[cfg(feature = "deno_embed")] 7 | deno_runtime::snapshot::create_runtime_snapshot(runtime_snapshot_path, deno_runtime::ops::bootstrap::SnapshotOptions::default()); 8 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/deno/snapshot.rs: -------------------------------------------------------------------------------- 1 | pub static DENO_SNAPSHOT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/DENO_RUNTIME_SNAPSHOT.bin")); 2 | 3 | -------------------------------------------------------------------------------- /crates/zflow_runtime/deno/transpiler.rs: -------------------------------------------------------------------------------- 1 | use deno_ast::{MediaType, ParseParams, SourceTextInfo}; 2 | use deno_core::error::AnyError; 3 | use deno_core::{ ModuleCodeString, ModuleName, SourceMapData}; 4 | use std::path::Path; 5 | 6 | pub fn maybe_transpile_source( 7 | name: ModuleName, 8 | source: ModuleCodeString, 9 | ) -> Result<(ModuleCodeString, Option), AnyError> { 10 | // Always transpile `node:` built-in modules, since they might be TypeScript. 11 | let media_type = if name.starts_with("node:") { 12 | MediaType::TypeScript 13 | } else { 14 | MediaType::from_path(Path::new(&name)) 15 | }; 16 | 17 | match media_type { 18 | MediaType::TypeScript => {} 19 | MediaType::JavaScript => return Ok((source, None)), 20 | MediaType::Mjs => return Ok((source, None)), 21 | _ => panic!( 22 | "Unsupported media type for snapshotting {media_type:?} for file {}", 23 | name 24 | ), 25 | } 26 | 27 | let parsed = deno_ast::parse_module(ParseParams { 28 | specifier: deno_core::url::Url::parse(&name).unwrap(), 29 | text_info: SourceTextInfo::from_string(source.as_str().to_owned()), 30 | media_type, 31 | capture_tokens: false, 32 | scope_analysis: false, 33 | maybe_syntax: None, 34 | })?; 35 | let transpiled_source = parsed.transpile(&deno_ast::EmitOptions { 36 | imports_not_used_as_values: deno_ast::ImportsNotUsedAsValues::Remove, 37 | inline_source_map: false, 38 | source_map: cfg!(debug_assertions), 39 | ..Default::default() 40 | })?; 41 | 42 | let maybe_source_map: Option = transpiled_source 43 | .source_map 44 | .map(|sm| sm.into_bytes().into()); 45 | 46 | Ok((transpiled_source.text.into(), maybe_source_map)) 47 | } 48 | -------------------------------------------------------------------------------- /crates/zflow_runtime/errors.rs: -------------------------------------------------------------------------------- 1 | use std::pin::Pin; 2 | 3 | use futures::{future::join_all, Future}; 4 | 5 | pub async fn async_transform( 6 | futures: Vec>>>>, 7 | ) -> Result<(), String> { 8 | let mut errors = String::new(); 9 | for v in join_all(futures).await.iter() { 10 | match v { 11 | Err(msg) => { 12 | errors.push_str(msg); 13 | errors.push('\n'); 14 | } 15 | _ => {} 16 | } 17 | } 18 | if !errors.is_empty() { 19 | return Err(errors); 20 | } 21 | Ok(()) 22 | } 23 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std.zip -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/bytes/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/bytes/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/bytes/reader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytes 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "unicode/utf8" 11 | ) 12 | 13 | // A Reader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker, 14 | // io.ByteScanner, and io.RuneScanner interfaces by reading from 15 | // a byte slice. 16 | // Unlike a Buffer, a Reader is read-only and supports seeking. 17 | // The zero value for Reader operates like a Reader of an empty slice. 18 | type Reader struct { 19 | s []byte 20 | i int64 // current reading index 21 | prevRune int // index of previous rune; or < 0 22 | } 23 | 24 | // Len returns the number of bytes of the unread portion of the 25 | // slice. 26 | func (r *Reader) Len() int { 27 | if r.i >= int64(len(r.s)) { 28 | return 0 29 | } 30 | return int(int64(len(r.s)) - r.i) 31 | } 32 | 33 | // Size returns the original length of the underlying byte slice. 34 | // Size is the number of bytes available for reading via ReadAt. 35 | // The returned value is always the same and is not affected by calls 36 | // to any other method. 37 | func (r *Reader) Size() int64 { return int64(len(r.s)) } 38 | 39 | // Read implements the io.Reader interface. 40 | func (r *Reader) Read(b []byte) (n int, err error) { 41 | if r.i >= int64(len(r.s)) { 42 | return 0, io.EOF 43 | } 44 | r.prevRune = -1 45 | n = copy(b, r.s[r.i:]) 46 | r.i += int64(n) 47 | return 48 | } 49 | 50 | // ReadAt implements the io.ReaderAt interface. 51 | func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) { 52 | // cannot modify state - see io.ReaderAt 53 | if off < 0 { 54 | return 0, errors.New("bytes.Reader.ReadAt: negative offset") 55 | } 56 | if off >= int64(len(r.s)) { 57 | return 0, io.EOF 58 | } 59 | n = copy(b, r.s[off:]) 60 | if n < len(b) { 61 | err = io.EOF 62 | } 63 | return 64 | } 65 | 66 | // ReadByte implements the io.ByteReader interface. 67 | func (r *Reader) ReadByte() (byte, error) { 68 | r.prevRune = -1 69 | if r.i >= int64(len(r.s)) { 70 | return 0, io.EOF 71 | } 72 | b := r.s[r.i] 73 | r.i++ 74 | return b, nil 75 | } 76 | 77 | // UnreadByte complements ReadByte in implementing the io.ByteScanner interface. 78 | func (r *Reader) UnreadByte() error { 79 | if r.i <= 0 { 80 | return errors.New("bytes.Reader.UnreadByte: at beginning of slice") 81 | } 82 | r.prevRune = -1 83 | r.i-- 84 | return nil 85 | } 86 | 87 | // ReadRune implements the io.RuneReader interface. 88 | func (r *Reader) ReadRune() (ch rune, size int, err error) { 89 | if r.i >= int64(len(r.s)) { 90 | r.prevRune = -1 91 | return 0, 0, io.EOF 92 | } 93 | r.prevRune = int(r.i) 94 | if c := r.s[r.i]; c < utf8.RuneSelf { 95 | r.i++ 96 | return rune(c), 1, nil 97 | } 98 | ch, size = utf8.DecodeRune(r.s[r.i:]) 99 | r.i += int64(size) 100 | return 101 | } 102 | 103 | // UnreadRune complements ReadRune in implementing the io.RuneScanner interface. 104 | func (r *Reader) UnreadRune() error { 105 | if r.i <= 0 { 106 | return errors.New("bytes.Reader.UnreadRune: at beginning of slice") 107 | } 108 | if r.prevRune < 0 { 109 | return errors.New("bytes.Reader.UnreadRune: previous operation was not ReadRune") 110 | } 111 | r.i = int64(r.prevRune) 112 | r.prevRune = -1 113 | return nil 114 | } 115 | 116 | // Seek implements the io.Seeker interface. 117 | func (r *Reader) Seek(offset int64, whence int) (int64, error) { 118 | r.prevRune = -1 119 | var abs int64 120 | switch whence { 121 | case io.SeekStart: 122 | abs = offset 123 | case io.SeekCurrent: 124 | abs = r.i + offset 125 | case io.SeekEnd: 126 | abs = int64(len(r.s)) + offset 127 | default: 128 | return 0, errors.New("bytes.Reader.Seek: invalid whence") 129 | } 130 | if abs < 0 { 131 | return 0, errors.New("bytes.Reader.Seek: negative position") 132 | } 133 | r.i = abs 134 | return abs, nil 135 | } 136 | 137 | // WriteTo implements the io.WriterTo interface. 138 | func (r *Reader) WriteTo(w io.Writer) (n int64, err error) { 139 | r.prevRune = -1 140 | if r.i >= int64(len(r.s)) { 141 | return 0, nil 142 | } 143 | b := r.s[r.i:] 144 | m, err := w.Write(b) 145 | if m > len(b) { 146 | panic("bytes.Reader.WriteTo: invalid Write count") 147 | } 148 | r.i += int64(m) 149 | n = int64(m) 150 | if m != len(b) && err == nil { 151 | err = io.ErrShortWrite 152 | } 153 | return 154 | } 155 | 156 | // Reset resets the Reader to be reading from b. 157 | func (r *Reader) Reset(b []byte) { *r = Reader{b, 0, -1} } 158 | 159 | // NewReader returns a new Reader reading from b. 160 | func NewReader(b []byte) *Reader { return &Reader{b, 0, -1} } 161 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/errors/errors.gos: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Goscript Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package errors 6 | 7 | // New returns an error that formats as the given text. 8 | // Each call to New returns a distinct error value even if the text is identical. 9 | func New(text string) error { 10 | return &errorString{text} 11 | } 12 | 13 | // errorString is a trivial implementation of error. 14 | type errorString struct { 15 | s string 16 | } 17 | 18 | func (e *errorString) Error() string { 19 | return e.s 20 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/fmt/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/fmt/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/fmt2/fmt2.gos: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Goscript Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package fmt2 6 | 7 | type ffiFmt2 interface { 8 | println(a ...interface{}) 9 | printf(a ...interface{}) 10 | } 11 | 12 | func Println(a ...interface{}) { 13 | var f = ffi(ffiFmt2, "fmt2") 14 | f.println(a...) 15 | } 16 | 17 | func Printf(a ...interface{}) { 18 | var f = ffi(ffiFmt2, "fmt2") 19 | f.printf(a...) 20 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/internal/bytealg/bytealg.gos: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Goscript Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytealg 6 | 7 | // todo: implement these in native code 8 | 9 | 10 | func IndexByte(b []byte, c byte) int { 11 | for i, x := range b { 12 | if x == c { 13 | return i 14 | } 15 | } 16 | return -1 17 | } 18 | 19 | func IndexByteString(s string, c byte) int { 20 | for i := 0; i < len(s); i++ { 21 | if s[i] == c { 22 | return i 23 | } 24 | } 25 | return -1 26 | } 27 | 28 | func Count(b []byte, c byte) int { 29 | n := 0 30 | for _, x := range b { 31 | if x == c { 32 | n++ 33 | } 34 | } 35 | return n 36 | } 37 | 38 | func CountString(s string, c byte) int { 39 | n := 0 40 | for i := 0; i < len(s); i++ { 41 | if s[i] == c { 42 | n++ 43 | } 44 | } 45 | return n 46 | } 47 | 48 | 49 | func Compare(a, b []byte) int { 50 | l := len(a) 51 | if len(b) < l { 52 | l = len(b) 53 | } 54 | if l == 0 || &a[0] == &b[0] { 55 | goto samebytes 56 | } 57 | for i := 0; i < l; i++ { 58 | c1, c2 := a[i], b[i] 59 | if c1 < c2 { 60 | return -1 61 | } 62 | if c1 > c2 { 63 | return +1 64 | } 65 | } 66 | samebytes: 67 | if len(a) < len(b) { 68 | return -1 69 | } 70 | if len(a) > len(b) { 71 | return +1 72 | } 73 | return 0 74 | } 75 | 76 | func Equal(a, b []byte) bool { 77 | l := len(a) 78 | if len(b) != l { 79 | return false 80 | } 81 | for i := 0; i < l; i++ { 82 | if a[i] != b[i] { 83 | return false 84 | } 85 | } 86 | return true 87 | } 88 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/io/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/io/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/io/ioutil/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/io/ioutil/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/io/ioutil/tempfile.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ioutil 6 | 7 | import ( 8 | "os" 9 | "path/filepath" 10 | "strconv" 11 | "strings" 12 | "sync" 13 | "time" 14 | ) 15 | 16 | // Random number state. 17 | // We generate random temporary file names so that there's a good 18 | // chance the file doesn't exist yet - keeps the number of tries in 19 | // TempFile to a minimum. 20 | var rand uint32 21 | var randmu sync.Mutex 22 | 23 | func reseed() uint32 { 24 | return uint32(time.Now().UnixNano() + int64(os.Getpid())) 25 | } 26 | 27 | func nextRandom() string { 28 | randmu.Lock() 29 | r := rand 30 | if r == 0 { 31 | r = reseed() 32 | } 33 | r = r*1664525 + 1013904223 // constants from Numerical Recipes 34 | rand = r 35 | randmu.Unlock() 36 | return strconv.Itoa(int(1e9 + r%1e9))[1:] 37 | } 38 | 39 | // TempFile creates a new temporary file in the directory dir, 40 | // opens the file for reading and writing, and returns the resulting *os.File. 41 | // The filename is generated by taking pattern and adding a random 42 | // string to the end. If pattern includes a "*", the random string 43 | // replaces the last "*". 44 | // If dir is the empty string, TempFile uses the default directory 45 | // for temporary files (see os.TempDir). 46 | // Multiple programs calling TempFile simultaneously 47 | // will not choose the same file. The caller can use f.Name() 48 | // to find the pathname of the file. It is the caller's responsibility 49 | // to remove the file when no longer needed. 50 | func TempFile(dir, pattern string) (f *os.File, err error) { 51 | if dir == "" { 52 | dir = os.TempDir() 53 | } 54 | 55 | var prefix, suffix string 56 | if pos := strings.LastIndex(pattern, "*"); pos != -1 { 57 | prefix, suffix = pattern[:pos], pattern[pos+1:] 58 | } else { 59 | prefix = pattern 60 | } 61 | 62 | nconflict := 0 63 | for i := 0; i < 10000; i++ { 64 | name := filepath.Join(dir, prefix+nextRandom()+suffix) 65 | f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) 66 | if os.IsExist(err) { 67 | if nconflict++; nconflict > 10 { 68 | randmu.Lock() 69 | rand = reseed() 70 | randmu.Unlock() 71 | } 72 | continue 73 | } 74 | break 75 | } 76 | return 77 | } 78 | 79 | // TempDir creates a new temporary directory in the directory dir 80 | // with a name beginning with prefix and returns the path of the 81 | // new directory. If dir is the empty string, TempDir uses the 82 | // default directory for temporary files (see os.TempDir). 83 | // Multiple programs calling TempDir simultaneously 84 | // will not choose the same directory. It is the caller's responsibility 85 | // to remove the directory when no longer needed. 86 | func TempDir(dir, prefix string) (name string, err error) { 87 | if dir == "" { 88 | dir = os.TempDir() 89 | } 90 | 91 | nconflict := 0 92 | for i := 0; i < 10000; i++ { 93 | try := filepath.Join(dir, prefix+nextRandom()) 94 | err = os.Mkdir(try, 0700) 95 | if os.IsExist(err) { 96 | if nconflict++; nconflict > 10 { 97 | randmu.Lock() 98 | rand = reseed() 99 | randmu.Unlock() 100 | } 101 | continue 102 | } 103 | if os.IsNotExist(err) { 104 | if _, err := os.Stat(dir); os.IsNotExist(err) { 105 | return "", err 106 | } 107 | } 108 | if err == nil { 109 | name = try 110 | } 111 | break 112 | } 113 | return 114 | } 115 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/io/multi.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package io 6 | 7 | type eofReader struct{} 8 | 9 | func (eofReader) Read([]byte) (int, error) { 10 | return 0, EOF 11 | } 12 | 13 | type multiReader struct { 14 | readers []Reader 15 | } 16 | 17 | func (mr *multiReader) Read(p []byte) (n int, err error) { 18 | for len(mr.readers) > 0 { 19 | // Optimization to flatten nested multiReaders (Issue 13558). 20 | if len(mr.readers) == 1 { 21 | if r, ok := mr.readers[0].(*multiReader); ok { 22 | mr.readers = r.readers 23 | continue 24 | } 25 | } 26 | n, err = mr.readers[0].Read(p) 27 | if err == EOF { 28 | // Use eofReader instead of nil to avoid nil panic 29 | // after performing flatten (Issue 18232). 30 | mr.readers[0] = eofReader{} // permit earlier GC 31 | mr.readers = mr.readers[1:] 32 | } 33 | if n > 0 || err != EOF { 34 | if err == EOF && len(mr.readers) > 0 { 35 | // Don't return EOF yet. More readers remain. 36 | err = nil 37 | } 38 | return 39 | } 40 | } 41 | return 0, EOF 42 | } 43 | 44 | // MultiReader returns a Reader that's the logical concatenation of 45 | // the provided input readers. They're read sequentially. Once all 46 | // inputs have returned EOF, Read will return EOF. If any of the readers 47 | // return a non-nil, non-EOF error, Read will return that error. 48 | func MultiReader(readers ...Reader) Reader { 49 | r := make([]Reader, len(readers)) 50 | copy(r, readers) 51 | return &multiReader{r} 52 | } 53 | 54 | type multiWriter struct { 55 | writers []Writer 56 | } 57 | 58 | func (t *multiWriter) Write(p []byte) (n int, err error) { 59 | for _, w := range t.writers { 60 | n, err = w.Write(p) 61 | if err != nil { 62 | return 63 | } 64 | if n != len(p) { 65 | err = ErrShortWrite 66 | return 67 | } 68 | } 69 | return len(p), nil 70 | } 71 | 72 | var _ StringWriter = (*multiWriter)(nil) 73 | 74 | func (t *multiWriter) WriteString(s string) (n int, err error) { 75 | var p []byte // lazily initialized if/when needed 76 | for _, w := range t.writers { 77 | if sw, ok := w.(StringWriter); ok { 78 | n, err = sw.WriteString(s) 79 | } else { 80 | if p == nil { 81 | p = []byte(s) 82 | } 83 | n, err = w.Write(p) 84 | } 85 | if err != nil { 86 | return 87 | } 88 | if n != len(s) { 89 | err = ErrShortWrite 90 | return 91 | } 92 | } 93 | return len(s), nil 94 | } 95 | 96 | // MultiWriter creates a writer that duplicates its writes to all the 97 | // provided writers, similar to the Unix tee(1) command. 98 | // 99 | // Each write is written to each listed writer, one at a time. 100 | // If a listed writer returns an error, that overall write operation 101 | // stops and returns the error; it does not continue down the list. 102 | func MultiWriter(writers ...Writer) Writer { 103 | allWriters := make([]Writer, 0, len(writers)) 104 | for _, w := range writers { 105 | if mw, ok := w.(*multiWriter); ok { 106 | allWriters = append(allWriters, mw.writers...) 107 | } else { 108 | allWriters = append(allWriters, w) 109 | } 110 | } 111 | return &multiWriter{allWriters} 112 | } 113 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/math/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/abs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Abs returns the absolute value of x. 8 | // 9 | // Special cases are: 10 | // Abs(±Inf) = +Inf 11 | // Abs(NaN) = NaN 12 | func Abs(x float64) float64 { 13 | return Float64frombits(Float64bits(x) &^ (1 << 63)) 14 | } 15 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/acosh.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // The original C code, the long comment, and the constants 8 | // below are from FreeBSD's /usr/src/lib/msun/src/e_acosh.c 9 | // and came with this notice. The go code is a simplified 10 | // version of the original C. 11 | // 12 | // ==================================================== 13 | // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 14 | // 15 | // Developed at SunPro, a Sun Microsystems, Inc. business. 16 | // Permission to use, copy, modify, and distribute this 17 | // software is freely granted, provided that this notice 18 | // is preserved. 19 | // ==================================================== 20 | // 21 | // 22 | // __ieee754_acosh(x) 23 | // Method : 24 | // Based on 25 | // acosh(x) = log [ x + sqrt(x*x-1) ] 26 | // we have 27 | // acosh(x) := log(x)+ln2, if x is large; else 28 | // acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else 29 | // acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1. 30 | // 31 | // Special cases: 32 | // acosh(x) is NaN with signal if x<1. 33 | // acosh(NaN) is NaN without signal. 34 | // 35 | 36 | // Acosh returns the inverse hyperbolic cosine of x. 37 | // 38 | // Special cases are: 39 | // Acosh(+Inf) = +Inf 40 | // Acosh(x) = NaN if x < 1 41 | // Acosh(NaN) = NaN 42 | func Acosh(x float64) float64 { 43 | const ( 44 | Ln2 = 6.93147180559945286227e-01 // 0x3FE62E42FEFA39EF 45 | Large = 1 << 28 // 2**28 46 | ) 47 | // first case is special case 48 | switch { 49 | case x < 1 || IsNaN(x): 50 | return NaN() 51 | case x == 1: 52 | return 0 53 | case x >= Large: 54 | return Log(x) + Ln2 // x > 2**28 55 | case x > 2: 56 | return Log(2*x - 1/(x+Sqrt(x*x-1))) // 2**28 > x > 2 57 | } 58 | t := x - 1 59 | return Log1p(t + Sqrt(2*t+t*t)) // 2 >= x > 1 60 | } 61 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/asin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Floating-point arcsine and arccosine. 9 | 10 | They are implemented by computing the arctangent 11 | after appropriate range reduction. 12 | */ 13 | 14 | // Asin returns the arcsine, in radians, of x. 15 | // 16 | // Special cases are: 17 | // Asin(±0) = ±0 18 | // Asin(x) = NaN if x < -1 or x > 1 19 | func Asin(x float64) float64 { 20 | if x == 0 { 21 | return x // special case 22 | } 23 | sign := false 24 | if x < 0 { 25 | x = -x 26 | sign = true 27 | } 28 | if x > 1 { 29 | return NaN() // special case 30 | } 31 | 32 | temp := Sqrt(1 - x*x) 33 | if x > 0.7 { 34 | temp = Pi/2 - satan(temp/x) 35 | } else { 36 | temp = satan(x / temp) 37 | } 38 | 39 | if sign { 40 | temp = -temp 41 | } 42 | return temp 43 | } 44 | 45 | // Acos returns the arccosine, in radians, of x. 46 | // 47 | // Special case is: 48 | // Acos(x) = NaN if x < -1 or x > 1 49 | func Acos(x float64) float64 50 | 51 | func acos(x float64) float64 { 52 | return Pi/2 - Asin(x) 53 | } 54 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/asinh.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // The original C code, the long comment, and the constants 8 | // below are from FreeBSD's /usr/src/lib/msun/src/s_asinh.c 9 | // and came with this notice. The go code is a simplified 10 | // version of the original C. 11 | // 12 | // ==================================================== 13 | // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 14 | // 15 | // Developed at SunPro, a Sun Microsystems, Inc. business. 16 | // Permission to use, copy, modify, and distribute this 17 | // software is freely granted, provided that this notice 18 | // is preserved. 19 | // ==================================================== 20 | // 21 | // 22 | // asinh(x) 23 | // Method : 24 | // Based on 25 | // asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 26 | // we have 27 | // asinh(x) := x if 1+x*x=1, 28 | // := sign(x)*(log(x)+ln2)) for large |x|, else 29 | // := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else 30 | // := sign(x)*log1p(|x| + x**2/(1 + sqrt(1+x**2))) 31 | // 32 | 33 | // Asinh returns the inverse hyperbolic sine of x. 34 | // 35 | // Special cases are: 36 | // Asinh(±0) = ±0 37 | // Asinh(±Inf) = ±Inf 38 | // Asinh(NaN) = NaN 39 | func Asinh(x float64) float64 { 40 | const ( 41 | Ln2 = 6.93147180559945286227e-01 // 0x3FE62E42FEFA39EF 42 | NearZero = 1.0 / (1 << 28) // 2**-28 43 | Large = 1 << 28 // 2**28 44 | ) 45 | // special cases 46 | if IsNaN(x) || IsInf(x, 0) { 47 | return x 48 | } 49 | sign := false 50 | if x < 0 { 51 | x = -x 52 | sign = true 53 | } 54 | var temp float64 55 | switch { 56 | case x > Large: 57 | temp = Log(x) + Ln2 // |x| > 2**28 58 | case x > 2: 59 | temp = Log(2*x + 1/(Sqrt(x*x+1)+x)) // 2**28 > |x| > 2.0 60 | case x < NearZero: 61 | temp = x // |x| < 2**-28 62 | default: 63 | temp = Log1p(x + x*x/(1+Sqrt(1+x*x))) // 2.0 > |x| > 2**-28 64 | } 65 | if sign { 66 | temp = -temp 67 | } 68 | return temp 69 | } 70 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/atan.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Floating-point arctangent. 9 | */ 10 | 11 | // The original C code, the long comment, and the constants below were 12 | // from http://netlib.sandia.gov/cephes/cmath/atan.c, available from 13 | // http://www.netlib.org/cephes/cmath.tgz. 14 | // The go code is a version of the original C. 15 | // 16 | // atan.c 17 | // Inverse circular tangent (arctangent) 18 | // 19 | // SYNOPSIS: 20 | // double x, y, atan(); 21 | // y = atan( x ); 22 | // 23 | // DESCRIPTION: 24 | // Returns radian angle between -pi/2 and +pi/2 whose tangent is x. 25 | // 26 | // Range reduction is from three intervals into the interval from zero to 0.66. 27 | // The approximant uses a rational function of degree 4/5 of the form 28 | // x + x**3 P(x)/Q(x). 29 | // 30 | // ACCURACY: 31 | // Relative error: 32 | // arithmetic domain # trials peak rms 33 | // DEC -10, 10 50000 2.4e-17 8.3e-18 34 | // IEEE -10, 10 10^6 1.8e-16 5.0e-17 35 | // 36 | // Cephes Math Library Release 2.8: June, 2000 37 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 38 | // 39 | // The readme file at http://netlib.sandia.gov/cephes/ says: 40 | // Some software in this archive may be from the book _Methods and 41 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 42 | // International, 1989) or from the Cephes Mathematical Library, a 43 | // commercial product. In either event, it is copyrighted by the author. 44 | // What you see here may be used freely but it comes with no support or 45 | // guarantee. 46 | // 47 | // The two known misprints in the book are repaired here in the 48 | // source listings for the gamma function and the incomplete beta 49 | // integral. 50 | // 51 | // Stephen L. Moshier 52 | // moshier@na-net.ornl.gov 53 | 54 | // xatan evaluates a series valid in the range [0, 0.66]. 55 | func xatan(x float64) float64 { 56 | const ( 57 | P0 = -8.750608600031904122785e-01 58 | P1 = -1.615753718733365076637e+01 59 | P2 = -7.500855792314704667340e+01 60 | P3 = -1.228866684490136173410e+02 61 | P4 = -6.485021904942025371773e+01 62 | Q0 = +2.485846490142306297962e+01 63 | Q1 = +1.650270098316988542046e+02 64 | Q2 = +4.328810604912902668951e+02 65 | Q3 = +4.853903996359136964868e+02 66 | Q4 = +1.945506571482613964425e+02 67 | ) 68 | z := x * x 69 | z = z * ((((P0*z+P1)*z+P2)*z+P3)*z + P4) / (((((z+Q0)*z+Q1)*z+Q2)*z+Q3)*z + Q4) 70 | z = x*z + x 71 | return z 72 | } 73 | 74 | // satan reduces its argument (known to be positive) 75 | // to the range [0, 0.66] and calls xatan. 76 | func satan(x float64) float64 { 77 | const ( 78 | Morebits = 6.123233995736765886130e-17 // pi/2 = PIO2 + Morebits 79 | Tan3pio8 = 2.41421356237309504880 // tan(3*pi/8) 80 | ) 81 | if x <= 0.66 { 82 | return xatan(x) 83 | } 84 | if x > Tan3pio8 { 85 | return Pi/2 - xatan(1/x) + Morebits 86 | } 87 | return Pi/4 + xatan((x-1)/(x+1)) + 0.5*Morebits 88 | } 89 | 90 | // Atan returns the arctangent, in radians, of x. 91 | // 92 | // Special cases are: 93 | // Atan(±0) = ±0 94 | // Atan(±Inf) = ±Pi/2 95 | func Atan(x float64) float64 { 96 | if x == 0 { 97 | return x 98 | } 99 | if x > 0 { 100 | return satan(x) 101 | } 102 | return -satan(-x) 103 | } 104 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/atan2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Atan2 returns the arc tangent of y/x, using 8 | // the signs of the two to determine the quadrant 9 | // of the return value. 10 | // 11 | // Special cases are (in order): 12 | // Atan2(y, NaN) = NaN 13 | // Atan2(NaN, x) = NaN 14 | // Atan2(+0, x>=0) = +0 15 | // Atan2(-0, x>=0) = -0 16 | // Atan2(+0, x<=-0) = +Pi 17 | // Atan2(-0, x<=-0) = -Pi 18 | // Atan2(y>0, 0) = +Pi/2 19 | // Atan2(y<0, 0) = -Pi/2 20 | // Atan2(+Inf, +Inf) = +Pi/4 21 | // Atan2(-Inf, +Inf) = -Pi/4 22 | // Atan2(+Inf, -Inf) = 3Pi/4 23 | // Atan2(-Inf, -Inf) = -3Pi/4 24 | // Atan2(y, +Inf) = 0 25 | // Atan2(y>0, -Inf) = +Pi 26 | // Atan2(y<0, -Inf) = -Pi 27 | // Atan2(+Inf, x) = +Pi/2 28 | // Atan2(-Inf, x) = -Pi/2 29 | func Atan2(y, x float64) float64 { 30 | // special cases 31 | switch { 32 | case IsNaN(y) || IsNaN(x): 33 | return NaN() 34 | case y == 0: 35 | if x >= 0 && !Signbit(x) { 36 | return Copysign(0, y) 37 | } 38 | return Copysign(Pi, y) 39 | case x == 0: 40 | return Copysign(Pi/2, y) 41 | case IsInf(x, 0): 42 | if IsInf(x, 1) { 43 | switch { 44 | case IsInf(y, 0): 45 | return Copysign(Pi/4, y) 46 | default: 47 | return Copysign(0, y) 48 | } 49 | } 50 | switch { 51 | case IsInf(y, 0): 52 | return Copysign(3*Pi/4, y) 53 | default: 54 | return Copysign(Pi, y) 55 | } 56 | case IsInf(y, 0): 57 | return Copysign(Pi/2, y) 58 | } 59 | 60 | // Call atan and determine the quadrant. 61 | q := Atan(y / x) 62 | if x < 0 { 63 | if q <= 0 { 64 | return q + Pi 65 | } 66 | return q - Pi 67 | } 68 | return q 69 | } 70 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/atanh.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // The original C code, the long comment, and the constants 8 | // below are from FreeBSD's /usr/src/lib/msun/src/e_atanh.c 9 | // and came with this notice. The go code is a simplified 10 | // version of the original C. 11 | // 12 | // ==================================================== 13 | // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 14 | // 15 | // Developed at SunPro, a Sun Microsystems, Inc. business. 16 | // Permission to use, copy, modify, and distribute this 17 | // software is freely granted, provided that this notice 18 | // is preserved. 19 | // ==================================================== 20 | // 21 | // 22 | // __ieee754_atanh(x) 23 | // Method : 24 | // 1. Reduce x to positive by atanh(-x) = -atanh(x) 25 | // 2. For x>=0.5 26 | // 1 2x x 27 | // atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) 28 | // 2 1 - x 1 - x 29 | // 30 | // For x<0.5 31 | // atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) 32 | // 33 | // Special cases: 34 | // atanh(x) is NaN if |x| > 1 with signal; 35 | // atanh(NaN) is that NaN with no signal; 36 | // atanh(+-1) is +-INF with signal. 37 | // 38 | 39 | // Atanh returns the inverse hyperbolic tangent of x. 40 | // 41 | // Special cases are: 42 | // Atanh(1) = +Inf 43 | // Atanh(±0) = ±0 44 | // Atanh(-1) = -Inf 45 | // Atanh(x) = NaN if x < -1 or x > 1 46 | // Atanh(NaN) = NaN 47 | func Atanh(x float64) float64 { 48 | const NearZero = 1.0 / (1 << 28) // 2**-28 49 | // special cases 50 | switch { 51 | case x < -1 || x > 1 || IsNaN(x): 52 | return NaN() 53 | case x == 1: 54 | return Inf(1) 55 | case x == -1: 56 | return Inf(-1) 57 | } 58 | sign := false 59 | if x < 0 { 60 | x = -x 61 | sign = true 62 | } 63 | var temp float64 64 | switch { 65 | case x < NearZero: 66 | temp = x 67 | case x < 0.5: 68 | temp = x + x 69 | temp = 0.5 * Log1p(temp+temp*x/(1-x)) 70 | default: 71 | temp = 0.5 * Log1p((x+x)/(1-x)) 72 | } 73 | if sign { 74 | temp = -temp 75 | } 76 | return temp 77 | } 78 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/bits.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | const ( 8 | uvnan = 0x7FF8000000000001 9 | uvinf = 0x7FF0000000000000 10 | uvneginf = 0xFFF0000000000000 11 | uvone = 0x3FF0000000000000 12 | mask = 0x7FF 13 | shift = 64 - 11 - 1 14 | bias = 1023 15 | signMask = 1 << 63 16 | fracMask = 1<= 0, negative infinity if sign < 0. 20 | func Inf(sign int) float64 { 21 | var v uint64 22 | if sign >= 0 { 23 | v = uvinf 24 | } else { 25 | v = uvneginf 26 | } 27 | return Float64frombits(v) 28 | } 29 | 30 | // NaN returns an IEEE 754 ``not-a-number'' value. 31 | func NaN() float64 { return Float64frombits(uvnan) } 32 | 33 | // IsNaN reports whether f is an IEEE 754 ``not-a-number'' value. 34 | func IsNaN(f float64) (is bool) { 35 | // IEEE 754 says that only NaNs satisfy f != f. 36 | // To avoid the floating-point hardware, could use: 37 | // x := Float64bits(f); 38 | // return uint32(x>>shift)&mask == mask && x != uvinf && x != uvneginf 39 | return f != f 40 | } 41 | 42 | // IsInf reports whether f is an infinity, according to sign. 43 | // If sign > 0, IsInf reports whether f is positive infinity. 44 | // If sign < 0, IsInf reports whether f is negative infinity. 45 | // If sign == 0, IsInf reports whether f is either infinity. 46 | func IsInf(f float64, sign int) bool { 47 | // Test for infinity by comparing against maximum float. 48 | // To avoid the floating-point hardware, could use: 49 | // x := Float64bits(f); 50 | // return sign >= 0 && x == uvinf || sign <= 0 && x == uvneginf; 51 | return sign >= 0 && f > MaxFloat64 || sign <= 0 && f < -MaxFloat64 52 | } 53 | 54 | // normalize returns a normal number y and exponent exp 55 | // satisfying x == y × 2**exp. It assumes x is finite and non-zero. 56 | func normalize(x float64) (y float64, exp int) { 57 | const SmallestNormal = 2.2250738585072014e-308 // 2**-1022 58 | if Abs(x) < SmallestNormal { 59 | return x * (1 << 52), -52 60 | } 61 | return x, 0 62 | } 63 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/bits/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/math/bits/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cbrt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // The go code is a modified version of the original C code from 8 | // http://www.netlib.org/fdlibm/s_cbrt.c and came with this notice. 9 | // 10 | // ==================================================== 11 | // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 12 | // 13 | // Developed at SunSoft, a Sun Microsystems, Inc. business. 14 | // Permission to use, copy, modify, and distribute this 15 | // software is freely granted, provided that this notice 16 | // is preserved. 17 | // ==================================================== 18 | 19 | // Cbrt returns the cube root of x. 20 | // 21 | // Special cases are: 22 | // Cbrt(±0) = ±0 23 | // Cbrt(±Inf) = ±Inf 24 | // Cbrt(NaN) = NaN 25 | func Cbrt(x float64) float64 { 26 | const ( 27 | B1 = 715094163 // (682-0.03306235651)*2**20 28 | B2 = 696219795 // (664-0.03306235651)*2**20 29 | C = 5.42857142857142815906e-01 // 19/35 = 0x3FE15F15F15F15F1 30 | D = -7.05306122448979611050e-01 // -864/1225 = 0xBFE691DE2532C834 31 | E = 1.41428571428571436819e+00 // 99/70 = 0x3FF6A0EA0EA0EA0F 32 | F = 1.60714285714285720630e+00 // 45/28 = 0x3FF9B6DB6DB6DB6E 33 | G = 3.57142857142857150787e-01 // 5/14 = 0x3FD6DB6DB6DB6DB7 34 | SmallestNormal = 2.22507385850720138309e-308 // 2**-1022 = 0x0010000000000000 35 | ) 36 | // special cases 37 | switch { 38 | case x == 0 || IsNaN(x) || IsInf(x, 0): 39 | return x 40 | } 41 | 42 | sign := false 43 | if x < 0 { 44 | x = -x 45 | sign = true 46 | } 47 | 48 | // rough cbrt to 5 bits 49 | t := Float64frombits(Float64bits(x)/3 + B1<<32) 50 | if x < SmallestNormal { 51 | // subnormal number 52 | t = float64(1 << 54) // set t= 2**54 53 | t *= x 54 | t = Float64frombits(Float64bits(t)/3 + B2<<32) 55 | } 56 | 57 | // new cbrt to 23 bits 58 | r := t * t / x 59 | s := C + r*t 60 | t *= G + F/(s+E+D/s) 61 | 62 | // chop to 22 bits, make larger than cbrt(x) 63 | t = Float64frombits(Float64bits(t)&(0xFFFFFFFFC<<28) + 1<<30) 64 | 65 | // one step newton iteration to 53 bits with error less than 0.667ulps 66 | s = t * t // t*t is exact 67 | r = x / s 68 | w := t + t 69 | r = (r - t) / (w + r) // r-s is exact 70 | t = t + t*r 71 | 72 | // restore the sign bit 73 | if sign { 74 | t = -t 75 | } 76 | return t 77 | } 78 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/math/cmplx/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/abs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package cmplx provides basic constants and mathematical functions for 6 | // complex numbers. 7 | package cmplx 8 | 9 | import "math" 10 | 11 | // Abs returns the absolute value (also called the modulus) of x. 12 | func Abs(x complex128) float64 { return math.Hypot(real(x), imag(x)) } 13 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/conj.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | // Conj returns the complex conjugate of x. 8 | func Conj(x complex128) complex128 { return complex(real(x), -imag(x)) } 9 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/exp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // The original C code, the long comment, and the constants 10 | // below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c. 11 | // The go code is a simplified version of the original C. 12 | // 13 | // Cephes Math Library Release 2.8: June, 2000 14 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 15 | // 16 | // The readme file at http://netlib.sandia.gov/cephes/ says: 17 | // Some software in this archive may be from the book _Methods and 18 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 19 | // International, 1989) or from the Cephes Mathematical Library, a 20 | // commercial product. In either event, it is copyrighted by the author. 21 | // What you see here may be used freely but it comes with no support or 22 | // guarantee. 23 | // 24 | // The two known misprints in the book are repaired here in the 25 | // source listings for the gamma function and the incomplete beta 26 | // integral. 27 | // 28 | // Stephen L. Moshier 29 | // moshier@na-net.ornl.gov 30 | 31 | // Complex exponential function 32 | // 33 | // DESCRIPTION: 34 | // 35 | // Returns the complex exponential of the complex argument z. 36 | // 37 | // If 38 | // z = x + iy, 39 | // r = exp(x), 40 | // then 41 | // w = r cos y + i r sin y. 42 | // 43 | // ACCURACY: 44 | // 45 | // Relative error: 46 | // arithmetic domain # trials peak rms 47 | // DEC -10,+10 8700 3.7e-17 1.1e-17 48 | // IEEE -10,+10 30000 3.0e-16 8.7e-17 49 | 50 | // Exp returns e**x, the base-e exponential of x. 51 | func Exp(x complex128) complex128 { 52 | r := math.Exp(real(x)) 53 | s, c := math.Sincos(imag(x)) 54 | return complex(r*c, r*s) 55 | } 56 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/isinf.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // IsInf reports whether either real(x) or imag(x) is an infinity. 10 | func IsInf(x complex128) bool { 11 | if math.IsInf(real(x), 0) || math.IsInf(imag(x), 0) { 12 | return true 13 | } 14 | return false 15 | } 16 | 17 | // Inf returns a complex infinity, complex(+Inf, +Inf). 18 | func Inf() complex128 { 19 | inf := math.Inf(1) 20 | return complex(inf, inf) 21 | } 22 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/isnan.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // IsNaN reports whether either real(x) or imag(x) is NaN 10 | // and neither is an infinity. 11 | func IsNaN(x complex128) bool { 12 | switch { 13 | case math.IsInf(real(x), 0) || math.IsInf(imag(x), 0): 14 | return false 15 | case math.IsNaN(real(x)) || math.IsNaN(imag(x)): 16 | return true 17 | } 18 | return false 19 | } 20 | 21 | // NaN returns a complex ``not-a-number'' value. 22 | func NaN() complex128 { 23 | nan := math.NaN() 24 | return complex(nan, nan) 25 | } 26 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/log.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // The original C code, the long comment, and the constants 10 | // below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c. 11 | // The go code is a simplified version of the original C. 12 | // 13 | // Cephes Math Library Release 2.8: June, 2000 14 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 15 | // 16 | // The readme file at http://netlib.sandia.gov/cephes/ says: 17 | // Some software in this archive may be from the book _Methods and 18 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 19 | // International, 1989) or from the Cephes Mathematical Library, a 20 | // commercial product. In either event, it is copyrighted by the author. 21 | // What you see here may be used freely but it comes with no support or 22 | // guarantee. 23 | // 24 | // The two known misprints in the book are repaired here in the 25 | // source listings for the gamma function and the incomplete beta 26 | // integral. 27 | // 28 | // Stephen L. Moshier 29 | // moshier@na-net.ornl.gov 30 | 31 | // Complex natural logarithm 32 | // 33 | // DESCRIPTION: 34 | // 35 | // Returns complex logarithm to the base e (2.718...) of 36 | // the complex argument z. 37 | // 38 | // If 39 | // z = x + iy, r = sqrt( x**2 + y**2 ), 40 | // then 41 | // w = log(r) + i arctan(y/x). 42 | // 43 | // The arctangent ranges from -PI to +PI. 44 | // 45 | // ACCURACY: 46 | // 47 | // Relative error: 48 | // arithmetic domain # trials peak rms 49 | // DEC -10,+10 7000 8.5e-17 1.9e-17 50 | // IEEE -10,+10 30000 5.0e-15 1.1e-16 51 | // 52 | // Larger relative error can be observed for z near 1 +i0. 53 | // In IEEE arithmetic the peak absolute error is 5.2e-16, rms 54 | // absolute error 1.0e-16. 55 | 56 | // Log returns the natural logarithm of x. 57 | func Log(x complex128) complex128 { 58 | return complex(math.Log(Abs(x)), Phase(x)) 59 | } 60 | 61 | // Log10 returns the decimal logarithm of x. 62 | func Log10(x complex128) complex128 { 63 | return math.Log10E * Log(x) 64 | } 65 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/phase.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // Phase returns the phase (also called the argument) of x. 10 | // The returned value is in the range [-Pi, Pi]. 11 | func Phase(x complex128) float64 { return math.Atan2(imag(x), real(x)) } 12 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/polar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | // Polar returns the absolute value r and phase θ of x, 8 | // such that x = r * e**θi. 9 | // The phase is in the range [-Pi, Pi]. 10 | func Polar(x complex128) (r, θ float64) { 11 | return Abs(x), Phase(x) 12 | } 13 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/pow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // The original C code, the long comment, and the constants 10 | // below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c. 11 | // The go code is a simplified version of the original C. 12 | // 13 | // Cephes Math Library Release 2.8: June, 2000 14 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 15 | // 16 | // The readme file at http://netlib.sandia.gov/cephes/ says: 17 | // Some software in this archive may be from the book _Methods and 18 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 19 | // International, 1989) or from the Cephes Mathematical Library, a 20 | // commercial product. In either event, it is copyrighted by the author. 21 | // What you see here may be used freely but it comes with no support or 22 | // guarantee. 23 | // 24 | // The two known misprints in the book are repaired here in the 25 | // source listings for the gamma function and the incomplete beta 26 | // integral. 27 | // 28 | // Stephen L. Moshier 29 | // moshier@na-net.ornl.gov 30 | 31 | // Complex power function 32 | // 33 | // DESCRIPTION: 34 | // 35 | // Raises complex A to the complex Zth power. 36 | // Definition is per AMS55 # 4.2.8, 37 | // analytically equivalent to cpow(a,z) = cexp(z clog(a)). 38 | // 39 | // ACCURACY: 40 | // 41 | // Relative error: 42 | // arithmetic domain # trials peak rms 43 | // IEEE -10,+10 30000 9.4e-15 1.5e-15 44 | 45 | // Pow returns x**y, the base-x exponential of y. 46 | // For generalized compatibility with math.Pow: 47 | // Pow(0, ±0) returns 1+0i 48 | // Pow(0, c) for real(c)<0 returns Inf+0i if imag(c) is zero, otherwise Inf+Inf i. 49 | func Pow(x, y complex128) complex128 { 50 | if x == 0 { // Guaranteed also true for x == -0. 51 | r, i := real(y), imag(y) 52 | switch { 53 | case r == 0: 54 | return 1 55 | case r < 0: 56 | if i == 0 { 57 | return complex(math.Inf(1), 0) 58 | } 59 | return Inf() 60 | case r > 0: 61 | return 0 62 | } 63 | panic("not reached") 64 | } 65 | modulus := Abs(x) 66 | if modulus == 0 { 67 | return complex(0, 0) 68 | } 69 | r := math.Pow(modulus, real(y)) 70 | arg := Phase(x) 71 | theta := real(y) * arg 72 | if imag(y) != 0 { 73 | r *= math.Exp(-imag(y) * arg) 74 | theta += imag(y) * math.Log(modulus) 75 | } 76 | s, c := math.Sincos(theta) 77 | return complex(r*c, r*s) 78 | } 79 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/rect.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // Rect returns the complex number x with polar coordinates r, θ. 10 | func Rect(r, θ float64) complex128 { 11 | s, c := math.Sincos(θ) 12 | return complex(r*c, r*s) 13 | } 14 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/sin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // The original C code, the long comment, and the constants 10 | // below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c. 11 | // The go code is a simplified version of the original C. 12 | // 13 | // Cephes Math Library Release 2.8: June, 2000 14 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 15 | // 16 | // The readme file at http://netlib.sandia.gov/cephes/ says: 17 | // Some software in this archive may be from the book _Methods and 18 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 19 | // International, 1989) or from the Cephes Mathematical Library, a 20 | // commercial product. In either event, it is copyrighted by the author. 21 | // What you see here may be used freely but it comes with no support or 22 | // guarantee. 23 | // 24 | // The two known misprints in the book are repaired here in the 25 | // source listings for the gamma function and the incomplete beta 26 | // integral. 27 | // 28 | // Stephen L. Moshier 29 | // moshier@na-net.ornl.gov 30 | 31 | // Complex circular sine 32 | // 33 | // DESCRIPTION: 34 | // 35 | // If 36 | // z = x + iy, 37 | // 38 | // then 39 | // 40 | // w = sin x cosh y + i cos x sinh y. 41 | // 42 | // csin(z) = -i csinh(iz). 43 | // 44 | // ACCURACY: 45 | // 46 | // Relative error: 47 | // arithmetic domain # trials peak rms 48 | // DEC -10,+10 8400 5.3e-17 1.3e-17 49 | // IEEE -10,+10 30000 3.8e-16 1.0e-16 50 | // Also tested by csin(casin(z)) = z. 51 | 52 | // Sin returns the sine of x. 53 | func Sin(x complex128) complex128 { 54 | s, c := math.Sincos(real(x)) 55 | sh, ch := sinhcosh(imag(x)) 56 | return complex(s*ch, c*sh) 57 | } 58 | 59 | // Complex hyperbolic sine 60 | // 61 | // DESCRIPTION: 62 | // 63 | // csinh z = (cexp(z) - cexp(-z))/2 64 | // = sinh x * cos y + i cosh x * sin y . 65 | // 66 | // ACCURACY: 67 | // 68 | // Relative error: 69 | // arithmetic domain # trials peak rms 70 | // IEEE -10,+10 30000 3.1e-16 8.2e-17 71 | 72 | // Sinh returns the hyperbolic sine of x. 73 | func Sinh(x complex128) complex128 { 74 | s, c := math.Sincos(imag(x)) 75 | sh, ch := sinhcosh(real(x)) 76 | return complex(c*sh, s*ch) 77 | } 78 | 79 | // Complex circular cosine 80 | // 81 | // DESCRIPTION: 82 | // 83 | // If 84 | // z = x + iy, 85 | // 86 | // then 87 | // 88 | // w = cos x cosh y - i sin x sinh y. 89 | // 90 | // ACCURACY: 91 | // 92 | // Relative error: 93 | // arithmetic domain # trials peak rms 94 | // DEC -10,+10 8400 4.5e-17 1.3e-17 95 | // IEEE -10,+10 30000 3.8e-16 1.0e-16 96 | 97 | // Cos returns the cosine of x. 98 | func Cos(x complex128) complex128 { 99 | s, c := math.Sincos(real(x)) 100 | sh, ch := sinhcosh(imag(x)) 101 | return complex(c*ch, -s*sh) 102 | } 103 | 104 | // Complex hyperbolic cosine 105 | // 106 | // DESCRIPTION: 107 | // 108 | // ccosh(z) = cosh x cos y + i sinh x sin y . 109 | // 110 | // ACCURACY: 111 | // 112 | // Relative error: 113 | // arithmetic domain # trials peak rms 114 | // IEEE -10,+10 30000 2.9e-16 8.1e-17 115 | 116 | // Cosh returns the hyperbolic cosine of x. 117 | func Cosh(x complex128) complex128 { 118 | s, c := math.Sincos(imag(x)) 119 | sh, ch := sinhcosh(real(x)) 120 | return complex(c*ch, s*sh) 121 | } 122 | 123 | // calculate sinh and cosh 124 | func sinhcosh(x float64) (sh, ch float64) { 125 | if math.Abs(x) <= 0.5 { 126 | return math.Sinh(x), math.Cosh(x) 127 | } 128 | e := math.Exp(x) 129 | ei := 0.5 / e 130 | e *= 0.5 131 | return e - ei, e + ei 132 | } 133 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/cmplx/sqrt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmplx 6 | 7 | import "math" 8 | 9 | // The original C code, the long comment, and the constants 10 | // below are from http://netlib.sandia.gov/cephes/c9x-complex/clog.c. 11 | // The go code is a simplified version of the original C. 12 | // 13 | // Cephes Math Library Release 2.8: June, 2000 14 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 15 | // 16 | // The readme file at http://netlib.sandia.gov/cephes/ says: 17 | // Some software in this archive may be from the book _Methods and 18 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 19 | // International, 1989) or from the Cephes Mathematical Library, a 20 | // commercial product. In either event, it is copyrighted by the author. 21 | // What you see here may be used freely but it comes with no support or 22 | // guarantee. 23 | // 24 | // The two known misprints in the book are repaired here in the 25 | // source listings for the gamma function and the incomplete beta 26 | // integral. 27 | // 28 | // Stephen L. Moshier 29 | // moshier@na-net.ornl.gov 30 | 31 | // Complex square root 32 | // 33 | // DESCRIPTION: 34 | // 35 | // If z = x + iy, r = |z|, then 36 | // 37 | // 1/2 38 | // Re w = [ (r + x)/2 ] , 39 | // 40 | // 1/2 41 | // Im w = [ (r - x)/2 ] . 42 | // 43 | // Cancelation error in r-x or r+x is avoided by using the 44 | // identity 2 Re w Im w = y. 45 | // 46 | // Note that -w is also a square root of z. The root chosen 47 | // is always in the right half plane and Im w has the same sign as y. 48 | // 49 | // ACCURACY: 50 | // 51 | // Relative error: 52 | // arithmetic domain # trials peak rms 53 | // DEC -10,+10 25000 3.2e-17 9.6e-18 54 | // IEEE -10,+10 1,000,000 2.9e-16 6.1e-17 55 | 56 | // Sqrt returns the square root of x. 57 | // The result r is chosen so that real(r) ≥ 0 and imag(r) has the same sign as imag(x). 58 | func Sqrt(x complex128) complex128 { 59 | if imag(x) == 0 { 60 | // Ensure that imag(r) has the same sign as imag(x) for imag(x) == signed zero. 61 | if real(x) == 0 { 62 | return complex(0, imag(x)) 63 | } 64 | if real(x) < 0 { 65 | return complex(0, math.Copysign(math.Sqrt(-real(x)), imag(x))) 66 | } 67 | return complex(math.Sqrt(real(x)), imag(x)) 68 | } 69 | if real(x) == 0 { 70 | if imag(x) < 0 { 71 | r := math.Sqrt(-0.5 * imag(x)) 72 | return complex(r, -r) 73 | } 74 | r := math.Sqrt(0.5 * imag(x)) 75 | return complex(r, r) 76 | } 77 | a := real(x) 78 | b := imag(x) 79 | var scale float64 80 | // Rescale to avoid internal overflow or underflow. 81 | if math.Abs(a) > 4 || math.Abs(b) > 4 { 82 | a *= 0.25 83 | b *= 0.25 84 | scale = 2 85 | } else { 86 | a *= 1.8014398509481984e16 // 2**54 87 | b *= 1.8014398509481984e16 88 | scale = 7.450580596923828125e-9 // 2**-27 89 | } 90 | r := math.Hypot(a, b) 91 | var t float64 92 | if a > 0 { 93 | t = math.Sqrt(0.5*r + 0.5*a) 94 | r = scale * math.Abs((0.5*b)/t) 95 | t *= scale 96 | } else { 97 | r = math.Sqrt(0.5*r - 0.5*a) 98 | t = scale * math.Abs((0.5*b)/r) 99 | r *= scale 100 | } 101 | if b < 0 { 102 | return complex(t, -r) 103 | } 104 | return complex(t, r) 105 | } 106 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/const.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package math provides basic constants and mathematical functions. 6 | // 7 | // This package does not guarantee bit-identical results across architectures. 8 | package math 9 | 10 | // Mathematical constants. 11 | const ( 12 | E = 2.71828182845904523536028747135266249775724709369995957496696763 // https://oeis.org/A001113 13 | Pi = 3.14159265358979323846264338327950288419716939937510582097494459 // https://oeis.org/A000796 14 | Phi = 1.61803398874989484820458683436563811772030917980576286213544862 // https://oeis.org/A001622 15 | 16 | Sqrt2 = 1.41421356237309504880168872420969807856967187537694807317667974 // https://oeis.org/A002193 17 | SqrtE = 1.64872127070012814684865078781416357165377610071014801157507931 // https://oeis.org/A019774 18 | SqrtPi = 1.77245385090551602729816748334114518279754945612238712821380779 // https://oeis.org/A002161 19 | SqrtPhi = 1.27201964951406896425242246173749149171560804184009624861664038 // https://oeis.org/A139339 20 | 21 | Ln2 = 0.693147180559945309417232121458176568075500134360255254120680009 // https://oeis.org/A002162 22 | Log2E = 1 / Ln2 23 | Ln10 = 2.30258509299404568401799145468436420760110148862877297603332790 // https://oeis.org/A002392 24 | Log10E = 1 / Ln10 25 | ) 26 | 27 | // Floating-point limit values. 28 | // Max is the largest finite value representable by the type. 29 | // SmallestNonzero is the smallest positive, non-zero value representable by the type. 30 | const ( 31 | MaxFloat32 = 3.40282346638528859811704183484516925440e+38 // 2**127 * (2**24 - 1) / 2**23 32 | SmallestNonzeroFloat32 = 1.401298464324817070923729583289916131280e-45 // 1 / 2**(127 - 1 + 23) 33 | 34 | MaxFloat64 = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52 35 | SmallestNonzeroFloat64 = 4.940656458412465441765687928682213723651e-324 // 1 / 2**(1023 - 1 + 52) 36 | ) 37 | 38 | // Integer limit values. 39 | const ( 40 | MaxInt8 = 1<<7 - 1 41 | MinInt8 = -1 << 7 42 | MaxInt16 = 1<<15 - 1 43 | MinInt16 = -1 << 15 44 | MaxInt32 = 1<<31 - 1 45 | MinInt32 = -1 << 31 46 | MaxInt64 = 1<<63 - 1 47 | MinInt64 = -1 << 63 48 | MaxUint8 = 1<<8 - 1 49 | MaxUint16 = 1<<16 - 1 50 | MaxUint32 = 1<<32 - 1 51 | MaxUint64 = 1<<64 - 1 52 | ) 53 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/copysign.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Copysign returns a value with the magnitude 8 | // of x and the sign of y. 9 | func Copysign(x, y float64) float64 { 10 | const sign = 1 << 63 11 | return Float64frombits(Float64bits(x)&^sign | Float64bits(y)&sign) 12 | } 13 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/dim.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Dim returns the maximum of x-y or 0. 8 | // 9 | // Special cases are: 10 | // Dim(+Inf, +Inf) = NaN 11 | // Dim(-Inf, -Inf) = NaN 12 | // Dim(x, NaN) = Dim(NaN, x) = NaN 13 | func Dim(x, y float64) float64 { 14 | // The special cases result in NaN after the subtraction: 15 | // +Inf - +Inf = NaN 16 | // -Inf - -Inf = NaN 17 | // NaN - y = NaN 18 | // x - NaN = NaN 19 | v := x - y 20 | if v <= 0 { 21 | // v is negative or 0 22 | return 0 23 | } 24 | // v is positive or NaN 25 | return v 26 | } 27 | 28 | // Max returns the larger of x or y. 29 | // 30 | // Special cases are: 31 | // Max(x, +Inf) = Max(+Inf, x) = +Inf 32 | // Max(x, NaN) = Max(NaN, x) = NaN 33 | // Max(+0, ±0) = Max(±0, +0) = +0 34 | // Max(-0, -0) = -0 35 | func Max(x, y float64) float64 { 36 | // special cases 37 | switch { 38 | case IsInf(x, 1) || IsInf(y, 1): 39 | return Inf(1) 40 | case IsNaN(x) || IsNaN(y): 41 | return NaN() 42 | case x == 0 && x == y: 43 | if Signbit(x) { 44 | return y 45 | } 46 | return x 47 | } 48 | if x > y { 49 | return x 50 | } 51 | return y 52 | } 53 | 54 | // Min returns the smaller of x or y. 55 | // 56 | // Special cases are: 57 | // Min(x, -Inf) = Min(-Inf, x) = -Inf 58 | // Min(x, NaN) = Min(NaN, x) = NaN 59 | // Min(-0, ±0) = Min(±0, -0) = -0 60 | func Min(x, y float64) float64 61 | 62 | func min(x, y float64) float64 { 63 | // special cases 64 | switch { 65 | case IsInf(x, -1) || IsInf(y, -1): 66 | return Inf(-1) 67 | case IsNaN(x) || IsNaN(y): 68 | return NaN() 69 | case x == 0 && x == y: 70 | if Signbit(x) { 71 | return x 72 | } 73 | return y 74 | } 75 | if x < y { 76 | return x 77 | } 78 | return y 79 | } 80 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/erfinv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Inverse of the floating-point error function. 9 | */ 10 | 11 | // This implementation is based on the rational approximation 12 | // of percentage points of normal distribution available from 13 | // https://www.jstor.org/stable/2347330. 14 | 15 | const ( 16 | // Coefficients for approximation to erf in |x| <= 0.85 17 | a0 = 1.1975323115670912564578e0 18 | a1 = 4.7072688112383978012285e1 19 | a2 = 6.9706266534389598238465e2 20 | a3 = 4.8548868893843886794648e3 21 | a4 = 1.6235862515167575384252e4 22 | a5 = 2.3782041382114385731252e4 23 | a6 = 1.1819493347062294404278e4 24 | a7 = 8.8709406962545514830200e2 25 | b0 = 1.0000000000000000000e0 26 | b1 = 4.2313330701600911252e1 27 | b2 = 6.8718700749205790830e2 28 | b3 = 5.3941960214247511077e3 29 | b4 = 2.1213794301586595867e4 30 | b5 = 3.9307895800092710610e4 31 | b6 = 2.8729085735721942674e4 32 | b7 = 5.2264952788528545610e3 33 | // Coefficients for approximation to erf in 0.85 < |x| <= 1-2*exp(-25) 34 | c0 = 1.42343711074968357734e0 35 | c1 = 4.63033784615654529590e0 36 | c2 = 5.76949722146069140550e0 37 | c3 = 3.64784832476320460504e0 38 | c4 = 1.27045825245236838258e0 39 | c5 = 2.41780725177450611770e-1 40 | c6 = 2.27238449892691845833e-2 41 | c7 = 7.74545014278341407640e-4 42 | d0 = 1.4142135623730950488016887e0 43 | d1 = 2.9036514445419946173133295e0 44 | d2 = 2.3707661626024532365971225e0 45 | d3 = 9.7547832001787427186894837e-1 46 | d4 = 2.0945065210512749128288442e-1 47 | d5 = 2.1494160384252876777097297e-2 48 | d6 = 7.7441459065157709165577218e-4 49 | d7 = 1.4859850019840355905497876e-9 50 | // Coefficients for approximation to erf in 1-2*exp(-25) < |x| < 1 51 | e0 = 6.65790464350110377720e0 52 | e1 = 5.46378491116411436990e0 53 | e2 = 1.78482653991729133580e0 54 | e3 = 2.96560571828504891230e-1 55 | e4 = 2.65321895265761230930e-2 56 | e5 = 1.24266094738807843860e-3 57 | e6 = 2.71155556874348757815e-5 58 | e7 = 2.01033439929228813265e-7 59 | f0 = 1.414213562373095048801689e0 60 | f1 = 8.482908416595164588112026e-1 61 | f2 = 1.936480946950659106176712e-1 62 | f3 = 2.103693768272068968719679e-2 63 | f4 = 1.112800997078859844711555e-3 64 | f5 = 2.611088405080593625138020e-5 65 | f6 = 2.010321207683943062279931e-7 66 | f7 = 2.891024605872965461538222e-15 67 | ) 68 | 69 | // Erfinv returns the inverse error function of x. 70 | // 71 | // Special cases are: 72 | // Erfinv(1) = +Inf 73 | // Erfinv(-1) = -Inf 74 | // Erfinv(x) = NaN if x < -1 or x > 1 75 | // Erfinv(NaN) = NaN 76 | func Erfinv(x float64) float64 { 77 | // special cases 78 | if IsNaN(x) || x <= -1 || x >= 1 { 79 | if x == -1 || x == 1 { 80 | return Inf(int(x)) 81 | } 82 | return NaN() 83 | } 84 | 85 | sign := false 86 | if x < 0 { 87 | x = -x 88 | sign = true 89 | } 90 | 91 | var ans float64 92 | if x <= 0.85 { // |x| <= 0.85 93 | r := 0.180625 - 0.25*x*x 94 | z1 := ((((((a7*r+a6)*r+a5)*r+a4)*r+a3)*r+a2)*r+a1)*r + a0 95 | z2 := ((((((b7*r+b6)*r+b5)*r+b4)*r+b3)*r+b2)*r+b1)*r + b0 96 | ans = (x * z1) / z2 97 | } else { 98 | var z1, z2 float64 99 | r := Sqrt(Ln2 - Log(1.0-x)) 100 | if r <= 5.0 { 101 | r -= 1.6 102 | z1 = ((((((c7*r+c6)*r+c5)*r+c4)*r+c3)*r+c2)*r+c1)*r + c0 103 | z2 = ((((((d7*r+d6)*r+d5)*r+d4)*r+d3)*r+d2)*r+d1)*r + d0 104 | } else { 105 | r -= 5.0 106 | z1 = ((((((e7*r+e6)*r+e5)*r+e4)*r+e3)*r+e2)*r+e1)*r + e0 107 | z2 = ((((((f7*r+f6)*r+f5)*r+f4)*r+f3)*r+f2)*r+f1)*r + f0 108 | } 109 | ans = z1 / z2 110 | } 111 | 112 | if sign { 113 | return -ans 114 | } 115 | return ans 116 | } 117 | 118 | // Erfcinv returns the inverse of Erfc(x). 119 | // 120 | // Special cases are: 121 | // Erfcinv(0) = +Inf 122 | // Erfcinv(2) = -Inf 123 | // Erfcinv(x) = NaN if x < 0 or x > 2 124 | // Erfcinv(NaN) = NaN 125 | func Erfcinv(x float64) float64 { 126 | return Erfinv(1 - x) 127 | } 128 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/floor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Floor returns the greatest integer value less than or equal to x. 8 | // 9 | // Special cases are: 10 | // Floor(±0) = ±0 11 | // Floor(±Inf) = ±Inf 12 | // Floor(NaN) = NaN 13 | func Floor(x float64) float64 { 14 | if x == 0 || IsNaN(x) || IsInf(x, 0) { 15 | return x 16 | } 17 | if x < 0 { 18 | d, fract := Modf(-x) 19 | if fract != 0.0 { 20 | d = d + 1 21 | } 22 | return -d 23 | } 24 | d, _ := Modf(x) 25 | return d 26 | } 27 | 28 | // Ceil returns the least integer value greater than or equal to x. 29 | // 30 | // Special cases are: 31 | // Ceil(±0) = ±0 32 | // Ceil(±Inf) = ±Inf 33 | // Ceil(NaN) = NaN 34 | func Ceil(x float64) float64 { 35 | return -Floor(-x) 36 | } 37 | 38 | // Trunc returns the integer value of x. 39 | // 40 | // Special cases are: 41 | // Trunc(±0) = ±0 42 | // Trunc(±Inf) = ±Inf 43 | // Trunc(NaN) = NaN 44 | func Trunc(x float64) float64 { 45 | if x == 0 || IsNaN(x) || IsInf(x, 0) { 46 | return x 47 | } 48 | d, _ := Modf(x) 49 | return d 50 | } 51 | 52 | // Round returns the nearest integer, rounding half away from zero. 53 | // 54 | // Special cases are: 55 | // Round(±0) = ±0 56 | // Round(±Inf) = ±Inf 57 | // Round(NaN) = NaN 58 | func Round(x float64) float64 { 59 | // Round is a faster implementation of: 60 | // 61 | // func Round(x float64) float64 { 62 | // t := Trunc(x) 63 | // if Abs(x-t) >= 0.5 { 64 | // return t + Copysign(1, x) 65 | // } 66 | // return t 67 | // } 68 | bits := Float64bits(x) 69 | e := uint(bits>>shift) & mask 70 | if e < bias { 71 | // Round abs(x) < 1 including denormals. 72 | bits &= signMask // +-0 73 | if e == bias-1 { 74 | bits |= uvone // +-1 75 | } 76 | } else if e < bias+shift { 77 | // Round any abs(x) >= 1 containing a fractional component [0,1). 78 | // 79 | // Numbers with larger exponents are returned unchanged since they 80 | // must be either an integer, infinity, or NaN. 81 | const half = 1 << (shift - 1) 82 | e -= bias 83 | bits += half >> e 84 | bits &^= fracMask >> e 85 | } 86 | return Float64frombits(bits) 87 | } 88 | 89 | // RoundToEven returns the nearest integer, rounding ties to even. 90 | // 91 | // Special cases are: 92 | // RoundToEven(±0) = ±0 93 | // RoundToEven(±Inf) = ±Inf 94 | // RoundToEven(NaN) = NaN 95 | func RoundToEven(x float64) float64 { 96 | // RoundToEven is a faster implementation of: 97 | // 98 | // func RoundToEven(x float64) float64 { 99 | // t := math.Trunc(x) 100 | // odd := math.Remainder(t, 2) != 0 101 | // if d := math.Abs(x - t); d > 0.5 || (d == 0.5 && odd) { 102 | // return t + math.Copysign(1, x) 103 | // } 104 | // return t 105 | // } 106 | bits := Float64bits(x) 107 | e := uint(bits>>shift) & mask 108 | if e >= bias { 109 | // Round abs(x) >= 1. 110 | // - Large numbers without fractional components, infinity, and NaN are unchanged. 111 | // - Add 0.499.. or 0.5 before truncating depending on whether the truncated 112 | // number is even or odd (respectively). 113 | const halfMinusULP = (1 << (shift - 1)) - 1 114 | e -= bias 115 | bits += (halfMinusULP + (bits>>(shift-e))&1) >> e 116 | bits &^= fracMask >> e 117 | } else if e == bias-1 && bits&fracMask != 0 { 118 | // Round 0.5 < abs(x) < 1. 119 | bits = bits&signMask | uvone // +-1 120 | } else { 121 | // Round abs(x) <= 0.5 including denormals. 122 | bits &= signMask // +-0 123 | } 124 | return Float64frombits(bits) 125 | } 126 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/frexp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Frexp breaks f into a normalized fraction 8 | // and an integral power of two. 9 | // It returns frac and exp satisfying f == frac × 2**exp, 10 | // with the absolute value of frac in the interval [½, 1). 11 | // 12 | // Special cases are: 13 | // Frexp(±0) = ±0, 0 14 | // Frexp(±Inf) = ±Inf, 0 15 | // Frexp(NaN) = NaN, 0 16 | func Frexp(f float64) (frac float64, exp int) { 17 | // special cases 18 | switch { 19 | case f == 0: 20 | return f, 0 // correctly return -0 21 | case IsInf(f, 0) || IsNaN(f): 22 | return f, 0 23 | } 24 | f, exp = normalize(f) 25 | x := Float64bits(f) 26 | exp += int((x>>shift)&mask) - bias + 1 27 | x &^= mask << shift 28 | x |= (-1 + bias) << shift 29 | frac = Float64frombits(x) 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/hypot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Hypot -- sqrt(p*p + q*q), but overflows only if the result does. 9 | */ 10 | 11 | // Hypot returns Sqrt(p*p + q*q), taking care to avoid 12 | // unnecessary overflow and underflow. 13 | // 14 | // Special cases are: 15 | // Hypot(±Inf, q) = +Inf 16 | // Hypot(p, ±Inf) = +Inf 17 | // Hypot(NaN, q) = NaN 18 | // Hypot(p, NaN) = NaN 19 | func Hypot(p, q float64) float64 { 20 | // special cases 21 | switch { 22 | case IsInf(p, 0) || IsInf(q, 0): 23 | return Inf(1) 24 | case IsNaN(p) || IsNaN(q): 25 | return NaN() 26 | } 27 | p, q = Abs(p), Abs(q) 28 | if p < q { 29 | p, q = q, p 30 | } 31 | if p == 0 { 32 | return 0 33 | } 34 | q = q / p 35 | return p * Sqrt(1+q*q) 36 | } 37 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/ldexp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Ldexp is the inverse of Frexp. 8 | // It returns frac × 2**exp. 9 | // 10 | // Special cases are: 11 | // Ldexp(±0, exp) = ±0 12 | // Ldexp(±Inf, exp) = ±Inf 13 | // Ldexp(NaN, exp) = NaN 14 | func Ldexp(frac float64, exp int) float64 { 15 | // special cases 16 | switch { 17 | case frac == 0: 18 | return frac // correctly return -0 19 | case IsInf(frac, 0) || IsNaN(frac): 20 | return frac 21 | } 22 | frac, e := normalize(frac) 23 | exp += e 24 | x := Float64bits(frac) 25 | exp += int(x>>shift)&mask - bias 26 | if exp < -1075 { 27 | return Copysign(0, frac) // underflow 28 | } 29 | if exp > 1023 { // overflow 30 | if frac < 0 { 31 | return Inf(-1) 32 | } 33 | return Inf(1) 34 | } 35 | var m float64 = 1 36 | if exp < -1022 { // denormal 37 | exp += 53 38 | m = 1.0 / (1 << 53) // 2**-53 39 | } 40 | x &^= mask << shift 41 | x |= uint64(exp+bias) << shift 42 | return m * Float64frombits(x) 43 | } 44 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/log.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Floating-point logarithm. 9 | */ 10 | 11 | // The original C code, the long comment, and the constants 12 | // below are from FreeBSD's /usr/src/lib/msun/src/e_log.c 13 | // and came with this notice. The go code is a simpler 14 | // version of the original C. 15 | // 16 | // ==================================================== 17 | // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 18 | // 19 | // Developed at SunPro, a Sun Microsystems, Inc. business. 20 | // Permission to use, copy, modify, and distribute this 21 | // software is freely granted, provided that this notice 22 | // is preserved. 23 | // ==================================================== 24 | // 25 | // __ieee754_log(x) 26 | // Return the logarithm of x 27 | // 28 | // Method : 29 | // 1. Argument Reduction: find k and f such that 30 | // x = 2**k * (1+f), 31 | // where sqrt(2)/2 < 1+f < sqrt(2) . 32 | // 33 | // 2. Approximation of log(1+f). 34 | // Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) 35 | // = 2s + 2/3 s**3 + 2/5 s**5 + ....., 36 | // = 2s + s*R 37 | // We use a special Reme algorithm on [0,0.1716] to generate 38 | // a polynomial of degree 14 to approximate R. The maximum error 39 | // of this polynomial approximation is bounded by 2**-58.45. In 40 | // other words, 41 | // 2 4 6 8 10 12 14 42 | // R(z) ~ L1*s +L2*s +L3*s +L4*s +L5*s +L6*s +L7*s 43 | // (the values of L1 to L7 are listed in the program) and 44 | // | 2 14 | -58.45 45 | // | L1*s +...+L7*s - R(z) | <= 2 46 | // | | 47 | // Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. 48 | // In order to guarantee error in log below 1ulp, we compute log by 49 | // log(1+f) = f - s*(f - R) (if f is not too large) 50 | // log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) 51 | // 52 | // 3. Finally, log(x) = k*Ln2 + log(1+f). 53 | // = k*Ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*Ln2_lo))) 54 | // Here Ln2 is split into two floating point number: 55 | // Ln2_hi + Ln2_lo, 56 | // where n*Ln2_hi is always exact for |n| < 2000. 57 | // 58 | // Special cases: 59 | // log(x) is NaN with signal if x < 0 (including -INF) ; 60 | // log(+INF) is +INF; log(0) is -INF with signal; 61 | // log(NaN) is that NaN with no signal. 62 | // 63 | // Accuracy: 64 | // according to an error analysis, the error is always less than 65 | // 1 ulp (unit in the last place). 66 | // 67 | // Constants: 68 | // The hexadecimal values are the intended ones for the following 69 | // constants. The decimal values may be used, provided that the 70 | // compiler will convert from decimal to binary accurately enough 71 | // to produce the hexadecimal values shown. 72 | 73 | // Log returns the natural logarithm of x. 74 | // 75 | // Special cases are: 76 | // Log(+Inf) = +Inf 77 | // Log(0) = -Inf 78 | // Log(x < 0) = NaN 79 | // Log(NaN) = NaN 80 | func Log(x float64) float64 { 81 | const ( 82 | Ln2Hi = 6.93147180369123816490e-01 /* 3fe62e42 fee00000 */ 83 | Ln2Lo = 1.90821492927058770002e-10 /* 3dea39ef 35793c76 */ 84 | L1 = 6.666666666666735130e-01 /* 3FE55555 55555593 */ 85 | L2 = 3.999999999940941908e-01 /* 3FD99999 9997FA04 */ 86 | L3 = 2.857142874366239149e-01 /* 3FD24924 94229359 */ 87 | L4 = 2.222219843214978396e-01 /* 3FCC71C5 1D8E78AF */ 88 | L5 = 1.818357216161805012e-01 /* 3FC74664 96CB03DE */ 89 | L6 = 1.531383769920937332e-01 /* 3FC39A09 D078C69F */ 90 | L7 = 1.479819860511658591e-01 /* 3FC2F112 DF3E5244 */ 91 | ) 92 | 93 | // special cases 94 | switch { 95 | case IsNaN(x) || IsInf(x, 1): 96 | return x 97 | case x < 0: 98 | return NaN() 99 | case x == 0: 100 | return Inf(-1) 101 | } 102 | 103 | // reduce 104 | f1, ki := Frexp(x) 105 | if f1 < Sqrt2/2 { 106 | f1 *= 2 107 | ki-- 108 | } 109 | f := f1 - 1 110 | k := float64(ki) 111 | 112 | // compute 113 | s := f / (2 + f) 114 | s2 := s * s 115 | s4 := s2 * s2 116 | t1 := s2 * (L1 + s4*(L3+s4*(L5+s4*L7))) 117 | t2 := s4 * (L2 + s4*(L4+s4*L6)) 118 | R := t1 + t2 119 | hfsq := 0.5 * f * f 120 | return k*Ln2Hi - ((hfsq - (s*(hfsq+R) + k*Ln2Lo)) - f) 121 | } 122 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/log10.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Log10 returns the decimal logarithm of x. 8 | // The special cases are the same as for Log. 9 | func Log10(x float64) float64 { 10 | return Log(x) * (1 / Ln10) 11 | } 12 | 13 | // Log2 returns the binary logarithm of x. 14 | // The special cases are the same as for Log. 15 | func Log2(x float64) float64 { 16 | frac, exp := Frexp(x) 17 | // Make sure exact powers of two give an exact answer. 18 | // Don't depend on Log(0.5)*(1/Ln2)+exp being exactly exp-1. 19 | if frac == 0.5 { 20 | return float64(exp - 1) 21 | } 22 | return Log(frac)*(1/Ln2) + float64(exp) 23 | } 24 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/logb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Logb returns the binary exponent of x. 8 | // 9 | // Special cases are: 10 | // Logb(±Inf) = +Inf 11 | // Logb(0) = -Inf 12 | // Logb(NaN) = NaN 13 | func Logb(x float64) float64 { 14 | // special cases 15 | switch { 16 | case x == 0: 17 | return Inf(-1) 18 | case IsInf(x, 0): 19 | return Inf(1) 20 | case IsNaN(x): 21 | return x 22 | } 23 | return float64(ilogb(x)) 24 | } 25 | 26 | // Ilogb returns the binary exponent of x as an integer. 27 | // 28 | // Special cases are: 29 | // Ilogb(±Inf) = MaxInt32 30 | // Ilogb(0) = MinInt32 31 | // Ilogb(NaN) = MaxInt32 32 | func Ilogb(x float64) int { 33 | // special cases 34 | switch { 35 | case x == 0: 36 | return MinInt32 37 | case IsNaN(x): 38 | return MaxInt32 39 | case IsInf(x, 0): 40 | return MaxInt32 41 | } 42 | return ilogb(x) 43 | } 44 | 45 | // logb returns the binary exponent of x. It assumes x is finite and 46 | // non-zero. 47 | func ilogb(x float64) int { 48 | x, exp := normalize(x) 49 | return int((Float64bits(x)>>shift)&mask) - bias + exp 50 | } 51 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/mod.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009-2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Floating-point mod function. 9 | */ 10 | 11 | // Mod returns the floating-point remainder of x/y. 12 | // The magnitude of the result is less than y and its 13 | // sign agrees with that of x. 14 | // 15 | // Special cases are: 16 | // Mod(±Inf, y) = NaN 17 | // Mod(NaN, y) = NaN 18 | // Mod(x, 0) = NaN 19 | // Mod(x, ±Inf) = x 20 | // Mod(x, NaN) = NaN 21 | func Mod(x, y float64) float64 { 22 | if y == 0 || IsInf(x, 0) || IsNaN(x) || IsNaN(y) { 23 | return NaN() 24 | } 25 | y = Abs(y) 26 | 27 | yfr, yexp := Frexp(y) 28 | r := x 29 | if x < 0 { 30 | r = -x 31 | } 32 | 33 | for r >= y { 34 | rfr, rexp := Frexp(r) 35 | if rfr < yfr { 36 | rexp = rexp - 1 37 | } 38 | r = r - Ldexp(y, rexp-yexp) 39 | } 40 | if x < 0 { 41 | r = -r 42 | } 43 | return r 44 | } 45 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/modf.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Modf returns integer and fractional floating-point numbers 8 | // that sum to f. Both values have the same sign as f. 9 | // 10 | // Special cases are: 11 | // Modf(±Inf) = ±Inf, NaN 12 | // Modf(NaN) = NaN, NaN 13 | func Modf(f float64) (int float64, frac float64) { 14 | if f < 1 { 15 | switch { 16 | case f < 0: 17 | int, frac = Modf(-f) 18 | return -int, -frac 19 | case f == 0: 20 | return f, f // Return -0, -0 when f == -0 21 | } 22 | return 0, f 23 | } 24 | 25 | x := Float64bits(f) 26 | e := uint(x>>shift)&mask - bias 27 | 28 | // Keep the top 12+e bits, the integer part; clear the rest. 29 | if e < 64-12 { 30 | x &^= 1<<(64-12-e) - 1 31 | } 32 | int = Float64frombits(x) 33 | frac = f - int 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/nextafter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Nextafter32 returns the next representable float32 value after x towards y. 8 | // 9 | // Special cases are: 10 | // Nextafter32(x, x) = x 11 | // Nextafter32(NaN, y) = NaN 12 | // Nextafter32(x, NaN) = NaN 13 | func Nextafter32(x, y float32) (r float32) { 14 | switch { 15 | case IsNaN(float64(x)) || IsNaN(float64(y)): // special case 16 | r = float32(NaN()) 17 | case x == y: 18 | r = x 19 | case x == 0: 20 | r = float32(Copysign(float64(Float32frombits(1)), float64(y))) 21 | case (y > x) == (x > 0): 22 | r = Float32frombits(Float32bits(x) + 1) 23 | default: 24 | r = Float32frombits(Float32bits(x) - 1) 25 | } 26 | return 27 | } 28 | 29 | // Nextafter returns the next representable float64 value after x towards y. 30 | // 31 | // Special cases are: 32 | // Nextafter(x, x) = x 33 | // Nextafter(NaN, y) = NaN 34 | // Nextafter(x, NaN) = NaN 35 | func Nextafter(x, y float64) (r float64) { 36 | switch { 37 | case IsNaN(x) || IsNaN(y): // special case 38 | r = NaN() 39 | case x == y: 40 | r = x 41 | case x == 0: 42 | r = Copysign(Float64frombits(1), y) 43 | case (y > x) == (x > 0): 44 | r = Float64frombits(Float64bits(x) + 1) 45 | default: 46 | r = Float64frombits(Float64bits(x) - 1) 47 | } 48 | return 49 | } 50 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/pow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | func isOddInt(x float64) bool { 8 | xi, xf := Modf(x) 9 | return xf == 0 && int64(xi)&1 == 1 10 | } 11 | 12 | // Special cases taken from FreeBSD's /usr/src/lib/msun/src/e_pow.c 13 | // updated by IEEE Std. 754-2008 "Section 9.2.1 Special values". 14 | 15 | // Pow returns x**y, the base-x exponential of y. 16 | // 17 | // Special cases are (in order): 18 | // Pow(x, ±0) = 1 for any x 19 | // Pow(1, y) = 1 for any y 20 | // Pow(x, 1) = x for any x 21 | // Pow(NaN, y) = NaN 22 | // Pow(x, NaN) = NaN 23 | // Pow(±0, y) = ±Inf for y an odd integer < 0 24 | // Pow(±0, -Inf) = +Inf 25 | // Pow(±0, +Inf) = +0 26 | // Pow(±0, y) = +Inf for finite y < 0 and not an odd integer 27 | // Pow(±0, y) = ±0 for y an odd integer > 0 28 | // Pow(±0, y) = +0 for finite y > 0 and not an odd integer 29 | // Pow(-1, ±Inf) = 1 30 | // Pow(x, +Inf) = +Inf for |x| > 1 31 | // Pow(x, -Inf) = +0 for |x| > 1 32 | // Pow(x, +Inf) = +0 for |x| < 1 33 | // Pow(x, -Inf) = +Inf for |x| < 1 34 | // Pow(+Inf, y) = +Inf for y > 0 35 | // Pow(+Inf, y) = +0 for y < 0 36 | // Pow(-Inf, y) = Pow(-0, -y) 37 | // Pow(x, y) = NaN for finite x < 0 and finite non-integer y 38 | func Pow(x, y float64) float64 { 39 | switch { 40 | case y == 0 || x == 1: 41 | return 1 42 | case y == 1: 43 | return x 44 | case IsNaN(x) || IsNaN(y): 45 | return NaN() 46 | case x == 0: 47 | switch { 48 | case y < 0: 49 | if isOddInt(y) { 50 | return Copysign(Inf(1), x) 51 | } 52 | return Inf(1) 53 | case y > 0: 54 | if isOddInt(y) { 55 | return x 56 | } 57 | return 0 58 | } 59 | case IsInf(y, 0): 60 | switch { 61 | case x == -1: 62 | return 1 63 | case (Abs(x) < 1) == IsInf(y, 1): 64 | return 0 65 | default: 66 | return Inf(1) 67 | } 68 | case IsInf(x, 0): 69 | if IsInf(x, -1) { 70 | return Pow(1/x, -y) // Pow(-0, -y) 71 | } 72 | switch { 73 | case y < 0: 74 | return 0 75 | case y > 0: 76 | return Inf(1) 77 | } 78 | case y == 0.5: 79 | return Sqrt(x) 80 | case y == -0.5: 81 | return 1 / Sqrt(x) 82 | } 83 | 84 | yi, yf := Modf(Abs(y)) 85 | if yf != 0 && x < 0 { 86 | return NaN() 87 | } 88 | if yi >= 1<<63 { 89 | // yi is a large even int that will lead to overflow (or underflow to 0) 90 | // for all x except -1 (x == 1 was handled earlier) 91 | switch { 92 | case x == -1: 93 | return 1 94 | case (Abs(x) < 1) == (y > 0): 95 | return 0 96 | default: 97 | return Inf(1) 98 | } 99 | } 100 | 101 | // ans = a1 * 2**ae (= 1 for now). 102 | a1 := 1.0 103 | ae := 0 104 | 105 | // ans *= x**yf 106 | if yf != 0 { 107 | if yf > 0.5 { 108 | yf-- 109 | yi++ 110 | } 111 | a1 = Exp(yf * Log(x)) 112 | } 113 | 114 | // ans *= x**yi 115 | // by multiplying in successive squarings 116 | // of x according to bits of yi. 117 | // accumulate powers of two into exp. 118 | x1, xe := Frexp(x) 119 | for i := int64(yi); i != 0; i >>= 1 { 120 | if xe < -1<<12 || 1<<12 < xe { 121 | // catch xe before it overflows the left shift below 122 | // Since i !=0 it has at least one bit still set, so ae will accumulate xe 123 | // on at least one more iteration, ae += xe is a lower bound on ae 124 | // the lower bound on ae exceeds the size of a float64 exp 125 | // so the final call to Ldexp will produce under/overflow (0/Inf) 126 | ae += xe 127 | break 128 | } 129 | if i&1 == 1 { 130 | a1 *= x1 131 | ae += xe 132 | } 133 | x1 *= x1 134 | xe <<= 1 135 | if x1 < .5 { 136 | x1 += x1 137 | xe-- 138 | } 139 | } 140 | 141 | // ans = a1*2**ae 142 | // if y < 0 { ans = 1 / ans } 143 | // but in the opposite order 144 | if y < 0 { 145 | a1 = 1 / a1 146 | ae = -ae 147 | } 148 | return Ldexp(a1, ae) 149 | } 150 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/pow10.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // pow10tab stores the pre-computed values 10**i for i < 32. 8 | var pow10tab = [...]float64{ 9 | 1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09, 10 | 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 11 | 1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 12 | 1e30, 1e31, 13 | } 14 | 15 | // pow10postab32 stores the pre-computed value for 10**(i*32) at index i. 16 | var pow10postab32 = [...]float64{ 17 | 1e00, 1e32, 1e64, 1e96, 1e128, 1e160, 1e192, 1e224, 1e256, 1e288, 18 | } 19 | 20 | // pow10negtab32 stores the pre-computed value for 10**(-i*32) at index i. 21 | var pow10negtab32 = [...]float64{ 22 | 1e-00, 1e-32, 1e-64, 1e-96, 1e-128, 1e-160, 1e-192, 1e-224, 1e-256, 1e-288, 1e-320, 23 | } 24 | 25 | // Pow10 returns 10**n, the base-10 exponential of n. 26 | // 27 | // Special cases are: 28 | // Pow10(n) = 0 for n < -323 29 | // Pow10(n) = +Inf for n > 308 30 | func Pow10(n int) float64 { 31 | if 0 <= n && n <= 308 { 32 | return pow10postab32[uint(n)/32] * pow10tab[uint(n)%32] 33 | } 34 | 35 | if -323 <= n && n <= 0 { 36 | return pow10negtab32[uint(-n)/32] / pow10tab[uint(-n)%32] 37 | } 38 | 39 | // n < -323 || 308 < n 40 | if n > 0 { 41 | return Inf(1) 42 | } 43 | 44 | // n < -323 45 | return 0 46 | } 47 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/rand/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/math/rand/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/rand/zipf.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // W.Hormann, G.Derflinger: 6 | // "Rejection-Inversion to Generate Variates 7 | // from Monotone Discrete Distributions" 8 | // http://eeyore.wu-wien.ac.at/papers/96-04-04.wh-der.ps.gz 9 | 10 | package rand 11 | 12 | import "math" 13 | 14 | // A Zipf generates Zipf distributed variates. 15 | type Zipf struct { 16 | r *Rand 17 | imax float64 18 | v float64 19 | q float64 20 | s float64 21 | oneminusQ float64 22 | oneminusQinv float64 23 | hxm float64 24 | hx0minusHxm float64 25 | } 26 | 27 | func (z *Zipf) h(x float64) float64 { 28 | return math.Exp(z.oneminusQ*math.Log(z.v+x)) * z.oneminusQinv 29 | } 30 | 31 | func (z *Zipf) hinv(x float64) float64 { 32 | return math.Exp(z.oneminusQinv*math.Log(z.oneminusQ*x)) - z.v 33 | } 34 | 35 | // NewZipf returns a Zipf variate generator. 36 | // The generator generates values k ∈ [0, imax] 37 | // such that P(k) is proportional to (v + k) ** (-s). 38 | // Requirements: s > 1 and v >= 1. 39 | func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf { 40 | z := new(Zipf) 41 | if s <= 1.0 || v < 1 { 42 | return nil 43 | } 44 | z.r = r 45 | z.imax = float64(imax) 46 | z.v = v 47 | z.q = s 48 | z.oneminusQ = 1.0 - z.q 49 | z.oneminusQinv = 1.0 / z.oneminusQ 50 | z.hxm = z.h(z.imax + 0.5) 51 | z.hx0minusHxm = z.h(0.5) - math.Exp(math.Log(z.v)*(-z.q)) - z.hxm 52 | z.s = 1 - z.hinv(z.h(1.5)-math.Exp(-z.q*math.Log(z.v+1.0))) 53 | return z 54 | } 55 | 56 | // Uint64 returns a value drawn from the Zipf distribution described 57 | // by the Zipf object. 58 | func (z *Zipf) Uint64() uint64 { 59 | if z == nil { 60 | panic("rand: nil Zipf") 61 | } 62 | k := 0.0 63 | 64 | for { 65 | r := z.r.Float64() // r on [0,1] 66 | ur := z.hxm + r*z.hx0minusHxm 67 | x := z.hinv(ur) 68 | k = math.Floor(x + 0.5) 69 | if k-x <= z.s { 70 | break 71 | } 72 | if ur >= z.h(k+0.5)-math.Exp(-math.Log(k+z.v)*z.q) { 73 | break 74 | } 75 | } 76 | return uint64(k) 77 | } 78 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/remainder.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // The original C code and the comment below are from 8 | // FreeBSD's /usr/src/lib/msun/src/e_remainder.c and came 9 | // with this notice. The go code is a simplified version of 10 | // the original C. 11 | // 12 | // ==================================================== 13 | // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 14 | // 15 | // Developed at SunPro, a Sun Microsystems, Inc. business. 16 | // Permission to use, copy, modify, and distribute this 17 | // software is freely granted, provided that this notice 18 | // is preserved. 19 | // ==================================================== 20 | // 21 | // __ieee754_remainder(x,y) 22 | // Return : 23 | // returns x REM y = x - [x/y]*y as if in infinite 24 | // precision arithmetic, where [x/y] is the (infinite bit) 25 | // integer nearest x/y (in half way cases, choose the even one). 26 | // Method : 27 | // Based on Mod() returning x - [x/y]chopped * y exactly. 28 | 29 | // Remainder returns the IEEE 754 floating-point remainder of x/y. 30 | // 31 | // Special cases are: 32 | // Remainder(±Inf, y) = NaN 33 | // Remainder(NaN, y) = NaN 34 | // Remainder(x, 0) = NaN 35 | // Remainder(x, ±Inf) = x 36 | // Remainder(x, NaN) = NaN 37 | func Remainder(x, y float64) float64 { 38 | const ( 39 | Tiny = 4.45014771701440276618e-308 // 0x0020000000000000 40 | HalfMax = MaxFloat64 / 2 41 | ) 42 | // special cases 43 | switch { 44 | case IsNaN(x) || IsNaN(y) || IsInf(x, 0) || y == 0: 45 | return NaN() 46 | case IsInf(y, 0): 47 | return x 48 | } 49 | sign := false 50 | if x < 0 { 51 | x = -x 52 | sign = true 53 | } 54 | if y < 0 { 55 | y = -y 56 | } 57 | if x == y { 58 | return 0 59 | } 60 | if y <= HalfMax { 61 | x = Mod(x, y+y) // now x < 2y 62 | } 63 | if y < Tiny { 64 | if x+x > y { 65 | x -= y 66 | if x+x >= y { 67 | x -= y 68 | } 69 | } 70 | } else { 71 | yHalf := 0.5 * y 72 | if x > yHalf { 73 | x -= y 74 | if x >= yHalf { 75 | x -= y 76 | } 77 | } 78 | } 79 | if sign { 80 | x = -x 81 | } 82 | return x 83 | } 84 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/signbit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Signbit reports whether x is negative or negative zero. 8 | func Signbit(x float64) bool { 9 | return Float64bits(x)&(1<<63) != 0 10 | } 11 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/sincos.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // Coefficients _sin[] and _cos[] are found in pkg/math/sin.go. 8 | 9 | // Sincos returns Sin(x), Cos(x). 10 | // 11 | // Special cases are: 12 | // Sincos(±0) = ±0, 1 13 | // Sincos(±Inf) = NaN, NaN 14 | // Sincos(NaN) = NaN, NaN 15 | func Sincos(x float64) (sin, cos float64) { 16 | const ( 17 | PI4A = 7.85398125648498535156E-1 // 0x3fe921fb40000000, Pi/4 split into three parts 18 | PI4B = 3.77489470793079817668E-8 // 0x3e64442d00000000, 19 | PI4C = 2.69515142907905952645E-15 // 0x3ce8469898cc5170, 20 | ) 21 | // special cases 22 | switch { 23 | case x == 0: 24 | return x, 1 // return ±0.0, 1.0 25 | case IsNaN(x) || IsInf(x, 0): 26 | return NaN(), NaN() 27 | } 28 | 29 | // make argument positive 30 | sinSign, cosSign := false, false 31 | if x < 0 { 32 | x = -x 33 | sinSign = true 34 | } 35 | 36 | var j uint64 37 | var y, z float64 38 | if x >= reduceThreshold { 39 | j, z = trigReduce(x) 40 | } else { 41 | j = uint64(x * (4 / Pi)) // integer part of x/(Pi/4), as integer for tests on the phase angle 42 | y = float64(j) // integer part of x/(Pi/4), as float 43 | 44 | if j&1 == 1 { // map zeros to origin 45 | j++ 46 | y++ 47 | } 48 | j &= 7 // octant modulo 2Pi radians (360 degrees) 49 | z = ((x - y*PI4A) - y*PI4B) - y*PI4C // Extended precision modular arithmetic 50 | } 51 | if j > 3 { // reflect in x axis 52 | j -= 4 53 | sinSign, cosSign = !sinSign, !cosSign 54 | } 55 | if j > 1 { 56 | cosSign = !cosSign 57 | } 58 | 59 | zz := z * z 60 | cos = 1.0 - 0.5*zz + zz*zz*((((((_cos[0]*zz)+_cos[1])*zz+_cos[2])*zz+_cos[3])*zz+_cos[4])*zz+_cos[5]) 61 | sin = z + z*zz*((((((_sin[0]*zz)+_sin[1])*zz+_sin[2])*zz+_sin[3])*zz+_sin[4])*zz+_sin[5]) 62 | if j == 1 || j == 2 { 63 | sin, cos = cos, sin 64 | } 65 | if cosSign { 66 | cos = -cos 67 | } 68 | if sinSign { 69 | sin = -sin 70 | } 71 | return 72 | } 73 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/sinh.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Floating-point hyperbolic sine and cosine. 9 | 10 | The exponential func is called for arguments 11 | greater in magnitude than 0.5. 12 | 13 | A series is used for arguments smaller in magnitude than 0.5. 14 | 15 | Cosh(x) is computed from the exponential func for 16 | all arguments. 17 | */ 18 | 19 | // Sinh returns the hyperbolic sine of x. 20 | // 21 | // Special cases are: 22 | // Sinh(±0) = ±0 23 | // Sinh(±Inf) = ±Inf 24 | // Sinh(NaN) = NaN 25 | func Sinh(x float64) float64 { 26 | // The coefficients are #2029 from Hart & Cheney. (20.36D) 27 | const ( 28 | P0 = -0.6307673640497716991184787251e+6 29 | P1 = -0.8991272022039509355398013511e+5 30 | P2 = -0.2894211355989563807284660366e+4 31 | P3 = -0.2630563213397497062819489e+2 32 | Q0 = -0.6307673640497716991212077277e+6 33 | Q1 = 0.1521517378790019070696485176e+5 34 | Q2 = -0.173678953558233699533450911e+3 35 | ) 36 | 37 | sign := false 38 | if x < 0 { 39 | x = -x 40 | sign = true 41 | } 42 | 43 | var temp float64 44 | switch { 45 | case x > 21: 46 | temp = Exp(x) * 0.5 47 | 48 | case x > 0.5: 49 | ex := Exp(x) 50 | temp = (ex - 1/ex) * 0.5 51 | 52 | default: 53 | sq := x * x 54 | temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x 55 | temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0) 56 | } 57 | 58 | if sign { 59 | temp = -temp 60 | } 61 | return temp 62 | } 63 | 64 | // Cosh returns the hyperbolic cosine of x. 65 | // 66 | // Special cases are: 67 | // Cosh(±0) = 1 68 | // Cosh(±Inf) = +Inf 69 | // Cosh(NaN) = NaN 70 | func Cosh(x float64) float64 71 | 72 | func cosh(x float64) float64 { 73 | x = Abs(x) 74 | if x > 21 { 75 | return Exp(x) * 0.5 76 | } 77 | ex := Exp(x) 78 | return (ex + 1/ex) * 0.5 79 | } 80 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/tan.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | /* 8 | Floating-point tangent. 9 | */ 10 | 11 | // The original C code, the long comment, and the constants 12 | // below were from http://netlib.sandia.gov/cephes/cmath/sin.c, 13 | // available from http://www.netlib.org/cephes/cmath.tgz. 14 | // The go code is a simplified version of the original C. 15 | // 16 | // tan.c 17 | // 18 | // Circular tangent 19 | // 20 | // SYNOPSIS: 21 | // 22 | // double x, y, tan(); 23 | // y = tan( x ); 24 | // 25 | // DESCRIPTION: 26 | // 27 | // Returns the circular tangent of the radian argument x. 28 | // 29 | // Range reduction is modulo pi/4. A rational function 30 | // x + x**3 P(x**2)/Q(x**2) 31 | // is employed in the basic interval [0, pi/4]. 32 | // 33 | // ACCURACY: 34 | // Relative error: 35 | // arithmetic domain # trials peak rms 36 | // DEC +-1.07e9 44000 4.1e-17 1.0e-17 37 | // IEEE +-1.07e9 30000 2.9e-16 8.1e-17 38 | // 39 | // Partial loss of accuracy begins to occur at x = 2**30 = 1.074e9. The loss 40 | // is not gradual, but jumps suddenly to about 1 part in 10e7. Results may 41 | // be meaningless for x > 2**49 = 5.6e14. 42 | // [Accuracy loss statement from sin.go comments.] 43 | // 44 | // Cephes Math Library Release 2.8: June, 2000 45 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 46 | // 47 | // The readme file at http://netlib.sandia.gov/cephes/ says: 48 | // Some software in this archive may be from the book _Methods and 49 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 50 | // International, 1989) or from the Cephes Mathematical Library, a 51 | // commercial product. In either event, it is copyrighted by the author. 52 | // What you see here may be used freely but it comes with no support or 53 | // guarantee. 54 | // 55 | // The two known misprints in the book are repaired here in the 56 | // source listings for the gamma function and the incomplete beta 57 | // integral. 58 | // 59 | // Stephen L. Moshier 60 | // moshier@na-net.ornl.gov 61 | 62 | // tan coefficients 63 | var _tanP = [...]float64{ 64 | -1.30936939181383777646e4, // 0xc0c992d8d24f3f38 65 | 1.15351664838587416140e6, // 0x413199eca5fc9ddd 66 | -1.79565251976484877988e7, // 0xc1711fead3299176 67 | } 68 | var _tanQ = [...]float64{ 69 | 1.00000000000000000000e0, 70 | 1.36812963470692954678e4, //0x40cab8a5eeb36572 71 | -1.32089234440210967447e6, //0xc13427bc582abc96 72 | 2.50083801823357915839e7, //0x4177d98fc2ead8ef 73 | -5.38695755929454629881e7, //0xc189afe03cbe5a31 74 | } 75 | 76 | // Tan returns the tangent of the radian argument x. 77 | // 78 | // Special cases are: 79 | // Tan(±0) = ±0 80 | // Tan(±Inf) = NaN 81 | // Tan(NaN) = NaN 82 | func Tan(x float64) float64 { 83 | const ( 84 | PI4A = 7.85398125648498535156e-1 // 0x3fe921fb40000000, Pi/4 split into three parts 85 | PI4B = 3.77489470793079817668e-8 // 0x3e64442d00000000, 86 | PI4C = 2.69515142907905952645e-15 // 0x3ce8469898cc5170, 87 | ) 88 | // special cases 89 | switch { 90 | case x == 0 || IsNaN(x): 91 | return x // return ±0 || NaN() 92 | case IsInf(x, 0): 93 | return NaN() 94 | } 95 | 96 | // make argument positive but save the sign 97 | sign := false 98 | if x < 0 { 99 | x = -x 100 | sign = true 101 | } 102 | var j uint64 103 | var y, z float64 104 | if x >= reduceThreshold { 105 | j, z = trigReduce(x) 106 | } else { 107 | j = uint64(x * (4 / Pi)) // integer part of x/(Pi/4), as integer for tests on the phase angle 108 | y = float64(j) // integer part of x/(Pi/4), as float 109 | 110 | /* map zeros and singularities to origin */ 111 | if j&1 == 1 { 112 | j++ 113 | y++ 114 | } 115 | 116 | z = ((x - y*PI4A) - y*PI4B) - y*PI4C 117 | } 118 | zz := z * z 119 | 120 | if zz > 1e-14 { 121 | y = z + z*(zz*(((_tanP[0]*zz)+_tanP[1])*zz+_tanP[2])/((((zz+_tanQ[1])*zz+_tanQ[2])*zz+_tanQ[3])*zz+_tanQ[4])) 122 | } else { 123 | y = z 124 | } 125 | if j&2 == 2 { 126 | y = -1 / y 127 | } 128 | if sign { 129 | y = -y 130 | } 131 | return y 132 | } 133 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/tanh.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | // The original C code, the long comment, and the constants 8 | // below were from http://netlib.sandia.gov/cephes/cmath/sin.c, 9 | // available from http://www.netlib.org/cephes/cmath.tgz. 10 | // The go code is a simplified version of the original C. 11 | // tanh.c 12 | // 13 | // Hyperbolic tangent 14 | // 15 | // SYNOPSIS: 16 | // 17 | // double x, y, tanh(); 18 | // 19 | // y = tanh( x ); 20 | // 21 | // DESCRIPTION: 22 | // 23 | // Returns hyperbolic tangent of argument in the range MINLOG to MAXLOG. 24 | // MAXLOG = 8.8029691931113054295988e+01 = log(2**127) 25 | // MINLOG = -8.872283911167299960540e+01 = log(2**-128) 26 | // 27 | // A rational function is used for |x| < 0.625. The form 28 | // x + x**3 P(x)/Q(x) of Cody & Waite is employed. 29 | // Otherwise, 30 | // tanh(x) = sinh(x)/cosh(x) = 1 - 2/(exp(2x) + 1). 31 | // 32 | // ACCURACY: 33 | // 34 | // Relative error: 35 | // arithmetic domain # trials peak rms 36 | // IEEE -2,2 30000 2.5e-16 5.8e-17 37 | // 38 | // Cephes Math Library Release 2.8: June, 2000 39 | // Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier 40 | // 41 | // The readme file at http://netlib.sandia.gov/cephes/ says: 42 | // Some software in this archive may be from the book _Methods and 43 | // Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster 44 | // International, 1989) or from the Cephes Mathematical Library, a 45 | // commercial product. In either event, it is copyrighted by the author. 46 | // What you see here may be used freely but it comes with no support or 47 | // guarantee. 48 | // 49 | // The two known misprints in the book are repaired here in the 50 | // source listings for the gamma function and the incomplete beta 51 | // integral. 52 | // 53 | // Stephen L. Moshier 54 | // moshier@na-net.ornl.gov 55 | // 56 | 57 | var tanhP = [...]float64{ 58 | -9.64399179425052238628e-1, 59 | -9.92877231001918586564e1, 60 | -1.61468768441708447952e3, 61 | } 62 | var tanhQ = [...]float64{ 63 | 1.12811678491632931402e2, 64 | 2.23548839060100448583e3, 65 | 4.84406305325125486048e3, 66 | } 67 | 68 | // Tanh returns the hyperbolic tangent of x. 69 | // 70 | // Special cases are: 71 | // Tanh(±0) = ±0 72 | // Tanh(±Inf) = ±1 73 | // Tanh(NaN) = NaN 74 | func Tanh(x float64) float64 { 75 | const MAXLOG = 8.8029691931113054295988e+01 // log(2**127) 76 | z := Abs(x) 77 | switch { 78 | case z > 0.5*MAXLOG: 79 | if x < 0 { 80 | return -1 81 | } 82 | return 1 83 | case z >= 0.625: 84 | s := Exp(2 * z) 85 | z = 1 - 2/(s+1) 86 | if x < 0 { 87 | z = -z 88 | } 89 | default: 90 | if x == 0 { 91 | return x 92 | } 93 | s := x * x 94 | z = x + x*s*((tanhP[0]*s+tanhP[1])*s+tanhP[2])/(((s+tanhQ[0])*s+tanhQ[1])*s+tanhQ[2]) 95 | } 96 | return z 97 | } 98 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/trig_reduce.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package math 6 | 7 | import ( 8 | "math/bits" 9 | ) 10 | 11 | // reduceThreshold is the maximum value where the reduction using Pi/4 12 | // in 3 float64 parts still gives accurate results. Above this 13 | // threshold Payne-Hanek range reduction must be used. 14 | const reduceThreshold = (1 << 52) / (4 / Pi) 15 | 16 | // trigReduce implements Payne-Hanek range reduction by Pi/4 17 | // for x > 0. It returns the integer part mod 8 (j) and 18 | // the fractional part (z) of x / (Pi/4). 19 | // The implementation is based on: 20 | // "ARGUMENT REDUCTION FOR HUGE ARGUMENTS: Good to the Last Bit" 21 | // K. C. Ng et al, March 24, 1992 22 | // The simulated multi-precision calculation of x*B uses 64-bit integer arithmetic. 23 | func trigReduce(x float64) (j uint64, z float64) { 24 | const PI4 = Pi / 4 25 | if x < PI4 { 26 | return 0, x 27 | } 28 | // Extract out the integer and exponent such that, 29 | // x = ix * 2 ** exp. 30 | ix := Float64bits(x) 31 | exp := int(ix>>shift&mask) - bias - shift 32 | ix &^= mask << shift 33 | ix |= 1 << shift 34 | // Use the exponent to extract the 3 appropriate uint64 digits from mPi4, 35 | // B ~ (z0, z1, z2), such that the product leading digit has the exponent -61. 36 | // Note, exp >= -53 since x >= PI4 and exp < 971 for maximum float64. 37 | digit, bitshift := uint(exp+61)/64, uint(exp+61)%64 38 | z0 := (mPi4[digit] << bitshift) | (mPi4[digit+1] >> (64 - bitshift)) 39 | z1 := (mPi4[digit+1] << bitshift) | (mPi4[digit+2] >> (64 - bitshift)) 40 | z2 := (mPi4[digit+2] << bitshift) | (mPi4[digit+3] >> (64 - bitshift)) 41 | // Multiply mantissa by the digits and extract the upper two digits (hi, lo). 42 | z2hi, _ := bits.Mul64(z2, ix) 43 | z1hi, z1lo := bits.Mul64(z1, ix) 44 | z0lo := z0 * ix 45 | lo, c := bits.Add64(z1lo, z2hi, 0) 46 | hi, _ := bits.Add64(z0lo, z1hi, c) 47 | // The top 3 bits are j. 48 | j = hi >> 61 49 | // Extract the fraction and find its magnitude. 50 | hi = hi<<3 | lo>>61 51 | lz := uint(bits.LeadingZeros64(hi)) 52 | e := uint64(bias - (lz + 1)) 53 | // Clear implicit mantissa bit and shift into place. 54 | hi = (hi << (lz + 1)) | (lo >> (64 - (lz + 1))) 55 | hi >>= 64 - shift 56 | // Include the exponent and convert to a float. 57 | hi |= e << shift 58 | z = Float64frombits(hi) 59 | // Map zeros to origin. 60 | if j&1 == 1 { 61 | j++ 62 | j &= 7 63 | z-- 64 | } 65 | // Multiply the fractional part by pi/4. 66 | return j, z * PI4 67 | } 68 | 69 | // mPi4 is the binary digits of 4/pi as a uint64 array, 70 | // that is, 4/pi = Sum mPi4[i]*2^(-64*i) 71 | // 19 64-bit digits and the leading one bit give 1217 bits 72 | // of precision to handle the largest possible float64 exponent. 73 | var mPi4 = [...]uint64{ 74 | 0x0000000000000001, 75 | 0x45f306dc9c882a53, 76 | 0xf84eafa3ea69bb81, 77 | 0xb6c52b3278872083, 78 | 0xfca2c757bd778ac3, 79 | 0x6e48dc74849ba5c0, 80 | 0x0c925dd413a32439, 81 | 0xfc3bd63962534e7d, 82 | 0xd1046bea5d768909, 83 | 0xd338e04d68befc82, 84 | 0x7323ac7306a673e9, 85 | 0x3908bf177bf25076, 86 | 0x3ff12fffbc0b301f, 87 | 0xde5e2316b414da3e, 88 | 0xda6cfd9e4f96136e, 89 | 0x9e8c7ecd3cbfd45a, 90 | 0xea4f758fd7cbe2f6, 91 | 0x7a0e73ef14a525d4, 92 | 0xd7f6bf623f1aba10, 93 | 0xac06608df8f6d757, 94 | } 95 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/math/unsafe.go: -------------------------------------------------------------------------------- 1 | // This code is adapted from the offical Go code written in Go 2 | // with license as follows: 3 | // 4 | // Copyright 2009 The Go Authors. All rights reserved. 5 | // Use of this source code is governed by a BSD-style 6 | // license that can be found in the LICENSE file. 7 | 8 | package math 9 | 10 | /* This is the offical version: 11 | import "unsafe" 12 | 13 | // Float32bits returns the IEEE 754 binary representation of f, 14 | // with the sign bit of f and the result in the same bit position. 15 | // Float32bits(Float32frombits(x)) == x. 16 | func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) } 17 | 18 | // Float32frombits returns the floating-point number corresponding 19 | // to the IEEE 754 binary representation b, with the sign bit of b 20 | // and the result in the same bit position. 21 | // Float32frombits(Float32bits(x)) == x. 22 | func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) } 23 | 24 | // Float64bits returns the IEEE 754 binary representation of f, 25 | // with the sign bit of f and the result in the same bit position, 26 | // and Float64bits(Float64frombits(x)) == x. 27 | func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) } 28 | 29 | // Float64frombits returns the floating-point number corresponding 30 | // to the IEEE 754 binary representation b, with the sign bit of b 31 | // and the result in the same bit position. 32 | // Float64frombits(Float64bits(x)) == x. 33 | func Float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) } 34 | */ 35 | 36 | var native ffiBits 37 | 38 | func init() { 39 | native = ffi(ffiBits, "bits") 40 | } 41 | 42 | type ffiBits interface { 43 | f32_to_bits(f float32) uint32 44 | f32_from_bits(b uint32) float32 45 | f64_to_bits(f float64) uint64 46 | f64_from_bits(b uint64) float64 47 | } 48 | 49 | // Float32bits returns the IEEE 754 binary representation of f, 50 | // with the sign bit of f and the result in the same bit position. 51 | // Float32bits(Float32frombits(x)) == x. 52 | func Float32bits(f float32) uint32 { 53 | return native.f32_to_bits(f) 54 | } 55 | 56 | // Float32frombits returns the floating-point number corresponding 57 | // to the IEEE 754 binary representation b, with the sign bit of b 58 | // and the result in the same bit position. 59 | // Float32frombits(Float32bits(x)) == x. 60 | func Float32frombits(b uint32) float32 { 61 | return native.f32_from_bits(b) 62 | } 63 | 64 | // Float64bits returns the IEEE 754 binary representation of f, 65 | // with the sign bit of f and the result in the same bit position, 66 | // and Float64bits(Float64frombits(x)) == x. 67 | func Float64bits(f float64) uint64 { 68 | return native.f64_to_bits(f) 69 | } 70 | 71 | // Float64frombits returns the floating-point number corresponding 72 | // to the IEEE 754 binary representation b, with the sign bit of b 73 | // and the result in the same bit position. 74 | // Float64frombits(Float64bits(x)) == x. 75 | func Float64frombits(b uint64) float64 { 76 | return native.f64_from_bits(b) 77 | } 78 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/os/file.gos: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Goscript Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | 6 | package os 7 | 8 | import "unsafe" 9 | import "errors" 10 | 11 | var fileIface ffiFile 12 | 13 | type ffiFile interface { 14 | get_std_io(which int) unsafe.Pointer 15 | open(name string, flags int) (p unsafe.Pointer, errKind int, err string) 16 | read(f unsafe.Pointer, b []byte) (n int, errKind int, err string) 17 | write(f unsafe.Pointer, b []byte) (n int, errKind int, err string) 18 | seek(f unsafe.Pointer, offset int64, whence int) (ret int64, errKind int, err string) 19 | } 20 | 21 | var Stdin *File 22 | var Stdout *File 23 | var Stderr *File 24 | 25 | func init() { 26 | fileIface = ffi(ffiFile, "os.file") 27 | 28 | Stdin = &File{fileIface.get_std_io(0), "Stdin"} 29 | Stdout = &File{fileIface.get_std_io(1), "Stdout"} 30 | Stderr = &File{fileIface.get_std_io(2), "Stderr"} 31 | } 32 | 33 | // Flags to OpenFile 34 | const ( 35 | // Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified. 36 | O_RDONLY int = 0x00000 // open the file read-only. 37 | O_WRONLY int = 0x00001 // open the file write-only. 38 | O_RDWR int = 0x00002 // open the file read-write. 39 | // The remaining values may be or'ed in to control behavior. 40 | O_APPEND int = 0x00400 // append data to the file when writing. 41 | O_CREATE int = 0x00040 // create a new file if none exists. 42 | O_EXCL int = 0x00080 // used with O_CREATE, file must not exist. 43 | //O_SYNC int = syscall.O_SYNC // open for synchronous I/O. 44 | O_TRUNC int = 0x00200 // truncate regular writable file when opened. 45 | ) 46 | 47 | type File struct{ 48 | ptr unsafe.Pointer 49 | name string 50 | } 51 | 52 | func Open(name string) (*File, error) { 53 | p, _, msg := fileIface.open(name, O_RDONLY) 54 | if msg != "" { 55 | return nil, errors.New(msg) 56 | } else { 57 | return &File{ptr: p, name: name}, nil 58 | } 59 | } 60 | 61 | func (f *File) Read(b []byte) (n int, err error) { 62 | n, _, msg := fileIface.read(f.ptr, b) 63 | if msg != "" { 64 | return n, errors.New(msg) 65 | } else { 66 | return n, nil 67 | } 68 | } 69 | 70 | func (f *File) Write(b []byte) (n int, err error) { 71 | n, _, msg := fileIface.write(f.ptr, b) 72 | if msg != "" { 73 | return n, errors.New(msg) 74 | } else { 75 | return n, nil 76 | } 77 | } 78 | 79 | func (f *File) Seek(offset int64, whence int) (ret int64, err error) { 80 | n, _, msg := fileIface.seek(f.ptr, offset, whence) 81 | if msg != "" { 82 | return n, errors.New(msg) 83 | } else { 84 | return n, nil 85 | } 86 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/path/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/path/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/path/filepath/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/path/filepath/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/reflect/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/reflect/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/reflect/deepequal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Deep equality test via reflection 6 | 7 | package reflect 8 | 9 | func DeepEqual(x, y interface{}) bool { 10 | panic("not implemented") 11 | } 12 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/reflect/makefunc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // MakeFunc implementation. 6 | 7 | package reflect 8 | 9 | func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value { 10 | panic("not implemented") 11 | } 12 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/reflect/swapper.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package reflect 6 | 7 | // Swapper returns a function that swaps the elements in the provided 8 | // slice. 9 | // 10 | // Swapper panics if the provided interface is not a slice. 11 | func Swapper(slice interface{}) func(i, j int) { 12 | return func(i, j int) { 13 | native.swap(slice, i, j) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/runtime/runtime.gos: -------------------------------------------------------------------------------- 1 | package runtime 2 | 3 | var GOOS string -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sort/search.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This file implements binary search. 6 | 7 | package sort 8 | 9 | // Search uses binary search to find and return the smallest index i 10 | // in [0, n) at which f(i) is true, assuming that on the range [0, n), 11 | // f(i) == true implies f(i+1) == true. That is, Search requires that 12 | // f is false for some (possibly empty) prefix of the input range [0, n) 13 | // and then true for the (possibly empty) remainder; Search returns 14 | // the first true index. If there is no such index, Search returns n. 15 | // (Note that the "not found" return value is not -1 as in, for instance, 16 | // strings.Index.) 17 | // Search calls f(i) only for i in the range [0, n). 18 | // 19 | // A common use of Search is to find the index i for a value x in 20 | // a sorted, indexable data structure such as an array or slice. 21 | // In this case, the argument f, typically a closure, captures the value 22 | // to be searched for, and how the data structure is indexed and 23 | // ordered. 24 | // 25 | // For instance, given a slice data sorted in ascending order, 26 | // the call Search(len(data), func(i int) bool { return data[i] >= 23 }) 27 | // returns the smallest index i such that data[i] >= 23. If the caller 28 | // wants to find whether 23 is in the slice, it must test data[i] == 23 29 | // separately. 30 | // 31 | // Searching data sorted in descending order would use the <= 32 | // operator instead of the >= operator. 33 | // 34 | // To complete the example above, the following code tries to find the value 35 | // x in an integer slice data sorted in ascending order: 36 | // 37 | // x := 23 38 | // i := sort.Search(len(data), func(i int) bool { return data[i] >= x }) 39 | // if i < len(data) && data[i] == x { 40 | // // x is present at data[i] 41 | // } else { 42 | // // x is not present in data, 43 | // // but i is the index where it would be inserted. 44 | // } 45 | // 46 | // As a more whimsical example, this program guesses your number: 47 | // 48 | // func GuessingGame() { 49 | // var s string 50 | // fmt.Printf("Pick an integer from 0 to 100.\n") 51 | // answer := sort.Search(100, func(i int) bool { 52 | // fmt.Printf("Is your number <= %d? ", i) 53 | // fmt.Scanf("%s", &s) 54 | // return s != "" && s[0] == 'y' 55 | // }) 56 | // fmt.Printf("Your number is %d.\n", answer) 57 | // } 58 | // 59 | func Search(n int, f func(int) bool) int { 60 | // Define f(-1) == false and f(n) == true. 61 | // Invariant: f(i-1) == false, f(j) == true. 62 | i, j := 0, n 63 | for i < j { 64 | h := int(uint(i+j) >> 1) // avoid overflow when computing h 65 | // i ≤ h < j 66 | if !f(h) { 67 | i = h + 1 // preserves f(i-1) == false 68 | } else { 69 | j = h // preserves f(j) == true 70 | } 71 | } 72 | // i == j, f(i-1) == false, and f(j) (= f(i)) == true => answer is i. 73 | return i 74 | } 75 | 76 | // Convenience wrappers for common cases. 77 | 78 | // SearchInts searches for x in a sorted slice of ints and returns the index 79 | // as specified by Search. The return value is the index to insert x if x is 80 | // not present (it could be len(a)). 81 | // The slice must be sorted in ascending order. 82 | // 83 | func SearchInts(a []int, x int) int { 84 | return Search(len(a), func(i int) bool { return a[i] >= x }) 85 | } 86 | 87 | // SearchFloat64s searches for x in a sorted slice of float64s and returns the index 88 | // as specified by Search. The return value is the index to insert x if x is not 89 | // present (it could be len(a)). 90 | // The slice must be sorted in ascending order. 91 | // 92 | func SearchFloat64s(a []float64, x float64) int { 93 | return Search(len(a), func(i int) bool { return a[i] >= x }) 94 | } 95 | 96 | // SearchStrings searches for x in a sorted slice of strings and returns the index 97 | // as specified by Search. The return value is the index to insert x if x is not 98 | // present (it could be len(a)). 99 | // The slice must be sorted in ascending order. 100 | // 101 | func SearchStrings(a []string, x string) int { 102 | return Search(len(a), func(i int) bool { return a[i] >= x }) 103 | } 104 | 105 | // Search returns the result of applying SearchInts to the receiver and x. 106 | func (p IntSlice) Search(x int) int { return SearchInts(p, x) } 107 | 108 | // Search returns the result of applying SearchFloat64s to the receiver and x. 109 | func (p Float64Slice) Search(x float64) int { return SearchFloat64s(p, x) } 110 | 111 | // Search returns the result of applying SearchStrings to the receiver and x. 112 | func (p StringSlice) Search(x string) int { return SearchStrings(p, x) } 113 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sort/slice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !compiler_bootstrap go1.8 6 | 7 | package sort 8 | 9 | import "reflect" 10 | 11 | // Slice sorts the provided slice given the provided less function. 12 | // 13 | // The sort is not guaranteed to be stable. For a stable sort, use 14 | // SliceStable. 15 | // 16 | // The function panics if the provided interface is not a slice. 17 | func Slice(slice interface{}, less func(i, j int) bool) { 18 | rv := reflect.ValueOf(slice) 19 | swap := reflect.Swapper(slice) 20 | length := rv.Len() 21 | quickSort_func(lessSwap{less, swap}, 0, length, maxDepth(length)) 22 | } 23 | 24 | // SliceStable sorts the provided slice given the provided less 25 | // function while keeping the original order of equal elements. 26 | // 27 | // The function panics if the provided interface is not a slice. 28 | func SliceStable(slice interface{}, less func(i, j int) bool) { 29 | rv := reflect.ValueOf(slice) 30 | swap := reflect.Swapper(slice) 31 | stable_func(lessSwap{less, swap}, rv.Len()) 32 | } 33 | 34 | // SliceIsSorted tests whether a slice is sorted. 35 | // 36 | // The function panics if the provided interface is not a slice. 37 | func SliceIsSorted(slice interface{}, less func(i, j int) bool) bool { 38 | rv := reflect.ValueOf(slice) 39 | n := rv.Len() 40 | for i := n - 1; i > 0; i-- { 41 | if less(i, i-1) { 42 | return false 43 | } 44 | } 45 | return true 46 | } 47 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strconv/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/strconv/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strconv/atob.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package strconv 6 | 7 | // ParseBool returns the boolean value represented by the string. 8 | // It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. 9 | // Any other value returns an error. 10 | func ParseBool(str string) (bool, error) { 11 | switch str { 12 | case "1", "t", "T", "true", "TRUE", "True": 13 | return true, nil 14 | case "0", "f", "F", "false", "FALSE", "False": 15 | return false, nil 16 | } 17 | return false, syntaxError("ParseBool", str) 18 | } 19 | 20 | // FormatBool returns "true" or "false" according to the value of b. 21 | func FormatBool(b bool) string { 22 | if b { 23 | return "true" 24 | } 25 | return "false" 26 | } 27 | 28 | // AppendBool appends "true" or "false", according to the value of b, 29 | // to dst and returns the extended buffer. 30 | func AppendBool(dst []byte, b bool) []byte { 31 | if b { 32 | return append(dst, "true"...) 33 | } 34 | return append(dst, "false"...) 35 | } 36 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strconv/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package strconv implements conversions to and from string representations 6 | // of basic data types. 7 | // 8 | // Numeric Conversions 9 | // 10 | // The most common numeric conversions are Atoi (string to int) and Itoa (int to string). 11 | // 12 | // i, err := strconv.Atoi("-42") 13 | // s := strconv.Itoa(-42) 14 | // 15 | // These assume decimal and the Go int type. 16 | // 17 | // ParseBool, ParseFloat, ParseInt, and ParseUint convert strings to values: 18 | // 19 | // b, err := strconv.ParseBool("true") 20 | // f, err := strconv.ParseFloat("3.1415", 64) 21 | // i, err := strconv.ParseInt("-42", 10, 64) 22 | // u, err := strconv.ParseUint("42", 10, 64) 23 | // 24 | // The parse functions return the widest type (float64, int64, and uint64), 25 | // but if the size argument specifies a narrower width the result can be 26 | // converted to that narrower type without data loss: 27 | // 28 | // s := "2147483647" // biggest int32 29 | // i64, err := strconv.ParseInt(s, 10, 32) 30 | // ... 31 | // i := int32(i64) 32 | // 33 | // FormatBool, FormatFloat, FormatInt, and FormatUint convert values to strings: 34 | // 35 | // s := strconv.FormatBool(true) 36 | // s := strconv.FormatFloat(3.1415, 'E', -1, 64) 37 | // s := strconv.FormatInt(-42, 16) 38 | // s := strconv.FormatUint(42, 16) 39 | // 40 | // AppendBool, AppendFloat, AppendInt, and AppendUint are similar but 41 | // append the formatted value to a destination slice. 42 | // 43 | // String Conversions 44 | // 45 | // Quote and QuoteToASCII convert strings to quoted Go string literals. 46 | // The latter guarantees that the result is an ASCII string, by escaping 47 | // any non-ASCII Unicode with \u: 48 | // 49 | // q := strconv.Quote("Hello, 世界") 50 | // q := strconv.QuoteToASCII("Hello, 世界") 51 | // 52 | // QuoteRune and QuoteRuneToASCII are similar but accept runes and 53 | // return quoted Go rune literals. 54 | // 55 | // Unquote and UnquoteChar unquote Go string and rune literals. 56 | // 57 | package strconv 58 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strings/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/strings/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strings/builder.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package strings 6 | 7 | import ( 8 | "unicode/utf8" 9 | "unsafe" 10 | ) 11 | 12 | // A Builder is used to efficiently build a string using Write methods. 13 | // It minimizes memory copying. The zero value is ready to use. 14 | // Do not copy a non-zero Builder. 15 | type Builder struct { 16 | addr *Builder // of receiver, to detect copies by value 17 | buf []byte 18 | } 19 | 20 | func (b *Builder) copyCheck() { 21 | if b.addr == nil { 22 | b.addr = b 23 | } else if b.addr != b { 24 | panic("strings: illegal use of non-zero Builder copied by value") 25 | } 26 | } 27 | 28 | // String returns the accumulated string. 29 | func (b *Builder) String() string { 30 | return *(*string)(unsafe.Pointer(&b.buf)) 31 | } 32 | 33 | // Len returns the number of accumulated bytes; b.Len() == len(b.String()). 34 | func (b *Builder) Len() int { return len(b.buf) } 35 | 36 | // Cap returns the capacity of the builder's underlying byte slice. It is the 37 | // total space allocated for the string being built and includes any bytes 38 | // already written. 39 | func (b *Builder) Cap() int { return cap(b.buf) } 40 | 41 | // Reset resets the Builder to be empty. 42 | func (b *Builder) Reset() { 43 | b.addr = nil 44 | b.buf = nil 45 | } 46 | 47 | // grow copies the buffer to a new, larger buffer so that there are at least n 48 | // bytes of capacity beyond len(b.buf). 49 | func (b *Builder) grow(n int) { 50 | buf := make([]byte, len(b.buf), 2*cap(b.buf)+n) 51 | copy(buf, b.buf) 52 | b.buf = buf 53 | } 54 | 55 | // Grow grows b's capacity, if necessary, to guarantee space for 56 | // another n bytes. After Grow(n), at least n bytes can be written to b 57 | // without another allocation. If n is negative, Grow panics. 58 | func (b *Builder) Grow(n int) { 59 | b.copyCheck() 60 | if n < 0 { 61 | panic("strings.Builder.Grow: negative count") 62 | } 63 | if cap(b.buf)-len(b.buf) < n { 64 | b.grow(n) 65 | } 66 | } 67 | 68 | // Write appends the contents of p to b's buffer. 69 | // Write always returns len(p), nil. 70 | func (b *Builder) Write(p []byte) (int, error) { 71 | b.copyCheck() 72 | b.buf = append(b.buf, p...) 73 | return len(p), nil 74 | } 75 | 76 | // WriteByte appends the byte c to b's buffer. 77 | // The returned error is always nil. 78 | func (b *Builder) WriteByte(c byte) error { 79 | b.copyCheck() 80 | b.buf = append(b.buf, c) 81 | return nil 82 | } 83 | 84 | // WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. 85 | // It returns the length of r and a nil error. 86 | func (b *Builder) WriteRune(r rune) (int, error) { 87 | b.copyCheck() 88 | if r < utf8.RuneSelf { 89 | b.buf = append(b.buf, byte(r)) 90 | return 1, nil 91 | } 92 | l := len(b.buf) 93 | if cap(b.buf)-l < utf8.UTFMax { 94 | b.grow(utf8.UTFMax) 95 | } 96 | n := utf8.EncodeRune(b.buf[l:l+utf8.UTFMax], r) 97 | b.buf = b.buf[:l+n] 98 | return n, nil 99 | } 100 | 101 | // WriteString appends the contents of s to b's buffer. 102 | // It returns the length of s and a nil error. 103 | func (b *Builder) WriteString(s string) (int, error) { 104 | b.copyCheck() 105 | b.buf = append(b.buf, s...) 106 | return len(s), nil 107 | } 108 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strings/compare.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package strings 6 | 7 | // Compare returns an integer comparing two strings lexicographically. 8 | // The result will be 0 if a==b, -1 if a < b, and +1 if a > b. 9 | // 10 | // Compare is included only for symmetry with package bytes. 11 | // It is usually clearer and always faster to use the built-in 12 | // string comparison operators ==, <, >, and so on. 13 | func Compare(a, b string) int { 14 | // NOTE(rsc): This function does NOT call the runtime cmpstring function, 15 | // because we do not want to provide any performance justification for 16 | // using strings.Compare. Basically no one should use strings.Compare. 17 | // As the comment above says, it is here only for symmetry with package bytes. 18 | // If performance is important, the compiler should be changed to recognize 19 | // the pattern so that all code doing three-way comparisons, not just code 20 | // using strings.Compare, can benefit. 21 | if a == b { 22 | return 0 23 | } 24 | if a < b { 25 | return -1 26 | } 27 | return +1 28 | } 29 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/strings/reader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package strings 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "unicode/utf8" 11 | ) 12 | 13 | // A Reader implements the io.Reader, io.ReaderAt, io.Seeker, io.WriterTo, 14 | // io.ByteScanner, and io.RuneScanner interfaces by reading 15 | // from a string. 16 | // The zero value for Reader operates like a Reader of an empty string. 17 | type Reader struct { 18 | s string 19 | i int64 // current reading index 20 | prevRune int // index of previous rune; or < 0 21 | } 22 | 23 | // Len returns the number of bytes of the unread portion of the 24 | // string. 25 | func (r *Reader) Len() int { 26 | if r.i >= int64(len(r.s)) { 27 | return 0 28 | } 29 | return int(int64(len(r.s)) - r.i) 30 | } 31 | 32 | // Size returns the original length of the underlying string. 33 | // Size is the number of bytes available for reading via ReadAt. 34 | // The returned value is always the same and is not affected by calls 35 | // to any other method. 36 | func (r *Reader) Size() int64 { return int64(len(r.s)) } 37 | 38 | func (r *Reader) Read(b []byte) (n int, err error) { 39 | if r.i >= int64(len(r.s)) { 40 | return 0, io.EOF 41 | } 42 | r.prevRune = -1 43 | n = copy(b, r.s[r.i:]) 44 | r.i += int64(n) 45 | return 46 | } 47 | 48 | func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) { 49 | // cannot modify state - see io.ReaderAt 50 | if off < 0 { 51 | return 0, errors.New("strings.Reader.ReadAt: negative offset") 52 | } 53 | if off >= int64(len(r.s)) { 54 | return 0, io.EOF 55 | } 56 | n = copy(b, r.s[off:]) 57 | if n < len(b) { 58 | err = io.EOF 59 | } 60 | return 61 | } 62 | 63 | func (r *Reader) ReadByte() (byte, error) { 64 | r.prevRune = -1 65 | if r.i >= int64(len(r.s)) { 66 | return 0, io.EOF 67 | } 68 | b := r.s[r.i] 69 | r.i++ 70 | return b, nil 71 | } 72 | 73 | func (r *Reader) UnreadByte() error { 74 | if r.i <= 0 { 75 | return errors.New("strings.Reader.UnreadByte: at beginning of string") 76 | } 77 | r.prevRune = -1 78 | r.i-- 79 | return nil 80 | } 81 | 82 | func (r *Reader) ReadRune() (ch rune, size int, err error) { 83 | if r.i >= int64(len(r.s)) { 84 | r.prevRune = -1 85 | return 0, 0, io.EOF 86 | } 87 | r.prevRune = int(r.i) 88 | if c := r.s[r.i]; c < utf8.RuneSelf { 89 | r.i++ 90 | return rune(c), 1, nil 91 | } 92 | ch, size = utf8.DecodeRuneInString(r.s[r.i:]) 93 | r.i += int64(size) 94 | return 95 | } 96 | 97 | func (r *Reader) UnreadRune() error { 98 | if r.i <= 0 { 99 | return errors.New("strings.Reader.UnreadRune: at beginning of string") 100 | } 101 | if r.prevRune < 0 { 102 | return errors.New("strings.Reader.UnreadRune: previous operation was not ReadRune") 103 | } 104 | r.i = int64(r.prevRune) 105 | r.prevRune = -1 106 | return nil 107 | } 108 | 109 | // Seek implements the io.Seeker interface. 110 | func (r *Reader) Seek(offset int64, whence int) (int64, error) { 111 | r.prevRune = -1 112 | var abs int64 113 | switch whence { 114 | case io.SeekStart: 115 | abs = offset 116 | case io.SeekCurrent: 117 | abs = r.i + offset 118 | case io.SeekEnd: 119 | abs = int64(len(r.s)) + offset 120 | default: 121 | return 0, errors.New("strings.Reader.Seek: invalid whence") 122 | } 123 | if abs < 0 { 124 | return 0, errors.New("strings.Reader.Seek: negative position") 125 | } 126 | r.i = abs 127 | return abs, nil 128 | } 129 | 130 | // WriteTo implements the io.WriterTo interface. 131 | func (r *Reader) WriteTo(w io.Writer) (n int64, err error) { 132 | r.prevRune = -1 133 | if r.i >= int64(len(r.s)) { 134 | return 0, nil 135 | } 136 | s := r.s[r.i:] 137 | m, err := io.WriteString(w, s) 138 | if m > len(s) { 139 | panic("strings.Reader.WriteTo: invalid WriteString count") 140 | } 141 | r.i += int64(m) 142 | n = int64(m) 143 | if m != len(s) && err == nil { 144 | err = io.ErrShortWrite 145 | } 146 | return 147 | } 148 | 149 | // Reset resets the Reader to be reading from s. 150 | func (r *Reader) Reset(s string) { *r = Reader{s, 0, -1} } 151 | 152 | // NewReader returns a new Reader reading from s. 153 | // It is similar to bytes.NewBufferString but more efficient and read-only. 154 | func NewReader(s string) *Reader { return &Reader{s, 0, -1} } 155 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sync/atomic/value.gos: -------------------------------------------------------------------------------- 1 | package atomic 2 | 3 | // Load and Store are innately atomic in Goscript 4 | type Value struct { 5 | val interface{} 6 | } 7 | 8 | func (v *Value) Load() interface{} { 9 | return v.val 10 | } 11 | 12 | func (v *Value) Store(val interface{}) { 13 | v.val = val 14 | } 15 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sync/map.gos: -------------------------------------------------------------------------------- 1 | package sync 2 | 3 | // Map operations in Goscript are innately atomic 4 | 5 | type Map struct { 6 | data map[interface{}]interface{} 7 | } 8 | 9 | // Load returns the value stored in the map for a key, or nil if no 10 | // value is present. 11 | // The ok result indicates whether value was found in the map. 12 | func (m *Map) Load(key interface{}) (value interface{}, ok bool) { 13 | v, ok := m.getData()[key] 14 | return v, ok 15 | } 16 | 17 | // Store sets the value for a key. 18 | func (m *Map) Store(key, value interface{}) { 19 | m.getData()[key] = value 20 | } 21 | 22 | // LoadOrStore returns the existing value for the key if present. 23 | // Otherwise, it stores and returns the given value. 24 | // The loaded result is true if the value was loaded, false if stored. 25 | func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) { 26 | if e, ok := m.getData()[key]; ok { 27 | return e, true 28 | } 29 | 30 | var mu Mutex 31 | mu.Lock() 32 | defer mu.Unlock() 33 | if e, ok := m.data[key]; ok { 34 | return e, true 35 | } else { 36 | m.data[key] = value 37 | return value, false 38 | } 39 | } 40 | 41 | // Delete deletes the value for a key. 42 | func (m *Map) Delete(key interface{}) { 43 | delete(m.getData(), key) 44 | } 45 | 46 | // Range calls f sequentially for each key and value present in the map. 47 | // If f returns false, range stops the iteration. 48 | // 49 | // Range does not necessarily correspond to any consistent snapshot of the Map's 50 | // contents: no key will be visited more than once, but if the value for any key 51 | // is stored or deleted concurrently, Range may reflect any mapping for that key 52 | // from any point during the Range call. 53 | // 54 | // Range may be O(N) with the number of elements in the map even if f returns 55 | // false after a constant number of calls. 56 | func (m *Map) Range(f func(key, value interface{}) bool) { 57 | panic("not implemented") 58 | } 59 | 60 | func (m *Map) getData() map[interface{}]interface{} { 61 | var l Mutex 62 | l.Lock() 63 | defer l.Unlock() 64 | if m.data == nil { 65 | m.data = make(map[interface{}]interface{}) 66 | } 67 | return m.data 68 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sync/once.gos: -------------------------------------------------------------------------------- 1 | // Adapted from Go. 2 | 3 | // Copyright 2009 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package sync 8 | 9 | // Once is an object that will perform exactly one action. 10 | type Once struct { 11 | m Mutex 12 | done bool 13 | } 14 | 15 | // Do calls the function f if and only if Do is being called for the 16 | // first time for this instance of Once. In other words, given 17 | // var once Once 18 | // if once.Do(f) is called multiple times, only the first call will invoke f, 19 | // even if f has a different value in each invocation. A new instance of 20 | // Once is required for each function to execute. 21 | // 22 | // Do is intended for initialization that must be run exactly once. Since f 23 | // is niladic, it may be necessary to use a function literal to capture the 24 | // arguments to a function to be invoked by Do: 25 | // config.once.Do(func() { config.init(filename) }) 26 | // 27 | // Because no call to Do returns until the one call to f returns, if f causes 28 | // Do to be called, it will deadlock. 29 | // 30 | // If f panics, Do considers it to have returned; future calls of Do return 31 | // without calling f. 32 | // 33 | func (o *Once) Do(f func()) { 34 | if o.done { 35 | return 36 | } 37 | // Slow-path. 38 | o.m.Lock() 39 | defer o.m.Unlock() 40 | if !o.done { 41 | defer func () { 42 | o.done = true 43 | }() 44 | f() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sync/pool.gos: -------------------------------------------------------------------------------- 1 | package sync 2 | 3 | type Pool struct { 4 | shared []interface{} 5 | lock RWMutex 6 | // New optionally specifies a function to generate 7 | // a value when Get would otherwise return nil. 8 | // It may not be changed concurrently with calls to Get. 9 | New func() interface{} 10 | } 11 | 12 | func (p *Pool) Put(x interface{}) { 13 | p.lock.Lock() 14 | p.shared = append(p.shared, x) 15 | p.lock.Unlock() 16 | } 17 | 18 | 19 | func (p *Pool) Get() interface{} { 20 | p.lock.RLock() 21 | defer p.lock.RUnlock() 22 | l := len(p.shared) 23 | var x interface{} 24 | if l > 0 { 25 | x = p.shared[l-1] 26 | p.shared = p.shared[:l-1] 27 | } else if p.New != nil { 28 | x = p.New() 29 | } 30 | return x 31 | } 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/sync/sync.gos: -------------------------------------------------------------------------------- 1 | package sync 2 | 3 | import "unsafe" 4 | 5 | var nativeMutex ffiMutex 6 | var nativeRWMutex ffiRWMutex 7 | 8 | func init() { 9 | nativeMutex = ffi(ffiMutex, "sync.mutex") 10 | nativeRWMutex = ffi(ffiRWMutex, "sync.rw_mutex") 11 | } 12 | 13 | type ffiMutex interface { 14 | async_lock(*unsafe.Pointer) 15 | async_unlock(unsafe.Pointer) 16 | } 17 | 18 | type ffiRWMutex interface { 19 | async_r_lock(*unsafe.Pointer) 20 | async_r_unlock(unsafe.Pointer) 21 | async_w_lock(*unsafe.Pointer) 22 | async_w_unlock(unsafe.Pointer) 23 | } 24 | 25 | // A Locker represents an object that can be locked and unlocked. 26 | type Locker interface { 27 | Lock() 28 | Unlock() 29 | } 30 | 31 | // A Mutex is a mutual exclusion lock. 32 | // The zero value for a Mutex is an unlocked mutex. 33 | // 34 | // A Mutex must not be copied after first use. 35 | type Mutex struct { 36 | handle unsafe.Pointer 37 | } 38 | 39 | // Lock locks m. 40 | // If the lock is already in use, the calling goroutine 41 | // blocks until the mutex is available. 42 | func (m *Mutex) Lock() { 43 | nativeMutex.async_lock(&m.handle) 44 | } 45 | 46 | 47 | // Unlock unlocks m. 48 | // It is a run-time error if m is not locked on entry to Unlock. 49 | // 50 | // A locked Mutex is not associated with a particular goroutine. 51 | // It is allowed for one goroutine to lock a Mutex and then 52 | // arrange for another goroutine to unlock it. 53 | func (m *Mutex) Unlock() { 54 | nativeMutex.async_unlock(m.handle) 55 | } 56 | 57 | 58 | // A RWMutex is a reader/writer mutual exclusion lock. 59 | // The lock can be held by an arbitrary number of readers or a single writer. 60 | // The zero value for a RWMutex is an unlocked mutex. 61 | // 62 | // A RWMutex must not be copied after first use. 63 | type RWMutex struct { 64 | handle unsafe.Pointer 65 | } 66 | 67 | func (rw *RWMutex) RLock() { 68 | nativeRWMutex.async_r_lock(&rw.handle) 69 | } 70 | 71 | func (rw *RWMutex) RUnlock() { 72 | nativeRWMutex.async_r_unlock(rw.handle) 73 | } 74 | 75 | func (rw *RWMutex) Lock() { 76 | nativeRWMutex.async_w_lock(&rw.handle) 77 | } 78 | 79 | func (rw *RWMutex) Unlock() { 80 | nativeRWMutex.async_w_unlock(rw.handle) 81 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/syscall/syscall.gos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/syscall/syscall.gos -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/time/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/time/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/time/tick.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package time 6 | 7 | import "errors" 8 | 9 | // A Ticker holds a channel that delivers `ticks' of a clock 10 | // at intervals. 11 | type Ticker struct { 12 | C <-chan Time // The channel on which the ticks are delivered. 13 | r runtimeTimer 14 | } 15 | 16 | // NewTicker returns a new Ticker containing a channel that will send the 17 | // time with a period specified by the duration argument. 18 | // It adjusts the intervals or drops ticks to make up for slow receivers. 19 | // The duration d must be greater than zero; if not, NewTicker will panic. 20 | // Stop the ticker to release associated resources. 21 | func NewTicker(d Duration) *Ticker { 22 | if d <= 0 { 23 | panic(errors.New("non-positive interval for NewTicker")) 24 | } 25 | // Give the channel a 1-element time buffer. 26 | // If the client falls behind while reading, we drop ticks 27 | // on the floor until the client catches up. 28 | c := make(chan Time, 1) 29 | t := &Ticker{ 30 | C: c, 31 | r: runtimeTimer{ 32 | when: when(d), 33 | period: int64(d), 34 | f: sendTime, 35 | arg: c, 36 | }, 37 | } 38 | startTimer(&t.r) 39 | return t 40 | } 41 | 42 | // Stop turns off a ticker. After Stop, no more ticks will be sent. 43 | // Stop does not close the channel, to prevent a concurrent goroutine 44 | // reading from the channel from seeing an erroneous "tick". 45 | func (t *Ticker) Stop() { 46 | stopTimer(&t.r) 47 | } 48 | 49 | // Tick is a convenience wrapper for NewTicker providing access to the ticking 50 | // channel only. While Tick is useful for clients that have no need to shut down 51 | // the Ticker, be aware that without a way to shut it down the underlying 52 | // Ticker cannot be recovered by the garbage collector; it "leaks". 53 | // Unlike NewTicker, Tick will return nil if d <= 0. 54 | func Tick(d Duration) <-chan Time { 55 | if d <= 0 { 56 | return nil 57 | } 58 | return NewTicker(d).C 59 | } 60 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/unicode/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/unicode/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/unicode/casetables.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // TODO: This file contains the special casing rules for Turkish and Azeri only. 6 | // It should encompass all the languages with special casing rules 7 | // and be generated automatically, but that requires some API 8 | // development first. 9 | 10 | package unicode 11 | 12 | var TurkishCase SpecialCase = _TurkishCase 13 | var _TurkishCase = SpecialCase{ 14 | CaseRange{0x0049, 0x0049, d{0, 0x131 - 0x49, 0}}, 15 | CaseRange{0x0069, 0x0069, d{0x130 - 0x69, 0, 0x130 - 0x69}}, 16 | CaseRange{0x0130, 0x0130, d{0, 0x69 - 0x130, 0}}, 17 | CaseRange{0x0131, 0x0131, d{0x49 - 0x131, 0, 0x49 - 0x131}}, 18 | } 19 | 20 | var AzeriCase SpecialCase = _TurkishCase 21 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/unicode/digit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unicode 6 | 7 | // IsDigit reports whether the rune is a decimal digit. 8 | func IsDigit(r rune) bool { 9 | if r <= MaxLatin1 { 10 | return '0' <= r && r <= '9' 11 | } 12 | return isExcludingLatin(Digit, r) 13 | } 14 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/unicode/utf16/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/unicode/utf16/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/unicode/utf16/utf16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package utf16 implements encoding and decoding of UTF-16 sequences. 6 | package utf16 7 | 8 | // The conditions replacementChar==unicode.ReplacementChar and 9 | // maxRune==unicode.MaxRune are verified in the tests. 10 | // Defining them locally avoids this package depending on package unicode. 11 | 12 | const ( 13 | replacementChar = '\uFFFD' // Unicode replacement character 14 | maxRune = '\U0010FFFF' // Maximum valid Unicode code point. 15 | ) 16 | 17 | const ( 18 | // 0xd800-0xdc00 encodes the high 10 bits of a pair. 19 | // 0xdc00-0xe000 encodes the low 10 bits of a pair. 20 | // the value is those 20 bits plus 0x10000. 21 | surr1 = 0xd800 22 | surr2 = 0xdc00 23 | surr3 = 0xe000 24 | 25 | surrSelf = 0x10000 26 | ) 27 | 28 | // IsSurrogate reports whether the specified Unicode code point 29 | // can appear in a surrogate pair. 30 | func IsSurrogate(r rune) bool { 31 | return surr1 <= r && r < surr3 32 | } 33 | 34 | // DecodeRune returns the UTF-16 decoding of a surrogate pair. 35 | // If the pair is not a valid UTF-16 surrogate pair, DecodeRune returns 36 | // the Unicode replacement code point U+FFFD. 37 | func DecodeRune(r1, r2 rune) rune { 38 | if surr1 <= r1 && r1 < surr2 && surr2 <= r2 && r2 < surr3 { 39 | return (r1-surr1)<<10 | (r2 - surr2) + surrSelf 40 | } 41 | return replacementChar 42 | } 43 | 44 | // EncodeRune returns the UTF-16 surrogate pair r1, r2 for the given rune. 45 | // If the rune is not a valid Unicode code point or does not need encoding, 46 | // EncodeRune returns U+FFFD, U+FFFD. 47 | func EncodeRune(r rune) (r1, r2 rune) { 48 | if r < surrSelf || r > maxRune { 49 | return replacementChar, replacementChar 50 | } 51 | r -= surrSelf 52 | return surr1 + (r>>10)&0x3ff, surr2 + r&0x3ff 53 | } 54 | 55 | // Encode returns the UTF-16 encoding of the Unicode code point sequence s. 56 | func Encode(s []rune) []uint16 { 57 | n := len(s) 58 | for _, v := range s { 59 | if v >= surrSelf { 60 | n++ 61 | } 62 | } 63 | 64 | a := make([]uint16, n) 65 | n = 0 66 | for _, v := range s { 67 | switch { 68 | case 0 <= v && v < surr1, surr3 <= v && v < surrSelf: 69 | // normal rune 70 | a[n] = uint16(v) 71 | n++ 72 | case surrSelf <= v && v <= maxRune: 73 | // needs surrogate sequence 74 | r1, r2 := EncodeRune(v) 75 | a[n] = uint16(r1) 76 | a[n+1] = uint16(r2) 77 | n += 2 78 | default: 79 | a[n] = uint16(replacementChar) 80 | n++ 81 | } 82 | } 83 | return a[:n] 84 | } 85 | 86 | // Decode returns the Unicode code point sequence represented 87 | // by the UTF-16 encoding s. 88 | func Decode(s []uint16) []rune { 89 | a := make([]rune, len(s)) 90 | n := 0 91 | for i := 0; i < len(s); i++ { 92 | switch r := s[i]; { 93 | case r < surr1, surr3 <= r: 94 | // normal rune 95 | a[n] = rune(r) 96 | case surr1 <= r && r < surr2 && i+1 < len(s) && 97 | surr2 <= s[i+1] && s[i+1] < surr3: 98 | // valid surrogate sequence 99 | a[n] = DecodeRune(rune(r), rune(s[i+1])) 100 | i++ 101 | default: 102 | // invalid surrogate sequence 103 | a[n] = replacementChar 104 | } 105 | n++ 106 | } 107 | return a[:n] 108 | } 109 | -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/unicode/utf8/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/crates/zflow_runtime/go/std/unicode/utf8/.DS_Store -------------------------------------------------------------------------------- /crates/zflow_runtime/go/std/zflow/process.gos: -------------------------------------------------------------------------------- 1 | package zflow 2 | 3 | import "unsafe" 4 | 5 | type ffiZflow interface { 6 | send(a interface{}) 7 | send_done(a interface{}) 8 | inputs() unsafe.Pointer 9 | } 10 | 11 | var datatype ffiZflowData 12 | 13 | type ffiZflowData interface { 14 | is_nil(unsafe.Pointer) bool 15 | i64(unsafe.Pointer) (int64, bool) 16 | u64(unsafe.Pointer) (uint64, bool) 17 | f64(unsafe.Pointer) (float64, bool) 18 | str(unsafe.Pointer) (string, bool) 19 | boolean(unsafe.Pointer) bool 20 | object(unsafe.Pointer) (map[string]unsafe.Pointer, bool) 21 | array(unsafe.Pointer) ([]unsafe.Pointer, bool) 22 | } 23 | 24 | func init() { 25 | datatype = ffi(ffiZflowData, "zflow.data") 26 | } 27 | 28 | type Data struct { 29 | internal unsafe.Pointer 30 | } 31 | 32 | func Get(d unsafe.Pointer) *Data { 33 | return &Data{ 34 | internal: d, 35 | } 36 | } 37 | 38 | func (d *Data) IsNil() bool { 39 | return datatype.is_nil(d.internal) 40 | } 41 | 42 | func (d *Data) I64() (int64, bool) { 43 | return datatype.i64(d.internal) 44 | } 45 | func (d *Data) U64() (uint64, bool) { 46 | return datatype.u64(d.internal) 47 | } 48 | func (d *Data) F64() (float64, bool) { 49 | return datatype.f64(d.internal) 50 | } 51 | func (d *Data) Bool() bool { 52 | return datatype.boolean(d.internal) 53 | } 54 | func (d *Data) String() (string, bool) { 55 | return datatype.str(d.internal) 56 | } 57 | func (d *Data) Map() (map[string]*Data, bool) { 58 | m, ok := datatype.object(d.internal) 59 | if !ok { 60 | return nil, false 61 | } 62 | res := map[string]*Data{} 63 | for key, element := range m { 64 | res[key] = Get(element) 65 | } 66 | return res, true 67 | } 68 | func (d *Data) Array() ([]*Data, bool) { 69 | a, ok := datatype.array(d.internal) 70 | if !ok { 71 | return nil, false 72 | } 73 | res := []*Data{} 74 | for i, e := range a { 75 | res[i] = Get(e) 76 | } 77 | return res, true 78 | } 79 | 80 | func Send(v interface{}) { 81 | var f = ffi(ffiZflow, "zflow.process") 82 | f.send(v) 83 | } 84 | 85 | func SendDone(v interface{}) { 86 | var f = ffi(ffiZflow, "zflow.process") 87 | f.send_done(v) 88 | } 89 | 90 | func Inputs() *Data { 91 | var f = ffi(ffiZflow, "zflow.process") 92 | inputs := Get(f.inputs()) 93 | return inputs 94 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/ip.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | use serde_json::Value; 3 | 4 | 5 | 6 | #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Default)] 7 | pub enum IPType { 8 | OpenBracket(Value), 9 | CloseBracket(Value), 10 | Data(Value), 11 | Buffer(Vec), 12 | All(Value), 13 | #[default] 14 | Unknown, 15 | } 16 | 17 | #[derive(Default, Clone, Debug, Serialize, Deserialize)] 18 | pub struct IPOptions { 19 | pub schema: String, 20 | pub scope: String, 21 | pub initial: bool, 22 | pub clonable: bool, 23 | pub userdata: Value, 24 | pub index: Option, 25 | } 26 | 27 | #[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)] 28 | pub struct IP { 29 | pub index: Option, 30 | pub datatype: IPType, 31 | pub schema: String, 32 | pub scope: String, 33 | pub initial: bool, 34 | // the node 35 | pub owner: Option, 36 | pub clonable: bool, 37 | pub userdata: Value, 38 | } 39 | 40 | impl IP { 41 | pub fn new(datatype: IPType, options: IPOptions) -> Self { 42 | IP { 43 | index: options.index, 44 | datatype, 45 | schema: options.schema, 46 | scope: options.scope, 47 | initial: options.initial, 48 | clonable: options.clonable, 49 | owner: None, 50 | userdata: options.userdata, 51 | } 52 | } 53 | 54 | pub fn fake_clone(&self) -> Self { 55 | // Todo: filter out unimportant data 56 | self.clone() 57 | } 58 | pub fn can_fake_clone(&self) -> bool { 59 | false 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /crates/zflow_runtime/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod component; 2 | mod component_test; 3 | pub mod errors; 4 | pub mod ip; 5 | 6 | pub mod network; 7 | 8 | pub mod port; 9 | 10 | mod port_test; 11 | 12 | pub mod process; 13 | 14 | pub mod sockets; 15 | 16 | pub mod network_manager; 17 | 18 | pub mod provider; 19 | pub mod runner; 20 | 21 | #[cfg(feature = "host_only")] 22 | pub mod extern_provider; 23 | 24 | 25 | // #[cfg(feature = "js_runtime")] 26 | // pub mod js; 27 | // #[cfg(feature = "lua_runtime")] 28 | // pub mod lua; 29 | 30 | #[cfg(feature = "host_only")] 31 | pub mod wasm; 32 | #[cfg(feature = "host_only")] 33 | pub mod deno; 34 | #[cfg(feature = "host_only")] 35 | pub mod websocket; 36 | // #[cfg(feature = "wren_runtime")] 37 | // pub mod wren; 38 | // #[cfg(feature = "go_runtime")] 39 | // pub mod go; 40 | 41 | mod network_test; 42 | 43 | // #[cfg(feature = "go_runtime")] 44 | // #[macro_use] 45 | // extern crate go_engine as goengine; 46 | -------------------------------------------------------------------------------- /crates/zflow_runtime/network_manager.rs: -------------------------------------------------------------------------------- 1 | #[derive(Default, Debug, Copy, Clone)] 2 | pub (crate) struct NetworkManager { 3 | pub (crate) weight:usize, 4 | pub (crate) started: bool, 5 | pub (crate) stopped: bool, 6 | pub (crate) debounce_end: bool, 7 | pub (crate) abort_debounce: bool 8 | } 9 | 10 | impl NetworkManager { 11 | pub (crate) fn update(&mut self, copy:NetworkManager) -> Self { 12 | self.weight = if copy.weight > self.weight {copy.weight}else{self.weight}; 13 | self.started = copy.started; 14 | self.stopped = copy.stopped; 15 | self.debounce_end = copy.debounce_end; 16 | self.abort_debounce = copy.abort_debounce; 17 | 18 | self.clone() 19 | } 20 | pub fn new()-> NetworkManager { 21 | Self { weight: 0, started: false, stopped: true, debounce_end: false, abort_debounce: false } 22 | } 23 | 24 | pub fn is_running(&self) -> bool { 25 | self.weight > 0 26 | } 27 | 28 | pub fn is_stopped(&self) -> bool { 29 | self.stopped 30 | } 31 | pub fn is_started(&self) -> bool { 32 | self.started 33 | } 34 | 35 | pub fn cancel_debounce(&mut self, abort: bool) { 36 | self.abort_debounce = abort; 37 | } 38 | 39 | pub fn check_if_finished(&mut self) { 40 | if self.is_running() { 41 | return; 42 | } 43 | self.cancel_debounce(false); 44 | 45 | while !self.debounce_end { 46 | if self.abort_debounce { 47 | break; 48 | } 49 | 50 | if self.is_running() { 51 | break; 52 | } 53 | 54 | self.started = false; 55 | self.debounce_end = true; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /crates/zflow_runtime/runner.rs: -------------------------------------------------------------------------------- 1 | use std::sync::{Arc, Mutex}; 2 | 3 | 4 | use crate::process::{ProcessError, ProcessHandle, ProcessResult}; 5 | 6 | pub type RunFunc = dyn FnMut(Arc>) -> Result 7 | + Send 8 | + Sync 9 | + 'static; 10 | 11 | pub type DynRunFunc = dyn FnMut(Box<[u8]>, Arc>) -> Result 12 | + Send 13 | + Sync 14 | + 'static; 15 | 16 | 17 | pub type UnsafeRunFunc = unsafe extern fn( 18 | source: *const u8, 19 | length: usize, 20 | handle: *const Arc>, 21 | result: *mut Result 22 | ); 23 | 24 | pub(crate) const WASM_RUNNER_ID: &str = "@zflow/wasm"; 25 | pub(crate) const DENO_RUNNER_ID: &str = "@zflow/deno"; 26 | 27 | pub(crate) const QUICKJS_RUNNER_ID: &str = "@zflow/quickjs"; 28 | 29 | 30 | -------------------------------------------------------------------------------- /crates/zflow_server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zflow_server" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Damilare Akinlaja "] 6 | license = "MIT" 7 | description = "ZFlow FBP Graph Server" 8 | keywords = ["fbp", "flowbased", "low-code", "no-code", "visual-programming", "server"] 9 | 10 | [dependencies] 11 | zflow_graph = {path = "../zflow_graph"} 12 | zflow_runtime = {path = "../zflow_runtime"} 13 | tokio = { version = "1.16", features = ["full"] } 14 | tokio-stream = { version = "0.1", features = ["sync"] } 15 | # serde_json = { version = "1" } 16 | jsonrpsee = {version="0.21.0", features = ["full"]} -------------------------------------------------------------------------------- /crates/zflow_server/src/main.rs: -------------------------------------------------------------------------------- 1 | use zflow_runtime::network::Network; 2 | 3 | #[tokio::main] 4 | async fn main(){ 5 | // let network = Network::create(graph, options) 6 | } -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | components = ["rust-src", "rustfmt", "clippy"] -------------------------------------------------------------------------------- /test_components/add_go/add.gos: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "zflow" 4 | 5 | func main() { 6 | // get inputs 7 | var in = zflow.Inputs() 8 | 9 | data, ok := in.Map() 10 | if !ok { 11 | panic("could not read inputs") 12 | } 13 | input, _ := data["input"].Map() 14 | left, _ := input["left"].I64() 15 | right, _ := input["right"].I64() 16 | // some calculations 17 | total := left + right 18 | 19 | packet := map[string]int64{"sum": total} 20 | zflow.Send(packet) 21 | } 22 | -------------------------------------------------------------------------------- /test_components/add_go/zflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "package_id": "test", 3 | "components": [ 4 | { 5 | "name": "add_go", 6 | "inports": { 7 | "input":{"trigerring": true, "control":true} 8 | }, 9 | "outports": { 10 | "sum":{} 11 | }, 12 | "source_dir": "/", 13 | "source": "add.gos", 14 | "description": "sum of two numbers", 15 | "ordered": true, 16 | "runtime": { 17 | "provider_id": "@zflow/builtin", 18 | "runner_id": "@zflow/goscript", 19 | "platform": "System" 20 | } 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /test_components/add_js/add.js: -------------------------------------------------------------------------------- 1 | 2 | export const process = ({input}) => { 3 | if(!input) return; 4 | if (input.a === null && input.b === null ) return; 5 | 6 | const left = input.a 7 | const right = input.b 8 | zflow.sendDone({ result: Number(left) + Number(right) }) 9 | } -------------------------------------------------------------------------------- /test_components/add_js/runner/libzflow_runner_js.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/test_components/add_js/runner/libzflow_runner_js.dylib -------------------------------------------------------------------------------- /test_components/add_js/zflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "package_id": "test", 3 | "version": "1.0.0", 4 | "author": "Damilare Akinlaja", 5 | "components": [ 6 | { 7 | "name": "add", 8 | "forward_brackets":{}, 9 | "activate_on_input": true, 10 | "inports": { 11 | "a":{}, 12 | "b":{} 13 | }, 14 | "outports": { 15 | "result":{} 16 | }, 17 | "source_dir": "/", 18 | "source": "add.js", 19 | "description": "sum of two numbers", 20 | "ordered": true, 21 | "runtime": { 22 | "provider_id": "@zflow/builtin", 23 | "runner_id": "@zflow/quickjs", 24 | "platform": "System" 25 | } 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /test_components/add_lua/add.lua: -------------------------------------------------------------------------------- 1 | function zflow.process(data) 2 | if data.input ~= nil then 3 | local input = data["input"] 4 | local left = input.left 5 | local right = input.right 6 | 7 | if left ~= nil and right ~= nil then 8 | zflow.send_done({ sum = left + right }) 9 | end 10 | end 11 | end -------------------------------------------------------------------------------- /test_components/add_lua/zflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "package_id": "test", 3 | "components": [ 4 | { 5 | "name": "add_lua", 6 | "inports": { 7 | "input":{"trigerring": true, "control":true} 8 | }, 9 | "outports": { 10 | "sum":{} 11 | }, 12 | "source_dir": "/", 13 | "source": "add.lua", 14 | "description": "sum of two numbers", 15 | "ordered": true, 16 | "runtime": { 17 | "provider_id": "@zflow/builtin", 18 | "runner_id": "@zflow/lua", 19 | "platform": "System" 20 | } 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /test_components/add_wasm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "add_wasm" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | extism-pdk= {workspace = true} 10 | serde_json = "1.0" 11 | serde = { version = "1.0", features = ["derive"] } 12 | zflow_plugin = {path= "../../crates/zflow_plugin"} 13 | 14 | [lib] 15 | crate_type = ["cdylib"] 16 | path = "lib.rs" -------------------------------------------------------------------------------- /test_components/add_wasm/add_wasm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/test_components/add_wasm/add_wasm.wasm -------------------------------------------------------------------------------- /test_components/add_wasm/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | 3 | use json::Value; 4 | use zflow_plugin::{*, extension::*}; 5 | use serde::{Deserialize, Serialize}; 6 | 7 | #[repr(C)] 8 | #[derive(Serialize, Deserialize)] 9 | pub struct Output { 10 | pub sum: i64, 11 | } 12 | 13 | #[derive(Serialize, Deserialize, Debug)] 14 | pub struct Packet { 15 | pub input: Input, 16 | } 17 | 18 | #[derive(Serialize, Deserialize, Debug)] 19 | pub struct Input { 20 | pub left: Value, 21 | pub right: Value, 22 | } 23 | 24 | #[plugin_fn] 25 | pub fn process(packet: Json) -> FnResult> { 26 | // because inputs are controlled, we wait for all of them 27 | let input:Input = packet.0.input; 28 | if input.left != Value::Null && input.right != Value::Null { 29 | let left = input.left.as_i64().unwrap(); 30 | let right = input.right.as_i64().unwrap(); 31 | 32 | let data = Output { sum: left + right }; 33 | unsafe { 34 | // send output to host 35 | send_done(Json(data))?; 36 | } 37 | } 38 | 39 | return Ok(Json(Output { sum: 0 })); 40 | } 41 | -------------------------------------------------------------------------------- /test_components/add_wasm/zflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "package_id": "test", 3 | "components": [ 4 | { 5 | "name": "add_wasm", 6 | "inports": { 7 | "input":{"trigerring": true, "control":true} 8 | }, 9 | "outports": { 10 | "sum":{} 11 | }, 12 | "base_dir": "/", 13 | "source": "add_wasm.wasm", 14 | "description": "sum of two numbers", 15 | "ordered": true, 16 | "runtime": { 17 | "provider_id": "@zflow/builtin", 18 | "runner_id": "@zflow/wasm", 19 | "platform": "System" 20 | } 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /test_components/add_wren/main.wren: -------------------------------------------------------------------------------- 1 | import "zflow" for ZFlow 2 | 3 | class Main { 4 | static process(packet){ 5 | if(packet == null) return 6 | if(!packet.containsKey("input")) return 7 | var data = packet["input"] 8 | if (!data.containsKey("left") && !data.containsKey("right")) return 9 | var result = data["left"] + data["right"] 10 | ZFlow.send({"sum": result}) 11 | } 12 | } -------------------------------------------------------------------------------- /test_components/add_wren/zflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "package_id": "test", 3 | "components": [ 4 | { 5 | "name": "add_wren", 6 | "inports": { 7 | "input":{"trigerring": true, "control":true} 8 | }, 9 | "outports": { 10 | "sum":{} 11 | }, 12 | "source_dir": "/", 13 | "source": "main.wren", 14 | "description": "sum of two numbers", 15 | "language": "wren", 16 | "ordered": true, 17 | "runtime": { 18 | "provider_id": "@zflow/builtin", 19 | "runner_id": "@zflow/wren", 20 | "platform": "System" 21 | } 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /test_providers/maths_provider/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target-dir = "bin" -------------------------------------------------------------------------------- /test_providers/maths_provider/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "maths_provider" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | extism-pdk= {workspace = true} 10 | serde_json = "1.0" 11 | serde = { version = "1.0", features = ["derive"] } 12 | zflow_plugin = {path= "../../crates/zflow_plugin"} 13 | 14 | [lib] 15 | crate_type = ["cdylib"] 16 | path = "lib.rs" -------------------------------------------------------------------------------- /test_providers/maths_provider/bin/.rustc_info.json: -------------------------------------------------------------------------------- 1 | {"rustc_fingerprint":2635327901679194958,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.77.0-nightly (88189a71e 2024-01-19)\nbinary: rustc\ncommit-hash: 88189a71e4e4376eea82ac61db6a539612eb200a\ncommit-date: 2024-01-19\nhost: aarch64-apple-darwin\nrelease: 1.77.0-nightly\nLLVM version: 17.0.6\n","stderr":""},"8780870655093111374":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/amaterasu/.rustup/toolchains/nightly-aarch64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"v8.1a\"\ntarget_feature=\"v8.2a\"\ntarget_feature=\"v8.3a\"\ntarget_feature=\"v8.4a\"\ntarget_feature=\"vh\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"128\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"2682271465812745747":{"success":true,"status":"","code":0,"stdout":"___.wasm\nlib___.rlib\n___.wasm\nlib___.a\n/Users/amaterasu/.rustup/toolchains/nightly-aarch64-apple-darwin\noff\n___\ndebug_assertions\noverflow_checks\npanic=\"abort\"\nproc_macro\nrelocation_model=\"static\"\ntarget_abi=\"\"\ntarget_arch=\"wasm32\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"wasm\"\ntarget_feature=\"mutable-globals\"\ntarget_feature=\"sign-ext\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"wasi\"\ntarget_pointer_width=\"32\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\n","stderr":"warning: dropping unsupported crate type `dylib` for target `wasm32-wasi`\n\nwarning: dropping unsupported crate type `proc-macro` for target `wasm32-wasi`\n\nwarning: 2 warnings emitted\n\n"}},"successes":{}} -------------------------------------------------------------------------------- /test_providers/maths_provider/bin/CACHEDIR.TAG: -------------------------------------------------------------------------------- 1 | Signature: 8a477f597d28d172789f06886806bc55 2 | # This file is a cache directory tag created by cargo. 3 | # For information about cache directory tags see https://bford.info/cachedir/ 4 | -------------------------------------------------------------------------------- /test_providers/maths_provider/bin/maths_provider.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zflow-dev/zflow/c9e01f509e4416a85f91cc7966b156694fa16d6b/test_providers/maths_provider/bin/maths_provider.wasm -------------------------------------------------------------------------------- /test_providers/maths_provider/bin/wasm32-wasi/CACHEDIR.TAG: -------------------------------------------------------------------------------- 1 | Signature: 8a477f597d28d172789f06886806bc55 2 | # This file is a cache directory tag created by cargo. 3 | # For information about cache directory tags see https://bford.info/cachedir/ 4 | -------------------------------------------------------------------------------- /test_providers/maths_provider/build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cargo build --target wasm32-wasi --release 4 | 5 | cp ./bin/wasm32-wasi/release/maths_provider.wasm ./bin/maths_provider.wasm -------------------------------------------------------------------------------- /test_providers/maths_provider/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | 3 | 4 | use serde::{Deserialize, Serialize}; 5 | 6 | use serde_json::{Value, json}; 7 | use zflow_plugin::{*, extension::*}; 8 | 9 | #[repr(C)] 10 | #[derive(Serialize, Deserialize)] 11 | pub struct Output { 12 | pub result: i64, 13 | } 14 | 15 | 16 | #[repr(C)] 17 | #[derive(Serialize, Deserialize, Debug)] 18 | pub struct Input { 19 | pub a: Value, 20 | pub b: Value, 21 | } 22 | 23 | pub fn add(input: Value) -> FnResult<()> { 24 | // because inputs are controlled, we wait for all of them 25 | let input = Input::deserialize(input)?; 26 | if input.a != Value::Null && input.b != Value::Null { 27 | let left = input.a.as_i64().unwrap(); 28 | let right = input.b.as_i64().unwrap(); 29 | 30 | let data = Output { 31 | result: left + right, 32 | }; 33 | unsafe { 34 | // send output to host 35 | // send(Json(data))?; 36 | send_done(Json(data))?; 37 | // send_buffer("Out".to_owned(), &[1, 2, 4])?; 38 | } 39 | } 40 | 41 | return Ok(()); 42 | } 43 | 44 | 45 | pub fn sub(input: Value) -> FnResult<()> { 46 | let input = Input::deserialize(input)?; 47 | if input.a != Value::Null && input.b != Value::Null { 48 | let left = input.a.as_i64().unwrap(); 49 | let right = input.b.as_i64().unwrap(); 50 | 51 | let data = Output { 52 | result: left - right, 53 | }; 54 | unsafe { 55 | // send output to host 56 | send_done(Json(data))?; 57 | } 58 | } 59 | 60 | return Ok(()); 61 | } 62 | 63 | 64 | #[plugin_fn] 65 | pub unsafe fn provider_id() -> FnResult { 66 | return Ok("@test/provider".to_owned()) 67 | } 68 | 69 | #[plugin_fn] 70 | pub unsafe fn get_logo() -> FnResult { 71 | // return valid SVG logo icon 72 | return Ok("".to_owned()) 73 | } 74 | 75 | #[plugin_fn] 76 | pub unsafe fn get_platform() -> FnResult> { 77 | return Ok(Json(Platform::System)) 78 | } 79 | 80 | #[plugin_fn] 81 | pub unsafe fn get_packages() -> FnResult>> { 82 | let packages = json!([ 83 | { 84 | "package_id": "math", 85 | "components": [ 86 | { 87 | "name": "math/add", 88 | "inports": { 89 | "a": { 90 | "trigerring": true, 91 | "control": true 92 | }, 93 | "b": { 94 | "trigerring": true, 95 | "control": true 96 | } 97 | }, 98 | "outports": { 99 | "result": {} 100 | }, 101 | "description": "Addition of two numbers", 102 | "ordered": true 103 | }, 104 | { 105 | "name": "math/sub", 106 | "inports": { 107 | "input": { 108 | "trigerring": true, 109 | "control": true 110 | } 111 | }, 112 | "outports": { 113 | "result": {} 114 | }, 115 | "description": "Substraction of two numbers", 116 | "ordered": true 117 | } 118 | ] 119 | } 120 | ]); 121 | 122 | let packages = packages.as_array().unwrap().iter().map(|p| Package::deserialize(p).unwrap()).collect::>(); 123 | 124 | return Ok(Json(packages)); 125 | } 126 | 127 | 128 | #[plugin_fn] 129 | pub unsafe fn run_component(packet:Json) -> FnResult<()> { 130 | let packet = packet.into_inner(); 131 | match packet.component.name.as_str() { 132 | "math/add"=> { 133 | add(packet.input)?; 134 | }, 135 | "math/sub"=> { 136 | sub(packet.input)?; 137 | }, 138 | _ => { 139 | return Err(Error::msg("Unknown process").into()) 140 | } 141 | } 142 | 143 | Ok(()) 144 | } -------------------------------------------------------------------------------- /test_providers/maths_provider/math.js: -------------------------------------------------------------------------------- 1 | const add = async (context,input) => { 2 | context.sendDone({ result: input.a + input.b }) 3 | } 4 | 5 | const sub = async (context,input) => { 6 | context.sendDone({ result: input.a - input.b }) 7 | } 8 | 9 | 10 | export const providerId = () => "@test/deno_provider"; 11 | 12 | export const getLogo = () => ""; 13 | 14 | export const getPlatform = () => "System"; 15 | 16 | export const getPackages = () => [ 17 | { 18 | "package_id": "math", 19 | "components": [ 20 | { 21 | "name": "math/add", 22 | "inports": { 23 | "a": { 24 | "trigerring": true, 25 | "control": true 26 | }, 27 | "b": { 28 | "trigerring": true, 29 | "control": true 30 | } 31 | }, 32 | "outports": { 33 | "result": {} 34 | }, 35 | "description": "Addition of two numbers", 36 | "ordered": true 37 | }, 38 | { 39 | "name": "math/sub", 40 | "inports": { 41 | "input": { 42 | "trigerring": true, 43 | "control": true 44 | } 45 | }, 46 | "outports": { 47 | "result": {} 48 | }, 49 | "description": "Substraction of two numbers", 50 | "ordered": true 51 | } 52 | ] 53 | } 54 | ]; 55 | 56 | 57 | export const runComponent = (context, payload) => { 58 | const componentName = payload.component.name; 59 | // fmt.printf("%s", JSON.stringify(payload)); 60 | fetch("https://deno.com").then(async (response)=>{ 61 | console.log(response.status); 62 | console.log(response.statusText); 63 | const jsonData = await response.json(); 64 | console.log(jsonData) 65 | }); 66 | 67 | switch (componentName) { 68 | case "math/add": { 69 | add(context, payload.input); 70 | break; 71 | } 72 | case "math/sub": { 73 | sub(context, payload.input); 74 | break; 75 | } 76 | default: throw "Unknown process" 77 | } 78 | } -------------------------------------------------------------------------------- /test_providers/maths_provider/math.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | interface Context { 3 | sendDone: (data: any) => void; 4 | send: (data: any) => void; 5 | sendBuffer: (port: string, data: Uint8Array) => void; 6 | } 7 | } 8 | 9 | type Input = { 10 | a: number; 11 | b: number; 12 | } 13 | 14 | const add = async (context: Context, input: Input) => { 15 | context.sendDone({ result: input.a + input.b }) 16 | } 17 | 18 | const sub = async (context: Context, input: Input) => { 19 | context.sendDone({ result: input.a - input.b }) 20 | } 21 | 22 | 23 | export const providerId = () => "@test/deno_provider"; 24 | 25 | export const getLogo = () => ""; 26 | 27 | export const getPlatform = () => "System"; 28 | 29 | export const getPackages = () => [ 30 | { 31 | "package_id": "math", 32 | "components": [ 33 | { 34 | "name": "math/add", 35 | "inports": { 36 | "a": { 37 | "trigerring": true, 38 | "control": true 39 | }, 40 | "b": { 41 | "trigerring": true, 42 | "control": true 43 | } 44 | }, 45 | "outports": { 46 | "result": {} 47 | }, 48 | "description": "Addition of two numbers", 49 | "ordered": true 50 | }, 51 | { 52 | "name": "math/sub", 53 | "inports": { 54 | "input": { 55 | "trigerring": true, 56 | "control": true 57 | } 58 | }, 59 | "outports": { 60 | "result": {} 61 | }, 62 | "description": "Substraction of two numbers", 63 | "ordered": true 64 | } 65 | ] 66 | } 67 | ]; 68 | 69 | 70 | export const runComponent = async (context: Context, payload: any) => { 71 | const componentName = payload.component.name; 72 | switch (componentName) { 73 | case "math/add": { 74 | await add(context, payload.input as Input); 75 | break; 76 | } 77 | case "math/sub": { 78 | await sub(context, payload.input as Input); 79 | break; 80 | } 81 | default: throw "Unknown process" 82 | } 83 | } -------------------------------------------------------------------------------- /test_providers/maths_provider/zflow.provider.json: -------------------------------------------------------------------------------- 1 | { 2 | "provider_id": "@test/provider", 3 | "platform": "System", 4 | "workspace": "/", 5 | "type": "Wasi", 6 | "source": { 7 | "path": "./bin/maths_provider.wasm" 8 | }, 9 | "logo": "", 10 | "packages": [ 11 | { 12 | "package_name": "math", 13 | "base_dir": "/", 14 | "components": [ 15 | { 16 | "name": "math/add", 17 | "inports": { 18 | "input": { 19 | "trigerring": true, 20 | "control": true 21 | } 22 | }, 23 | "outports": { 24 | "sum": {} 25 | }, 26 | "process": "add", 27 | "description": "Addition of two numbers", 28 | "ordered": true 29 | }, 30 | { 31 | "name": "math/sub", 32 | "inports": { 33 | "input": { 34 | "trigerring": true, 35 | "control": true 36 | } 37 | }, 38 | "outports": { 39 | "result": {} 40 | }, 41 | "process": "sub", 42 | "description": "Substraction of two numbers", 43 | "ordered": true 44 | } 45 | ] 46 | } 47 | ] 48 | } --------------------------------------------------------------------------------