flong 0.0.1.dev1__py3-none-any.whl
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.
- flong/__init__.py +90 -0
- flong/flong.wasm +0 -0
- flong/py.typed +0 -0
- flong-0.0.1.dev1.dist-info/METADATA +9 -0
- flong-0.0.1.dev1.dist-info/RECORD +7 -0
- flong-0.0.1.dev1.dist-info/WHEEL +4 -0
- flong-0.0.1.dev1.dist-info/licenses/LICENSE +22 -0
flong/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import struct
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from importlib.resources import files
|
|
4
|
+
|
|
5
|
+
from wasmtime import (
|
|
6
|
+
Caller,
|
|
7
|
+
Engine,
|
|
8
|
+
ExitTrap,
|
|
9
|
+
Func,
|
|
10
|
+
FuncType,
|
|
11
|
+
Linker,
|
|
12
|
+
Memory,
|
|
13
|
+
Module,
|
|
14
|
+
Store,
|
|
15
|
+
ValType,
|
|
16
|
+
WasiConfig,
|
|
17
|
+
WasmtimeError,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class Answered:
|
|
23
|
+
answer: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Refused:
|
|
28
|
+
reason: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Outcome = Answered | Refused
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _parse(memory: object, start: object) -> tuple[Memory, Func]:
|
|
35
|
+
if not isinstance(memory, Memory) or not isinstance(start, Func):
|
|
36
|
+
raise TypeError("flong.wasm exports no memory and _start")
|
|
37
|
+
return memory, start
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def run(request: str) -> Outcome:
|
|
41
|
+
stdin = request.encode()
|
|
42
|
+
offset = 0
|
|
43
|
+
stdout, stderr = bytearray(), bytearray()
|
|
44
|
+
memory: Memory
|
|
45
|
+
|
|
46
|
+
def fd_read(caller: Caller, fd: int, iovs: int, count: int, done: int) -> int:
|
|
47
|
+
nonlocal offset
|
|
48
|
+
total = 0
|
|
49
|
+
for index in range(count):
|
|
50
|
+
at, length = struct.unpack(
|
|
51
|
+
"<II", memory.read(caller, iovs + 8 * index, iovs + 8 * index + 8)
|
|
52
|
+
)
|
|
53
|
+
chunk = stdin[offset : offset + length]
|
|
54
|
+
memory.write(caller, chunk, at)
|
|
55
|
+
offset += len(chunk)
|
|
56
|
+
total += len(chunk)
|
|
57
|
+
memory.write(caller, struct.pack("<I", total), done)
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
engine = Engine()
|
|
61
|
+
linker = Linker(engine)
|
|
62
|
+
linker.allow_shadowing = True
|
|
63
|
+
linker.define_wasi()
|
|
64
|
+
linker.define_func(
|
|
65
|
+
"wasi_snapshot_preview1",
|
|
66
|
+
"fd_read",
|
|
67
|
+
FuncType([ValType.i32()] * 4, [ValType.i32()]),
|
|
68
|
+
fd_read,
|
|
69
|
+
access_caller=True,
|
|
70
|
+
)
|
|
71
|
+
wasi = WasiConfig()
|
|
72
|
+
wasi.stdout_custom = stdout.extend
|
|
73
|
+
wasi.stderr_custom = stderr.extend
|
|
74
|
+
store = Store(engine)
|
|
75
|
+
store.set_wasi(wasi)
|
|
76
|
+
module = Module(engine, (files(__name__) / "flong.wasm").read_bytes())
|
|
77
|
+
exports = linker.instantiate(store, module).exports(store)
|
|
78
|
+
memory, start = _parse(exports["memory"], exports["_start"])
|
|
79
|
+
code = 0
|
|
80
|
+
try:
|
|
81
|
+
start(store)
|
|
82
|
+
except ExitTrap as exited:
|
|
83
|
+
code = exited.code
|
|
84
|
+
except WasmtimeError as fault:
|
|
85
|
+
raise RuntimeError(f"flong: {stderr.decode().strip()}") from fault
|
|
86
|
+
if code == 0:
|
|
87
|
+
return Answered(stdout.decode())
|
|
88
|
+
if code == 1:
|
|
89
|
+
return Refused(stdout.decode())
|
|
90
|
+
raise RuntimeError(f"flong exited {code}: {stderr.decode().strip()}")
|
flong/flong.wasm
ADDED
|
Binary file
|
flong/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: flong
|
|
3
|
+
Version: 0.0.1.dev1
|
|
4
|
+
Summary: flong.wasm and a Python host that sends it one request
|
|
5
|
+
Project-URL: Repository, https://github.com/holon-sh/flong
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: wasmtime<52,>=51
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
flong/__init__.py,sha256=QCASHbFP-ulHIP98uS6um4LK6s_8psZp5baVg8FWD2A,2353
|
|
2
|
+
flong/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
flong/flong.wasm,sha256=ePVb6muW8kHGEQvH6-dHsbIpXNe5sEF_iLwZenTNmFA,397319
|
|
4
|
+
flong-0.0.1.dev1.dist-info/METADATA,sha256=-NYUWx9WLUrH84DB_ENYZBrYofeNBKZmAPvRheyu7Po,279
|
|
5
|
+
flong-0.0.1.dev1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
flong-0.0.1.dev1.dist-info/licenses/LICENSE,sha256=lY_6LhCHAwlhWJ-aCyK--ygY6y7c5PyHnNQd_PmgNzA,1077
|
|
7
|
+
flong-0.0.1.dev1.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Holon Systems, Inc.
|
|
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.
|
|
22
|
+
|