@greenpandastudios/aug-cli 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/docs/assets/benchmarks/execution.svg +774 -637
- package/docs/assets/benchmarks/http.svg +278 -249
- package/docs/assets/benchmarks/improvements.svg +66 -66
- package/docs/assets/benchmarks/kernels-mobile.svg +1 -0
- package/docs/assets/benchmarks/kernels.svg +1 -0
- package/docs/assets/benchmarks/memory.svg +153 -153
- package/docs/benchmark-results.json +227089 -90363
- package/docs/compatibility.md +6 -6
- package/docs/contributing-benchmarks.md +36 -6
- package/docs/dev-containers.md +8 -15
- package/docs/dgx-consumers.json +122 -0
- package/docs/dgx-gyms.json +784 -0
- package/docs/dgx-kernels.json +1170 -0
- package/docs/dgx-performance.json +227849 -0
- package/docs/dgx-spark.md +64 -0
- package/docs/diagnostics.md +1 -1
- package/docs/docker.md +16 -17
- package/docs/example-projects.json +32 -0
- package/docs/examples/approved-design/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/approved-design/domain/app.md +4 -4
- package/docs/examples/approved-design/main.md +2 -2
- package/docs/examples/calls-benchmark/index.md +36 -0
- package/docs/examples/calls-benchmark/main.md +78 -0
- package/docs/examples/calls-benchmark/operations.md +60 -0
- package/docs/examples/developer-workflow/calculator.md +5 -5
- package/docs/examples/developer-workflow/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/developer-workflow/logging/console.md +2 -2
- package/docs/examples/developer-workflow/logging/logger.md +2 -2
- package/docs/examples/developer-workflow/main.md +2 -2
- package/docs/examples/errors-benchmark/index.md +36 -0
- package/docs/examples/errors-benchmark/main.md +92 -0
- package/docs/examples/errors-benchmark/operations.md +65 -0
- package/docs/examples/float-benchmark/index.md +35 -0
- package/docs/examples/float-benchmark/main.md +75 -0
- package/docs/examples/generic-di/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/generic-di/main.md +2 -2
- package/docs/examples/generic-di/types.md +3 -3
- package/docs/examples/hello/app/greeter.md +3 -3
- package/docs/examples/hello/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/hello/logging/console.md +2 -2
- package/docs/examples/hello/logging/logger.md +2 -2
- package/docs/examples/hello/main.md +2 -2
- package/docs/examples/index.md +18 -1
- package/docs/examples/interceptors/app.md +5 -5
- package/docs/examples/interceptors/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/interceptors/interceptors.md +2 -2
- package/docs/examples/interceptors/logging.md +3 -3
- package/docs/examples/interceptors/main.md +2 -2
- package/docs/examples/list-benchmark/index.md +35 -0
- package/docs/examples/list-benchmark/main.md +78 -0
- package/docs/examples/map-churn-benchmark/index.md +35 -0
- package/docs/examples/map-churn-benchmark/main.md +106 -0
- package/docs/examples/native-blake3/dependencies/packages/@greenpandastudios/aug-blake3/0.1.3/api.md +104 -0
- package/docs/examples/native-blake3/dependencies/packages/@greenpandastudios/aug-blake3/0.1.3/contracts.md +54 -0
- package/docs/examples/native-blake3/dependencies/packages/@greenpandastudios/aug-blake3/0.1.3/native.abi-json.md +48 -0
- package/docs/examples/native-blake3/hashing.md +93 -0
- package/docs/examples/native-blake3/index.md +38 -0
- package/docs/examples/native-blake3/main.md +73 -0
- package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/api.md +406 -0
- package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/bindings.md +51 -0
- package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/contracts.md +63 -0
- package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/native.abi-json.md +161 -0
- package/docs/examples/native-pytorch/index.md +38 -0
- package/docs/examples/native-pytorch/main.md +73 -0
- package/docs/examples/native-pytorch/tensors.md +123 -0
- package/docs/examples/native-sqlite/database.md +116 -0
- package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/api.md +284 -0
- package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/bindings.md +51 -0
- package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/contracts.md +75 -0
- package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/native.abi-json.md +119 -0
- package/docs/examples/native-sqlite/index.md +38 -0
- package/docs/examples/native-sqlite/main.md +73 -0
- package/docs/examples/native-zlib/compression.md +99 -0
- package/docs/examples/native-zlib/dependencies/packages/@greenpandastudios/aug-zlib/0.1.3/api.md +153 -0
- package/docs/examples/native-zlib/dependencies/packages/@greenpandastudios/aug-zlib/0.1.3/contracts.md +54 -0
- package/docs/examples/native-zlib/dependencies/packages/@greenpandastudios/aug-zlib/0.1.3/native.abi-json.md +76 -0
- package/docs/examples/native-zlib/index.md +38 -0
- package/docs/examples/native-zlib/main.md +78 -0
- package/docs/examples/new-syntax/console.md +2 -2
- package/docs/examples/new-syntax/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/new-syntax/greeter.md +3 -3
- package/docs/examples/new-syntax/logger.md +2 -2
- package/docs/examples/new-syntax/main.md +2 -2
- package/docs/examples/ownership-transfer/dependencies/august/{0.20.1 → 0.21.0}/io/contracts.md +3 -3
- package/docs/examples/ownership-transfer/main.md +2 -2
- package/docs/examples/ownership-transfer/resource.md +2 -2
- package/docs/examples/packages-math/aug-package-json.md +1 -1
- package/docs/examples/records-benchmark/data.md +55 -0
- package/docs/examples/records-benchmark/index.md +36 -0
- package/docs/examples/records-benchmark/main.md +85 -0
- package/docs/examples/strings-benchmark/index.md +35 -0
- package/docs/examples/strings-benchmark/main.md +76 -0
- package/docs/examples/tasks-benchmark/index.md +36 -0
- package/docs/examples/tasks-benchmark/main.md +89 -0
- package/docs/examples/tasks-benchmark/operations.md +58 -0
- package/docs/getting-started.md +3 -3
- package/docs/grammar.md +2 -2
- package/docs/gym-results.json +784 -0
- package/docs/implementation-map.md +6 -0
- package/docs/index.md +1 -1
- package/docs/kernel-results.json +1170 -0
- package/docs/language-conformance.md +6 -0
- package/docs/language-constructs.md +9 -1
- package/docs/learn/index.md +1 -1
- package/docs/maintaining-docs.md +1 -1
- package/docs/native-implementation.md +276 -0
- package/docs/native-interop-llvm-plan.md +342 -0
- package/docs/native-package-examples.md +684 -0
- package/docs/native-packages.md +179 -0
- package/docs/packages.md +2 -2
- package/docs/performance.md +50 -29
- package/docs/production-readiness.md +11 -1
- package/docs/public/downloads/approved-design.zip +0 -0
- package/docs/public/downloads/calls-benchmark.zip +0 -0
- package/docs/public/downloads/developer-workflow.zip +0 -0
- package/docs/public/downloads/errors-benchmark.zip +0 -0
- package/docs/public/downloads/float-benchmark.zip +0 -0
- package/docs/public/downloads/generic-di.zip +0 -0
- package/docs/public/downloads/hello.zip +0 -0
- package/docs/public/downloads/interceptors.zip +0 -0
- package/docs/public/downloads/json-benchmark.zip +0 -0
- package/docs/public/downloads/list-benchmark.zip +0 -0
- package/docs/public/downloads/map-churn-benchmark.zip +0 -0
- package/docs/public/downloads/native-blake3.zip +0 -0
- package/docs/public/downloads/native-pytorch.zip +0 -0
- package/docs/public/downloads/native-sqlite.zip +0 -0
- package/docs/public/downloads/native-zlib.zip +0 -0
- package/docs/public/downloads/new-syntax.zip +0 -0
- package/docs/public/downloads/oidc-login.zip +0 -0
- package/docs/public/downloads/ownership-transfer.zip +0 -0
- package/docs/public/downloads/packages-app.zip +0 -0
- package/docs/public/downloads/packages-math.zip +0 -0
- package/docs/public/downloads/records-benchmark.zip +0 -0
- package/docs/public/downloads/strings-benchmark.zip +0 -0
- package/docs/public/downloads/tasks-benchmark.zip +0 -0
- package/docs/qualification-results.md +66 -0
- package/docs/reference.md +24 -0
- package/docs/releasing.md +81 -6
- package/docs/research/libtorch-native-qualification.md +115 -0
- package/docs/research/native-interop-llvm.md +197 -0
- package/docs/research/qualification-methods.md +15 -0
- package/docs/roadmap.md +1 -0
- package/docs/safety-gyms.md +41 -0
- package/docs/tooling.md +16 -15
- package/docs/web-library-gaps.md +1 -1
- package/docs/web.md +4 -0
- package/examples/approved-design/.aug-spec/manifest.json +3 -3
- package/examples/approved-design/domain/app.aug.md +4 -4
- package/examples/approved-design/main.aug.md +2 -2
- package/examples/developer-workflow/.aug-spec/manifest.json +3 -3
- package/examples/developer-workflow/calculator.aug.md +5 -5
- package/examples/developer-workflow/logging/console.aug.md +2 -2
- package/examples/developer-workflow/logging/logger.aug.md +2 -2
- package/examples/developer-workflow/main.aug.md +2 -2
- package/examples/generic-di/.aug-spec/manifest.json +3 -3
- package/examples/generic-di/main.aug.md +2 -2
- package/examples/generic-di/types.aug.md +3 -3
- package/examples/hello/.aug-spec/manifest.json +3 -3
- package/examples/hello/app/greeter.aug.md +3 -3
- package/examples/hello/logging/console.aug.md +2 -2
- package/examples/hello/logging/logger.aug.md +2 -2
- package/examples/hello/main.aug.md +2 -2
- package/examples/interceptors/.aug-spec/manifest.json +3 -3
- package/examples/interceptors/app.aug.md +5 -5
- package/examples/interceptors/interceptors.aug.md +2 -2
- package/examples/interceptors/logging.aug.md +3 -3
- package/examples/interceptors/main.aug.md +2 -2
- package/examples/native-blake3/.aug-spec/manifest.json +16 -0
- package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.1/native.abi.json +29 -0
- package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/api.aug +14 -0
- package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/api.aug.md +34 -0
- package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/contracts.aug +4 -0
- package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/contracts.aug.md +8 -0
- package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/native.abi.json +29 -0
- package/examples/native-blake3/AGENTS.md +5 -0
- package/examples/native-blake3/aug.lock.json +253 -0
- package/examples/native-blake3/hashing.aug +11 -0
- package/examples/native-blake3/hashing.aug.md +25 -0
- package/examples/native-blake3/main.aug +8 -0
- package/examples/native-blake3/main.aug.md +13 -0
- package/examples/native-pytorch/.aug-spec/manifest.json +18 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.1/native.abi.json +142 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.3/native.abi.json +142 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/api.aug +101 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/api.aug.md +160 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/bindings.aug +3 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/bindings.aug.md +8 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/contracts.aug +6 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/contracts.aug.md +13 -0
- package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/native.abi.json +142 -0
- package/examples/native-pytorch/AGENTS.md +5 -0
- package/examples/native-pytorch/aug.lock.json +309 -0
- package/examples/native-pytorch/main.aug +8 -0
- package/examples/native-pytorch/main.aug.md +13 -0
- package/examples/native-pytorch/tensors.aug +23 -0
- package/examples/native-pytorch/tensors.aug.md +35 -0
- package/examples/native-sqlite/.aug-spec/manifest.json +18 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.2/native.abi.json +100 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug +48 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug.md +91 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/bindings.aug +3 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/bindings.aug.md +8 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/contracts.aug +8 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/contracts.aug.md +22 -0
- package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/native.abi.json +100 -0
- package/examples/native-sqlite/AGENTS.md +5 -0
- package/examples/native-sqlite/aug.lock.json +236 -0
- package/examples/native-sqlite/database.aug +15 -0
- package/examples/native-sqlite/database.aug.md +27 -0
- package/examples/native-sqlite/main.aug +8 -0
- package/examples/native-sqlite/main.aug.md +13 -0
- package/examples/native-zlib/.aug-spec/manifest.json +16 -0
- package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.1/native.abi.json +57 -0
- package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/api.aug +29 -0
- package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/api.aug.md +54 -0
- package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/contracts.aug +4 -0
- package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/contracts.aug.md +8 -0
- package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/native.abi.json +57 -0
- package/examples/native-zlib/AGENTS.md +5 -0
- package/examples/native-zlib/aug.lock.json +236 -0
- package/examples/native-zlib/compression.aug +15 -0
- package/examples/native-zlib/compression.aug.md +27 -0
- package/examples/native-zlib/main.aug +10 -0
- package/examples/native-zlib/main.aug.md +13 -0
- package/examples/new-syntax/.aug-spec/manifest.json +3 -3
- package/examples/new-syntax/console.aug.md +2 -2
- package/examples/new-syntax/greeter.aug.md +3 -3
- package/examples/new-syntax/logger.aug.md +2 -2
- package/examples/new-syntax/main.aug.md +2 -2
- package/examples/oidc-login/aug.lock.json +6 -6
- package/examples/ownership-transfer/.aug-spec/manifest.json +3 -3
- package/examples/ownership-transfer/main.aug.md +2 -2
- package/examples/ownership-transfer/resource.aug.md +2 -2
- package/examples/packages/math/aug-package.json +1 -1
- package/native/compiler-packs.json +43 -0
- package/package.json +3 -2
- package/runtime/aug_http.c +48 -21
- package/runtime/aug_http_ir.c +30 -0
- package/runtime/aug_http_ir.h +18 -0
- package/runtime/aug_ir.c +209 -0
- package/runtime/aug_ir.h +89 -0
- package/runtime/aug_json.c +6 -1
- package/runtime/aug_runtime.c +82 -16
- package/runtime/aug_runtime.h +16 -2
- package/runtime/aug_tasks.c +38 -7
- package/runtime/aug_values.c +12 -6
- package/scripts/bootstrap-native.mjs +4 -1
- package/src/ast.js +1 -1
- package/src/checker.js +110 -28
- package/src/cli.js +92 -14
- package/src/codegen.js +31 -6
- package/src/compiler-packs.js +66 -0
- package/src/config.js +2 -2
- package/src/editor.js +15 -6
- package/src/formatter.js +4 -2
- package/src/git-http.js +137 -0
- package/src/git-packages.js +9 -1
- package/src/help.js +10 -2
- package/src/ir-types.js +5 -0
- package/src/ir-verify.js +277 -0
- package/src/ir.js +962 -0
- package/src/llvm-debug.js +101 -0
- package/src/llvm-native.js +152 -0
- package/src/llvm-platform.js +20 -0
- package/src/llvm.js +781 -0
- package/src/native-artifacts.js +207 -0
- package/src/native-bindings.js +189 -0
- package/src/native-contracts.js +295 -0
- package/src/native-declarations.js +68 -0
- package/src/native-facts.js +63 -0
- package/src/package-locking.js +43 -0
- package/src/package-manager.js +23 -8
- package/src/parser.js +20 -2
- package/src/project.js +2 -2
- package/src/runtime-abi.js +23 -0
- package/src/runtime-adapters.js +18 -0
- package/src/schemas.js +24 -17
- package/src/semantic.js +8 -3
- package/src/snippets.js +1 -0
- package/src/spec.js +49 -8
- /package/examples/approved-design/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/approved-design/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
- /package/examples/developer-workflow/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/developer-workflow/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
- /package/examples/generic-di/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/generic-di/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
- /package/examples/hello/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/hello/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
- /package/examples/interceptors/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/interceptors/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
- /package/examples/new-syntax/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/new-syntax/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
- /package/examples/ownership-transfer/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug +0 -0
- /package/examples/ownership-transfer/.aug-spec/august/{0.20.1 → 0.21.0}/io/contracts.aug.md +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "CPU tensors with PyTorch"
|
|
3
|
+
generated: true
|
|
4
|
+
source: "examples/native-pytorch"
|
|
5
|
+
editLink: false
|
|
6
|
+
prev: false
|
|
7
|
+
next: false
|
|
8
|
+
outline: [2, 3]
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# CPU tensors with PyTorch
|
|
12
|
+
|
|
13
|
+
Import real LibTorch from its public August package, add CPU tensors, and verify the elements and sum. Owned tensors are released when their scope ends.
|
|
14
|
+
|
|
15
|
+
Open a file to read its source beside the explanation produced by `aug spec`. **Indentation** and **Braces** display the same checked program; your choice carries across file pages.
|
|
16
|
+
|
|
17
|
+
This project requires the August `0.21.0` LLVM preview on macOS 14+ with Apple Silicon, or Debian/Ubuntu GNU/Linux x64 or ARM64 with glibc 2.36+. The library archives are public; the matching compiler release is still being qualified.
|
|
18
|
+
|
|
19
|
+
## Project files
|
|
20
|
+
|
|
21
|
+
- [`main.aug`](main.md)
|
|
22
|
+
- [`tensors.aug`](tensors.md)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Try this project
|
|
26
|
+
|
|
27
|
+
[Download this project](/downloads/native-pytorch.zip), then extract the archive in an empty working folder. It contains the checked source, configuration, and generated specs. [Install August](../../getting-started.md) once, then run these commands. Native libraries are prepared automatically when needed:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
cd native-pytorch
|
|
31
|
+
aug install .
|
|
32
|
+
aug check .
|
|
33
|
+
aug spec .
|
|
34
|
+
aug test .
|
|
35
|
+
aug run .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
[Browse all examples](../index.md)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "main.aug · CPU tensors with PyTorch"
|
|
3
|
+
generated: true
|
|
4
|
+
source: "examples/native-pytorch/main.aug"
|
|
5
|
+
editLink: false
|
|
6
|
+
prev: false
|
|
7
|
+
next: false
|
|
8
|
+
outline: [2, 3]
|
|
9
|
+
pageClass: aug-example-page
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# `main.aug`
|
|
13
|
+
|
|
14
|
+
[CPU tensors with PyTorch](index.md) · Source and specification
|
|
15
|
+
|
|
16
|
+
::: details Files in this project
|
|
17
|
+
|
|
18
|
+
- [`main.aug`](main.md)
|
|
19
|
+
- [`tensors.aug`](tensors.md)
|
|
20
|
+
|
|
21
|
+
:::
|
|
22
|
+
|
|
23
|
+
::::: example-compare
|
|
24
|
+
|
|
25
|
+
:::: example-code
|
|
26
|
+
|
|
27
|
+
## Code {#code}
|
|
28
|
+
|
|
29
|
+
::: code-group
|
|
30
|
+
|
|
31
|
+
```aug [Indentation]
|
|
32
|
+
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
33
|
+
import calculate from tensors
|
|
34
|
+
import TensorError from "https://github.com/GreenPandaStudios/aug-pytorch#v0.1.4"
|
|
35
|
+
try:
|
|
36
|
+
print(value=calculate())
|
|
37
|
+
catch TensorError error:
|
|
38
|
+
print(value=error.message)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```aug [Braces]
|
|
42
|
+
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
43
|
+
import calculate from tensors
|
|
44
|
+
import TensorError from "https://github.com/GreenPandaStudios/aug-pytorch#v0.1.4"
|
|
45
|
+
try {
|
|
46
|
+
print(value=calculate())
|
|
47
|
+
}
|
|
48
|
+
catch TensorError error {
|
|
49
|
+
print(value=error.message)
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
:::
|
|
54
|
+
|
|
55
|
+
::::
|
|
56
|
+
|
|
57
|
+
:::: example-spec
|
|
58
|
+
|
|
59
|
+
## Compiled specification {#specification}
|
|
60
|
+
|
|
61
|
+
### Startup
|
|
62
|
+
|
|
63
|
+
It prints [`calculate`](tensors.md#symbol-calculate). If this work raises [`TensorError`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/contracts.md#symbol-TensorError) as `error`, it prints `error.message`.
|
|
64
|
+
|
|
65
|
+
### Dependencies
|
|
66
|
+
|
|
67
|
+
It uses [`TensorError`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/contracts.md#symbol-TensorError) (`message`) from `https://github.com/GreenPandaStudios/aug-pytorch#v0.1.4`. It uses [`calculate`](tensors.md#symbol-calculate) from `tensors`.
|
|
68
|
+
|
|
69
|
+
Built-in operations follow the [language reference](https://greenpandastudios.github.io/augscript/language-constructs).
|
|
70
|
+
|
|
71
|
+
::::
|
|
72
|
+
|
|
73
|
+
:::::
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "tensors.aug · CPU tensors with PyTorch"
|
|
3
|
+
generated: true
|
|
4
|
+
source: "examples/native-pytorch/tensors.aug"
|
|
5
|
+
editLink: false
|
|
6
|
+
prev: false
|
|
7
|
+
next: false
|
|
8
|
+
outline: [2, 3]
|
|
9
|
+
pageClass: aug-example-page
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# `tensors.aug`
|
|
13
|
+
|
|
14
|
+
[CPU tensors with PyTorch](index.md) · Source and specification
|
|
15
|
+
|
|
16
|
+
::: details Files in this project
|
|
17
|
+
|
|
18
|
+
- [`main.aug`](main.md)
|
|
19
|
+
- [`tensors.aug`](tensors.md)
|
|
20
|
+
|
|
21
|
+
:::
|
|
22
|
+
|
|
23
|
+
::::: example-compare
|
|
24
|
+
|
|
25
|
+
:::: example-code
|
|
26
|
+
|
|
27
|
+
## Code {#code}
|
|
28
|
+
|
|
29
|
+
::: code-group
|
|
30
|
+
|
|
31
|
+
```aug [Indentation]
|
|
32
|
+
// aug-spec: "tensors.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
33
|
+
import Tensor and TensorError and tensor and add and sum and values from "https://github.com/GreenPandaStudios/aug-pytorch#v0.1.4"
|
|
34
|
+
/** Add two CPU tensors using LibTorch and return the sum of their elements. */
|
|
35
|
+
calculate() returns float unless TensorError:
|
|
36
|
+
own Tensor left = tensor(values=[1.0, 2.0, 3.0])
|
|
37
|
+
own Tensor right = tensor(values=[4.0, 5.0, 6.0])
|
|
38
|
+
own Tensor result = add(left, right)
|
|
39
|
+
return sum(tensor=result)
|
|
40
|
+
test calculate:
|
|
41
|
+
when "cpu":
|
|
42
|
+
it "adds_and_reads_real_tensors":
|
|
43
|
+
own Tensor left = tensor(values=[1.0, 2.0, 3.0])
|
|
44
|
+
own Tensor right = tensor(values=[4.0, 5.0, 6.0])
|
|
45
|
+
own Tensor result = add(left, right)
|
|
46
|
+
List<float> output = values(tensor=result)
|
|
47
|
+
assert(output.length() == 3)
|
|
48
|
+
assert(output.get(index=0) == 5.0)
|
|
49
|
+
assert(output.get(index=1) == 7.0)
|
|
50
|
+
assert(output.get(index=2) == 9.0)
|
|
51
|
+
assert(sum(tensor=result) == 21.0)
|
|
52
|
+
assert(calculate() == 21.0)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```aug [Braces]
|
|
56
|
+
// aug-spec: "tensors.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
57
|
+
import Tensor and TensorError and tensor and add and sum and values from "https://github.com/GreenPandaStudios/aug-pytorch#v0.1.4"
|
|
58
|
+
/** Add two CPU tensors using LibTorch and return the sum of their elements. */
|
|
59
|
+
calculate() returns float unless TensorError {
|
|
60
|
+
own Tensor left = tensor(values=[1.0, 2.0, 3.0])
|
|
61
|
+
own Tensor right = tensor(values=[4.0, 5.0, 6.0])
|
|
62
|
+
own Tensor result = add(left, right)
|
|
63
|
+
return sum(tensor=result)
|
|
64
|
+
}
|
|
65
|
+
test calculate {
|
|
66
|
+
when "cpu" {
|
|
67
|
+
it "adds_and_reads_real_tensors" {
|
|
68
|
+
own Tensor left = tensor(values=[1.0, 2.0, 3.0])
|
|
69
|
+
own Tensor right = tensor(values=[4.0, 5.0, 6.0])
|
|
70
|
+
own Tensor result = add(left, right)
|
|
71
|
+
List<float> output = values(tensor=result)
|
|
72
|
+
assert(output.length() == 3)
|
|
73
|
+
assert(output.get(index=0) == 5.0)
|
|
74
|
+
assert(output.get(index=1) == 7.0)
|
|
75
|
+
assert(output.get(index=2) == 9.0)
|
|
76
|
+
assert(sum(tensor=result) == 21.0)
|
|
77
|
+
assert(calculate() == 21.0)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
:::
|
|
84
|
+
|
|
85
|
+
::::
|
|
86
|
+
|
|
87
|
+
:::: example-spec
|
|
88
|
+
|
|
89
|
+
## Compiled specification {#specification}
|
|
90
|
+
|
|
91
|
+
### `calculate` · [source](tensors.md#code) {#symbol-calculate}
|
|
92
|
+
|
|
93
|
+
Add two CPU tensors using LibTorch and return the sum of their elements. Failures can raise [`TensorError`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/contracts.md#symbol-TensorError).
|
|
94
|
+
|
|
95
|
+
It sets `left` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) to [`tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-tensor) with `values` from a list containing `1.0`, `2.0`, `3.0`. `left` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) owns this value. It sets `right` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) to [`tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-tensor) with `values` from a list containing `4.0`, `5.0`, `6.0`. `right` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) owns this value.
|
|
96
|
+
|
|
97
|
+
It sets `result` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) to [`add`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-add) with `left` and `right`. `result` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) owns this value. It returns [`sum`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-sum) with `tensor` from `result`.
|
|
98
|
+
|
|
99
|
+
### `test calculate` · [source](tensors.md#code) {#symbol-test-20-calculate}
|
|
100
|
+
|
|
101
|
+
Tests [`calculate`](tensors.md#symbol-calculate). Each case gets fresh setup and dependencies.
|
|
102
|
+
|
|
103
|
+
#### `cpu`
|
|
104
|
+
|
|
105
|
+
##### `adds_and_reads_real_tensors` · [source](tensors.md#code)
|
|
106
|
+
|
|
107
|
+
It sets `left` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) to [`tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-tensor) with `values` from a list containing `1.0`, `2.0`, `3.0`. `left` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) owns this value. It sets `right` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) to [`tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-tensor) with `values` from a list containing `4.0`, `5.0`, `6.0`. `right` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) owns this value.
|
|
108
|
+
|
|
109
|
+
It sets `result` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) to [`add`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-add) with `left` and `right`. `result` of type [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor) owns this value. It sets `output` of type `List<float>` to [`values`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-values) with `tensor` from `result`. The test requires the number of elements in `output` equals `3`.
|
|
110
|
+
|
|
111
|
+
The test requires the item at index `0` in `output` equals `5.0`. The test requires the item at index `1` in `output` equals `7.0`. The test requires the item at index `2` in `output` equals `9.0`. The test requires [`sum`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-sum) with `tensor` from `result` equals `21.0`.
|
|
112
|
+
|
|
113
|
+
The test requires [`calculate`](tensors.md#symbol-calculate) equals `21.0`.
|
|
114
|
+
|
|
115
|
+
### Dependencies
|
|
116
|
+
|
|
117
|
+
It uses [`add`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-add), [`sum`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-sum), [`tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-tensor), [`values`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/api.md#symbol-values), [`Tensor`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/bindings.md#symbol-Tensor), and [`TensorError`](dependencies/packages/%40greenpandastudios/aug-pytorch/0.1.4/contracts.md#symbol-TensorError) from `https://github.com/GreenPandaStudios/aug-pytorch#v0.1.4`.
|
|
118
|
+
|
|
119
|
+
Built-in operations follow the [language reference](https://greenpandastudios.github.io/augscript/language-constructs).
|
|
120
|
+
|
|
121
|
+
::::
|
|
122
|
+
|
|
123
|
+
:::::
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "database.aug · A database with SQLite"
|
|
3
|
+
generated: true
|
|
4
|
+
source: "examples/native-sqlite/database.aug"
|
|
5
|
+
editLink: false
|
|
6
|
+
prev: false
|
|
7
|
+
next: false
|
|
8
|
+
outline: [2, 3]
|
|
9
|
+
pageClass: aug-example-page
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# `database.aug`
|
|
13
|
+
|
|
14
|
+
[A database with SQLite](index.md) · Source and specification
|
|
15
|
+
|
|
16
|
+
::: details Files in this project
|
|
17
|
+
|
|
18
|
+
- [`main.aug`](main.md)
|
|
19
|
+
- [`database.aug`](database.md)
|
|
20
|
+
|
|
21
|
+
:::
|
|
22
|
+
|
|
23
|
+
::::: example-compare
|
|
24
|
+
|
|
25
|
+
:::: example-code
|
|
26
|
+
|
|
27
|
+
## Code {#code}
|
|
28
|
+
|
|
29
|
+
::: code-group
|
|
30
|
+
|
|
31
|
+
```aug [Indentation]
|
|
32
|
+
// aug-spec: "database.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
33
|
+
import Database and SqliteError and openMemory and execute and queryScalar from "https://github.com/GreenPandaStudios/aug-sqlite#v0.1.3"
|
|
34
|
+
/** Store a bound value in an in-memory SQLite database and read it back. */
|
|
35
|
+
storedName() returns string unless SqliteError:
|
|
36
|
+
own Database database = openMemory()
|
|
37
|
+
borrow database:
|
|
38
|
+
execute(
|
|
39
|
+
database,
|
|
40
|
+
sql="CREATE TABLE users (name TEXT NOT NULL)",
|
|
41
|
+
parameters=[]
|
|
42
|
+
)
|
|
43
|
+
execute(
|
|
44
|
+
database,
|
|
45
|
+
sql="INSERT INTO users (name) VALUES (?)",
|
|
46
|
+
parameters=["August"]
|
|
47
|
+
)
|
|
48
|
+
return queryScalar(database, sql="SELECT name FROM users", parameters=[])
|
|
49
|
+
test storedName:
|
|
50
|
+
when "database":
|
|
51
|
+
it "inserts_and_queries_bound_data":
|
|
52
|
+
assert(storedName() == "August")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```aug [Braces]
|
|
56
|
+
// aug-spec: "database.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
57
|
+
import Database and SqliteError and openMemory and execute and queryScalar from "https://github.com/GreenPandaStudios/aug-sqlite#v0.1.3"
|
|
58
|
+
/** Store a bound value in an in-memory SQLite database and read it back. */
|
|
59
|
+
storedName() returns string unless SqliteError {
|
|
60
|
+
own Database database = openMemory()
|
|
61
|
+
borrow database {
|
|
62
|
+
execute(
|
|
63
|
+
database,
|
|
64
|
+
sql="CREATE TABLE users (name TEXT NOT NULL)",
|
|
65
|
+
parameters=[]
|
|
66
|
+
)
|
|
67
|
+
execute(
|
|
68
|
+
database,
|
|
69
|
+
sql="INSERT INTO users (name) VALUES (?)",
|
|
70
|
+
parameters=["August"]
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
return queryScalar(database, sql="SELECT name FROM users", parameters=[])
|
|
74
|
+
}
|
|
75
|
+
test storedName {
|
|
76
|
+
when "database" {
|
|
77
|
+
it "inserts_and_queries_bound_data" {
|
|
78
|
+
assert(storedName() == "August")
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
:::
|
|
85
|
+
|
|
86
|
+
::::
|
|
87
|
+
|
|
88
|
+
:::: example-spec
|
|
89
|
+
|
|
90
|
+
## Compiled specification {#specification}
|
|
91
|
+
|
|
92
|
+
### `storedName` · [source](database.md#code) {#symbol-storedName}
|
|
93
|
+
|
|
94
|
+
Store a bound value in an in-memory SQLite database and read it back. Failures can raise [`SqliteError`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/contracts.md#symbol-SqliteError).
|
|
95
|
+
|
|
96
|
+
It gets `database` of type [`Database`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/bindings.md#symbol-Database) from [`openMemory`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-openMemory). `database` of type [`Database`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/bindings.md#symbol-Database) owns this value. With temporary permission to change `database`, it calls [`execute`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-execute) with `database`, `sql` `"CREATE TABLE users (name TEXT NOT NULL)"`, and `parameters` from a list with no items; then it calls [`execute`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-execute) with `database`, `sql` `"INSERT INTO users (name) VALUES (?)"`, and `parameters` from a list containing `"August"`. It returns [`queryScalar`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-queryScalar) with `database`, `sql` `"SELECT name FROM users"`, and `parameters` from a list with no items.
|
|
97
|
+
|
|
98
|
+
### `test storedName` · [source](database.md#code) {#symbol-test-20-storedName}
|
|
99
|
+
|
|
100
|
+
Tests [`storedName`](database.md#symbol-storedName). Each case gets fresh setup and dependencies.
|
|
101
|
+
|
|
102
|
+
#### `database`
|
|
103
|
+
|
|
104
|
+
##### `inserts_and_queries_bound_data` · [source](database.md#code)
|
|
105
|
+
|
|
106
|
+
The test requires [`storedName`](database.md#symbol-storedName) equals `"August"`.
|
|
107
|
+
|
|
108
|
+
### Dependencies
|
|
109
|
+
|
|
110
|
+
It uses [`execute`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-execute), [`openMemory`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-openMemory), [`queryScalar`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/api.md#symbol-queryScalar), [`Database`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/bindings.md#symbol-Database), and [`SqliteError`](dependencies/packages/%40greenpandastudios/aug-sqlite/0.1.3/contracts.md#symbol-SqliteError) from `https://github.com/GreenPandaStudios/aug-sqlite#v0.1.3`.
|
|
111
|
+
|
|
112
|
+
Built-in operations follow the [language reference](https://greenpandastudios.github.io/augscript/language-constructs).
|
|
113
|
+
|
|
114
|
+
::::
|
|
115
|
+
|
|
116
|
+
:::::
|
package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/api.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug · A database with SQLite"
|
|
3
|
+
generated: true
|
|
4
|
+
source: "examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug"
|
|
5
|
+
editLink: false
|
|
6
|
+
prev: false
|
|
7
|
+
next: false
|
|
8
|
+
outline: [2, 3]
|
|
9
|
+
search: false
|
|
10
|
+
pageClass: aug-example-page
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# `packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug`
|
|
14
|
+
|
|
15
|
+
[A database with SQLite](../../../../../index.md) · Dependency source and specification
|
|
16
|
+
|
|
17
|
+
This is the exact dependency version used by this example.
|
|
18
|
+
|
|
19
|
+
::::: example-compare
|
|
20
|
+
|
|
21
|
+
:::: example-code
|
|
22
|
+
|
|
23
|
+
## Code {#code}
|
|
24
|
+
|
|
25
|
+
::: code-group
|
|
26
|
+
|
|
27
|
+
```aug [Indentation]
|
|
28
|
+
// aug-spec: "api.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
29
|
+
import Database from bindings
|
|
30
|
+
import SqliteError and DatabaseStorage from contracts
|
|
31
|
+
extern C _open(string path) returns own Database unless SqliteError
|
|
32
|
+
extern C _execute(borrow Database database, string sql, List<string> parameters) returns int changes database unless SqliteError
|
|
33
|
+
extern C _queryScalar(Database database, string sql, List<string> parameters) returns string unless SqliteError
|
|
34
|
+
/** Open a serialized connection. Use :memory: for an in-memory database. */
|
|
35
|
+
NativeDatabaseStorage() implements DatabaseStorage:
|
|
36
|
+
open(string path) returns own Database:
|
|
37
|
+
unsafe:
|
|
38
|
+
return _open(path)
|
|
39
|
+
open(resolve DatabaseStorage storage, string path) returns own Database:
|
|
40
|
+
return storage.open(path)
|
|
41
|
+
/** Open an in-memory database without filesystem permission. */
|
|
42
|
+
openMemory() returns own Database:
|
|
43
|
+
unsafe:
|
|
44
|
+
return _open(path=":memory:")
|
|
45
|
+
/** Execute one parameterized statement. Return the number of changed rows. */
|
|
46
|
+
execute(borrow Database database, string sql, List<string> parameters) returns int:
|
|
47
|
+
unsafe:
|
|
48
|
+
return _execute(database, sql, parameters)
|
|
49
|
+
/** Query one non-null text value with SELECT. Reject PRAGMAs, transactions, savepoints and writes before execution. Copy the result before finalization. */
|
|
50
|
+
queryScalar(Database database, string sql, List<string> parameters) returns string:
|
|
51
|
+
unsafe:
|
|
52
|
+
return _queryScalar(database, sql, parameters)
|
|
53
|
+
test openMemory:
|
|
54
|
+
when "databases":
|
|
55
|
+
it "binds_and_queries":
|
|
56
|
+
own Database database = openMemory()
|
|
57
|
+
borrow database:
|
|
58
|
+
execute(
|
|
59
|
+
database,
|
|
60
|
+
sql="CREATE TABLE users (name TEXT NOT NULL)",
|
|
61
|
+
parameters=[]
|
|
62
|
+
)
|
|
63
|
+
execute(
|
|
64
|
+
database,
|
|
65
|
+
sql="INSERT INTO users (name) VALUES (?)",
|
|
66
|
+
parameters=["O'Reilly"]
|
|
67
|
+
)
|
|
68
|
+
assert(
|
|
69
|
+
queryScalar(database, sql="SELECT name FROM users", parameters=[]) == "O'Reilly"
|
|
70
|
+
)
|
|
71
|
+
it "rejects_connection_and_transaction_control":
|
|
72
|
+
own Database database = openMemory()
|
|
73
|
+
for statement in [
|
|
74
|
+
"PRAGMA query_only=ON",
|
|
75
|
+
"BEGIN",
|
|
76
|
+
"COMMIT",
|
|
77
|
+
"ROLLBACK",
|
|
78
|
+
"SAVEPOINT hidden"
|
|
79
|
+
]:
|
|
80
|
+
rejected = false
|
|
81
|
+
try:
|
|
82
|
+
queryScalar(database, sql=statement, parameters=[])
|
|
83
|
+
catch SqliteError error:
|
|
84
|
+
rejected = error.code == 23
|
|
85
|
+
assert(rejected)
|
|
86
|
+
borrow database:
|
|
87
|
+
execute(
|
|
88
|
+
database,
|
|
89
|
+
sql="CREATE TABLE rows (value TEXT)",
|
|
90
|
+
parameters=[]
|
|
91
|
+
)
|
|
92
|
+
execute(
|
|
93
|
+
database,
|
|
94
|
+
sql="INSERT INTO rows VALUES (?)",
|
|
95
|
+
parameters=["unchanged"]
|
|
96
|
+
)
|
|
97
|
+
assert(
|
|
98
|
+
queryScalar(database, sql="SELECT value FROM rows", parameters=[]) == "unchanged"
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```aug [Braces]
|
|
103
|
+
// aug-spec: "api.aug.md" explains this file. Read it before changes; refresh with aug spec.
|
|
104
|
+
import Database from bindings
|
|
105
|
+
import SqliteError and DatabaseStorage from contracts
|
|
106
|
+
extern C _open(string path) returns own Database unless SqliteError
|
|
107
|
+
extern C _execute(borrow Database database, string sql, List<string> parameters) returns int changes database unless SqliteError
|
|
108
|
+
extern C _queryScalar(Database database, string sql, List<string> parameters) returns string unless SqliteError
|
|
109
|
+
/** Open a serialized connection. Use :memory: for an in-memory database. */
|
|
110
|
+
NativeDatabaseStorage() implements DatabaseStorage {
|
|
111
|
+
open(string path) returns own Database {
|
|
112
|
+
unsafe {
|
|
113
|
+
return _open(path)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
open(resolve DatabaseStorage storage, string path) returns own Database {
|
|
118
|
+
return storage.open(path)
|
|
119
|
+
}
|
|
120
|
+
/** Open an in-memory database without filesystem permission. */
|
|
121
|
+
openMemory() returns own Database {
|
|
122
|
+
unsafe {
|
|
123
|
+
return _open(path=":memory:")
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Execute one parameterized statement. Return the number of changed rows. */
|
|
127
|
+
execute(borrow Database database, string sql, List<string> parameters) returns int {
|
|
128
|
+
unsafe {
|
|
129
|
+
return _execute(database, sql, parameters)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Query one non-null text value with SELECT. Reject PRAGMAs, transactions, savepoints and writes before execution. Copy the result before finalization. */
|
|
133
|
+
queryScalar(Database database, string sql, List<string> parameters) returns string {
|
|
134
|
+
unsafe {
|
|
135
|
+
return _queryScalar(database, sql, parameters)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
test openMemory {
|
|
139
|
+
when "databases" {
|
|
140
|
+
it "binds_and_queries" {
|
|
141
|
+
own Database database = openMemory()
|
|
142
|
+
borrow database {
|
|
143
|
+
execute(
|
|
144
|
+
database,
|
|
145
|
+
sql="CREATE TABLE users (name TEXT NOT NULL)",
|
|
146
|
+
parameters=[]
|
|
147
|
+
)
|
|
148
|
+
execute(
|
|
149
|
+
database,
|
|
150
|
+
sql="INSERT INTO users (name) VALUES (?)",
|
|
151
|
+
parameters=["O'Reilly"]
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
assert(
|
|
155
|
+
queryScalar(database, sql="SELECT name FROM users", parameters=[]) == "O'Reilly"
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
it "rejects_connection_and_transaction_control" {
|
|
159
|
+
own Database database = openMemory()
|
|
160
|
+
for statement in [
|
|
161
|
+
"PRAGMA query_only=ON",
|
|
162
|
+
"BEGIN",
|
|
163
|
+
"COMMIT",
|
|
164
|
+
"ROLLBACK",
|
|
165
|
+
"SAVEPOINT hidden"
|
|
166
|
+
] {
|
|
167
|
+
rejected = false
|
|
168
|
+
try {
|
|
169
|
+
queryScalar(database, sql=statement, parameters=[])
|
|
170
|
+
}
|
|
171
|
+
catch SqliteError error {
|
|
172
|
+
rejected = error.code == 23
|
|
173
|
+
}
|
|
174
|
+
assert(rejected)
|
|
175
|
+
}
|
|
176
|
+
borrow database {
|
|
177
|
+
execute(
|
|
178
|
+
database,
|
|
179
|
+
sql="CREATE TABLE rows (value TEXT)",
|
|
180
|
+
parameters=[]
|
|
181
|
+
)
|
|
182
|
+
execute(
|
|
183
|
+
database,
|
|
184
|
+
sql="INSERT INTO rows VALUES (?)",
|
|
185
|
+
parameters=["unchanged"]
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
assert(
|
|
189
|
+
queryScalar(database, sql="SELECT value FROM rows", parameters=[]) == "unchanged"
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
:::
|
|
197
|
+
|
|
198
|
+
::::
|
|
199
|
+
|
|
200
|
+
:::: example-spec
|
|
201
|
+
|
|
202
|
+
## Compiled specification {#specification}
|
|
203
|
+
|
|
204
|
+
### `NativeDatabaseStorage` · class · [source](api.md#code) {#symbol-NativeDatabaseStorage}
|
|
205
|
+
|
|
206
|
+
Open a serialized connection. Use :memory: for an in-memory database. It implements [`DatabaseStorage`](contracts.md#symbol-DatabaseStorage).
|
|
207
|
+
|
|
208
|
+
#### `NativeDatabaseStorage.open` · [source](api.md#code) {#symbol-NativeDatabaseStorage.open}
|
|
209
|
+
|
|
210
|
+
It takes `path` as a string. It returns ownership of [`Database`](bindings.md#symbol-Database). Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError).
|
|
211
|
+
|
|
212
|
+
Within an unsafe block, it returns [`_open`](api.md#symbol-_open) with `path`. Native operations must satisfy their declared C contracts.
|
|
213
|
+
|
|
214
|
+
### `open` · [source](api.md#code) {#symbol-open}
|
|
215
|
+
|
|
216
|
+
It takes `path` as a string. It gets `storage` ([`DatabaseStorage`](contracts.md#symbol-DatabaseStorage)) from dependency injection. It returns ownership of [`Database`](bindings.md#symbol-Database). Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError).
|
|
217
|
+
|
|
218
|
+
It returns [`storage.open`](contracts.md#symbol-DatabaseStorage.open) with `path`.
|
|
219
|
+
|
|
220
|
+
### `openMemory` · [source](api.md#code) {#symbol-openMemory}
|
|
221
|
+
|
|
222
|
+
Open an in-memory database without filesystem permission. It returns ownership of [`Database`](bindings.md#symbol-Database). Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError).
|
|
223
|
+
|
|
224
|
+
Within an unsafe block, it returns [`_open`](api.md#symbol-_open) with `path` `":memory:"`. Native operations must satisfy their declared C contracts.
|
|
225
|
+
|
|
226
|
+
### `execute` · [source](api.md#code) {#symbol-execute}
|
|
227
|
+
|
|
228
|
+
Execute one parameterized statement. Return the number of changed rows. It takes `database` as [`Database`](bindings.md#symbol-Database) with permission to mutate it during the call, `sql` as a string, and `parameters` as `List<string>`.
|
|
229
|
+
|
|
230
|
+
It may change `database`. Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError). Within an unsafe block, it returns [`_execute`](api.md#symbol-_execute) with `database`, `sql`, and `parameters`. Native operations must satisfy their declared C contracts.
|
|
231
|
+
|
|
232
|
+
### `queryScalar` · [source](api.md#code) {#symbol-queryScalar}
|
|
233
|
+
|
|
234
|
+
Query one non-null text value with SELECT. Reject PRAGMAs, transactions, savepoints and writes before execution. Copy the result before finalization. It takes `database` as [`Database`](bindings.md#symbol-Database), `sql` as a string, and `parameters` as `List<string>`.
|
|
235
|
+
|
|
236
|
+
Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError). Within an unsafe block, it returns [`_queryScalar`](api.md#symbol-_queryScalar) with `database`, `sql`, and `parameters`. Native operations must satisfy their declared C contracts.
|
|
237
|
+
|
|
238
|
+
### `_open` · [source](api.md#code) {#symbol-_open}
|
|
239
|
+
|
|
240
|
+
It is private to its defining scope. It takes `path` as a string. It returns ownership of [`Database`](bindings.md#symbol-Database). Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError).
|
|
241
|
+
|
|
242
|
+
Native implementation: `@greenpandastudios/aug-sqlite@0.1.3`, `3.53.4`. Supported targets: linux arm64 glibc 2.36+, linux x64 glibc 2.36+, macos arm64 14.0+. Binding contract: [`native.abi.json`](native.abi-json.md) (SHA-256 `3c75c2925c85f1b83db06ee00fa04f1d2d37c9fd6edca0d074ce89b4647ffffb`). It calls `aug_sqlite_open_v1` through the C ABI on the caller thread; a blocking native call blocks that thread. The caller owns the returned handle. The compiler checks the provider, descriptor digest, signature and ownership at August call sites. The native author promises not to retain inputs, enter August from foreign threads, or unwind across the C boundary; internal native workers may run. The compiler does not prove those promises.
|
|
243
|
+
|
|
244
|
+
### `_execute` · [source](api.md#code) {#symbol-_execute}
|
|
245
|
+
|
|
246
|
+
It is private to its defining scope. It takes `database` as [`Database`](bindings.md#symbol-Database) with permission to mutate it during the call, `sql` as a string, and `parameters` as `List<string>`.
|
|
247
|
+
|
|
248
|
+
It returns `int`. It may change `database`. Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError).
|
|
249
|
+
|
|
250
|
+
Native implementation: `@greenpandastudios/aug-sqlite@0.1.3`, `3.53.4`. Supported targets: linux arm64 glibc 2.36+, linux x64 glibc 2.36+, macos arm64 14.0+. Binding contract: [`native.abi.json`](native.abi-json.md) (SHA-256 `3c75c2925c85f1b83db06ee00fa04f1d2d37c9fd6edca0d074ce89b4647ffffb`). It calls `aug_sqlite_execute_v1` through the C ABI on the caller thread; a blocking native call blocks that thread. `database` lends mutable access for this call. The compiler checks the provider, descriptor digest, signature and ownership at August call sites. The native author promises not to retain inputs, enter August from foreign threads, or unwind across the C boundary; internal native workers may run. The compiler does not prove those promises.
|
|
251
|
+
|
|
252
|
+
### `_queryScalar` · [source](api.md#code) {#symbol-_queryScalar}
|
|
253
|
+
|
|
254
|
+
It is private to its defining scope. It takes `database` as [`Database`](bindings.md#symbol-Database), `sql` as a string, and `parameters` as `List<string>`. It returns `string`. Failures can raise [`SqliteError`](contracts.md#symbol-SqliteError).
|
|
255
|
+
|
|
256
|
+
Native implementation: `@greenpandastudios/aug-sqlite@0.1.3`, `3.53.4`. Supported targets: linux arm64 glibc 2.36+, linux x64 glibc 2.36+, macos arm64 14.0+. Binding contract: [`native.abi.json`](native.abi-json.md) (SHA-256 `3c75c2925c85f1b83db06ee00fa04f1d2d37c9fd6edca0d074ce89b4647ffffb`). It calls `aug_sqlite_scalar_v1` through the C ABI on the caller thread; a blocking native call blocks that thread. `database` lends read access for this call. August copies the returned buffer, then calls `aug_sqlite_text_release_v1` to release it. The compiler checks the provider, descriptor digest, signature and ownership at August call sites. The native author promises not to retain inputs, enter August from foreign threads, or unwind across the C boundary; internal native workers may run. The compiler does not prove those promises.
|
|
257
|
+
|
|
258
|
+
### `test openMemory` · [source](api.md#code) {#symbol-test-20-openMemory}
|
|
259
|
+
|
|
260
|
+
Tests [`openMemory`](api.md#symbol-openMemory). Each case gets fresh setup and dependencies.
|
|
261
|
+
|
|
262
|
+
#### `databases`
|
|
263
|
+
|
|
264
|
+
##### `binds_and_queries` · [source](api.md#code)
|
|
265
|
+
|
|
266
|
+
It gets `database` of type [`Database`](bindings.md#symbol-Database) from [`openMemory`](api.md#symbol-openMemory). `database` of type [`Database`](bindings.md#symbol-Database) owns this value. With temporary permission to change `database`, it calls [`execute`](api.md#symbol-execute) with `database`, `sql` `"CREATE TABLE users (name TEXT NOT NULL)"`, and `parameters` from a list with no items; then it calls [`execute`](api.md#symbol-execute) with `database`, `sql` `"INSERT INTO users (name) VALUES (?)"`, and `parameters` from a list containing `"O'Reilly"`. The test requires [`queryScalar`](api.md#symbol-queryScalar) with `database`, `sql` `"SELECT name FROM users"`, and `parameters` from a list with no items equals `"O'Reilly"`.
|
|
267
|
+
|
|
268
|
+
##### `rejects_connection_and_transaction_control` · [source](api.md#code)
|
|
269
|
+
|
|
270
|
+
It gets `database` of type [`Database`](bindings.md#symbol-Database) from [`openMemory`](api.md#symbol-openMemory). `database` of type [`Database`](bindings.md#symbol-Database) owns this value. For each `statement` in a snapshot of a list containing `"PRAGMA query_only=ON"`, `"BEGIN"`, `"COMMIT"`, `"ROLLBACK"`, `"SAVEPOINT hidden"`, it sets `rejected` to `false`.
|
|
271
|
+
|
|
272
|
+
It tries to call [`queryScalar`](api.md#symbol-queryScalar) with `database`, `sql` from `statement`, and `parameters` from a list with no items. If this work raises [`SqliteError`](contracts.md#symbol-SqliteError) as `error`, it sets `rejected` to `error.code` equals `23`. The test requires `rejected` is true. After the loop, with temporary permission to change `database`, it calls [`execute`](api.md#symbol-execute) with `database`, `sql` `"CREATE TABLE rows (value TEXT)"`, and `parameters` from a list with no items; then it calls [`execute`](api.md#symbol-execute) with `database`, `sql` `"INSERT INTO rows VALUES (?)"`, and `parameters` from a list containing `"unchanged"`.
|
|
273
|
+
|
|
274
|
+
The test requires [`queryScalar`](api.md#symbol-queryScalar) with `database`, `sql` `"SELECT value FROM rows"`, and `parameters` from a list with no items equals `"unchanged"`.
|
|
275
|
+
|
|
276
|
+
### Dependencies
|
|
277
|
+
|
|
278
|
+
It uses [`Database`](bindings.md#symbol-Database) from `bindings`. It uses [`DatabaseStorage`](contracts.md#symbol-DatabaseStorage) ([`open`](contracts.md#symbol-DatabaseStorage.open)) and [`SqliteError`](contracts.md#symbol-SqliteError) from `contracts`.
|
|
279
|
+
|
|
280
|
+
Built-in operations follow the [language reference](https://greenpandastudios.github.io/augscript/language-constructs).
|
|
281
|
+
|
|
282
|
+
::::
|
|
283
|
+
|
|
284
|
+
:::::
|