Commit bd5f6b1
committed
add stdlib image extension and import-time extension loading
SPECIFICATION.html
Document IMPORT-time extension loading: interpreter will look for a companion <module>.asmxt next to the resolved module (or in lib/ fallback) and will also check the built-in ext/ directory for a single-file extension <module>.py. Extensions listed/located there are loaded at IMPORT so their operators are immediately available to the importer.
ext/image.py
New standard-library-only image extension providing three operators: LOAD_PNG(path), LOAD_JPEG(path), LOAD_BMP(path) -> TNS[height][width][r,g,b,a].
Prefers Windows GDI+ via ctypes for broad codec support and performance; falls back to pure-Python decoders for non-interlaced 8-bit PNG and uncompressed 24/32-bit BMP on non-Windows platforms. JPEG decoding available only when GDI+ is present.
Performs argument and size validation, converts pixel data into interpreter Tensor/Value objects, and registers operators via the ExtensionAPI.
Includes API version checks and clear error reporting.
interpreter.py
On IMPORT, attempt to load companion .asmxt and builtin ext/<module>.py extensions:
Read .asmxt to gather extension paths and load each extension module.
Validate extension API version and presence of callable asm_lang_register.
Call asm_lang_register(ext_api) and register any new operators into the running interpreter, avoiding duplicate registrations.
ASMExtensionError during extension loading is surfaced as a runtime error; other exceptions are non-fatal and do not prevent importing the module.
Ensures operators provided by extensions are attached to the interpreter at import time so the importer can call them immediately.
lib/
Add lib/image.asmln helper library (ASM-level helpers that accompany the extension).
Add lib/image.asmxt pointer file referencing image.py.
Update lib/path.asmln: add clarifying comments and small fixes to BASEPATH, BASENAME, SPLITEXT, EXTNAME, DELEXT signatures/comments.
test.asmln
Import image library and add a smoke test that loads sample icon.bmp, icon.png and icon.jpg from the interpreter dir and asserts equality (verifies LOAD_BMP/LOAD_PNG/LOAD_JPEG).
assets
Add sample image assets icon.bmp and icon.jpg used by tests.1 parent 0c1ad5e commit bd5f6b1
File tree
10 files changed
+549
-6
lines changed- ext
- lib
10 files changed
+549
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
438 | 449 | | |
439 | 450 | | |
440 | 451 | | |
| |||
Binary file not shown.
0 commit comments