as-labs 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ - Added support for branch hinting
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jairus Tanaka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ <h1 align="center"><pre>
2
+ ╔═╗╔═╗ ╦ ╔═╗╔╗ ╔═╗
3
+ ╠═╣╚═╗══║ ╠═╣╠╩╗╚═╗
4
+ ╩ ╩╚═╝ ╩═╝╩ ╩╚═╝╚═╝</pre></h1>
5
+
6
+ <details>
7
+ <summary>Table of Contents</summary>
8
+
9
+ - [Installation](#installation)
10
+ - [Docs](#docs)
11
+ - [Usage](#usage)
12
+ - [Examples](#examples)
13
+ - [Root Import](#root-import)
14
+ - [Feature-specific Import](#feature-specific-import)
15
+ - [Feature-specific Transform](#feature-specific-transform)
16
+ - [Aggregate Transform](#aggregate-transform)
17
+ - [Debugging](#debugging)
18
+ - [Architecture](#architecture)
19
+ - [Contributing](#contributing)
20
+ - [Who uses it?](#who-uses-it)
21
+ - [License](#license)
22
+ - [Contact](#contact)
23
+
24
+ </details>
25
+
26
+ # Installation
27
+
28
+ ```sh
29
+ npm install as-labs
30
+ ```
31
+
32
+ Add the transform to your `asc` command:
33
+
34
+ ```sh
35
+ asc assembly/index.ts --transform as-labs -o build/module.wasm
36
+ ```
37
+
38
+ If you only want branch hinting, use the feature-specific transform:
39
+
40
+ ```sh
41
+ asc assembly/index.ts --transform as-labs/branch-hinting -o build/module.wasm
42
+ ```
43
+
44
+ # Docs
45
+
46
+ `as-labs` is an experimental AssemblyScript package for unstable APIs, proposal shims, and compiler transforms.
47
+
48
+ The first feature included today is WebAssembly branch hinting. It exposes `likely()` and `unlikely()` helpers and emits the `metadata.code.branch_hint` custom section described by the branch hinting proposal.
49
+
50
+ Available entrypoints:
51
+
52
+ - `as-labs`
53
+ - `as-labs/branch-hinting`
54
+
55
+ Available transform entrypoints:
56
+
57
+ - `as-labs`
58
+ - `as-labs/branch-hinting`
59
+
60
+ Behavior:
61
+
62
+ - `likely()` and `unlikely()` are erased during compilation.
63
+ - The transform emits a single `metadata.code.branch_hint` custom section.
64
+ - Hint offsets are computed from the final emitted wasm.
65
+ - The custom section is inserted before the code section to match the proposal.
66
+ - Statement conditions are supported right now: `if`, `while`, `do`, and `for`.
67
+ - `assume()` is intentionally not included. Branch hints are non-semantic metadata, while `assume()` would change optimizer assumptions.
68
+
69
+ # Usage
70
+
71
+ Import from the root package if you want the default experimental surface:
72
+
73
+ ```ts
74
+ import { likely, unlikely } from "as-labs";
75
+ ```
76
+
77
+ Or import the feature directly if you want an explicit dependency on branch hinting:
78
+
79
+ ```ts
80
+ import { likely, unlikely } from "as-labs/branch-hinting";
81
+ ```
82
+
83
+ Use the helpers as wrappers around branch conditions:
84
+
85
+ ```ts
86
+ if (likely(condition)) {
87
+ // hot path
88
+ }
89
+
90
+ if (unlikely(condition)) {
91
+ // cold path
92
+ }
93
+ ```
94
+
95
+ # Examples
96
+
97
+ ## Root Import
98
+
99
+ ```ts
100
+ import { likely, unlikely } from "as-labs";
101
+
102
+ export function classify(n: i32): i32 {
103
+ if (likely(n > 0)) return 1;
104
+ if (unlikely(n < 0)) return -1;
105
+ return 0;
106
+ }
107
+ ```
108
+
109
+ ## Feature-specific Import
110
+
111
+ ```ts
112
+ import { likely, unlikely } from "as-labs/branch-hinting";
113
+
114
+ export function parse(code: i32): i32 {
115
+ if (likely(code == 200)) return 1;
116
+ if (unlikely(code == 500)) return -1;
117
+ return 0;
118
+ }
119
+ ```
120
+
121
+ ## Feature-specific Transform
122
+
123
+ ```sh
124
+ asc assembly/index.ts --transform as-labs/branch-hinting -o build/module.wasm
125
+ ```
126
+
127
+ ## Aggregate Transform
128
+
129
+ ```sh
130
+ asc assembly/index.ts --transform as-labs -o build/module.wasm
131
+ ```
132
+
133
+ The root transform is an umbrella entrypoint. It calls all feature-scoped transforms that are currently included in `as-labs`.
134
+
135
+ # Debugging
136
+
137
+ If branch hints do not appear to be emitted:
138
+
139
+ - verify the transform is enabled
140
+ - verify the condition is wrapped directly in `likely(...)` or `unlikely(...)`
141
+ - verify you are using statement conditions such as `if`, `while`, `do`, or `for`
142
+ - inspect the final wasm for a `metadata.code.branch_hint` custom section
143
+
144
+ # Architecture
145
+
146
+ The package is split into:
147
+
148
+ - a root AssemblyScript entrypoint
149
+ - feature-specific AssemblyScript entrypoints such as `branch-hinting`
150
+ - a root transform that aggregates all feature transforms
151
+ - feature-specific transforms that own the actual implementation
152
+
153
+ Branch hinting currently works in two phases:
154
+
155
+ 1. collect and erase `likely()` / `unlikely()` calls from the AssemblyScript AST
156
+ 2. read the final emitted wasm, compute real branch instruction offsets, and inject the custom section
157
+
158
+ # Contributing
159
+
160
+ The package is intentionally experimental. Contributions should prefer:
161
+
162
+ - feature isolation by subpath
163
+ - conservative root-transform behavior
164
+ - tests that validate final wasm output, not just AST rewrites
165
+
166
+ # Who uses it?
167
+
168
+ This package is early and experimental. If you are using it, that likely means you are testing proposal support or custom AssemblyScript workflows before they are ready for a more stable package.
169
+
170
+ ## License
171
+
172
+ This project is distributed under an open source license. Work on this project is done by passion, but if you want to support it financially, you can do so by making a donation to the project's [GitHub Sponsors](https://github.com/sponsors/JairusSW) page.
173
+
174
+ You can view the full license using the following link: [License](./LICENSE)
175
+
176
+ ## Contact
177
+
178
+ Please send all issues to [GitHub Issues](https://github.com/JairusSW/as-extensions/issues) and to converse, please send me an email at [me@jairus.dev](mailto:me@jairus.dev)
179
+
180
+ - **Email:** Send me inquiries, questions, or requests at [me@jairus.dev](mailto:me@jairus.dev)
181
+ - **GitHub:** Visit the official GitHub repository [Here](https://github.com/JairusSW/as-extensions)
182
+ - **Website:** Visit my official website at [jairus.dev](https://jairus.dev/)
183
+ - **Discord:** Contact me at [My Discord](https://discord.com/users/600700584038760448) or on the [AssemblyScript Discord Server](https://discord.gg/assemblyscript/)
@@ -0,0 +1,9 @@
1
+ @inline
2
+ export function likely(value: bool): bool {
3
+ return value;
4
+ }
5
+
6
+ @inline
7
+ export function unlikely(value: bool): bool {
8
+ return value;
9
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/branch-hinting/transform/index.js",
3
+ "type": "module",
4
+ "types": "./index.ts"
5
+ }