numbl 0.4.7 → 0.4.8
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/dist-cli/cli.js +238 -9
- package/dist-lib/lib.d.ts +4 -0
- package/dist-lib/lib.js +937 -6
- package/dist-lib/numbl-core/executors/jit/hostHelpers.d.ts +4 -0
- package/dist-lib/numbl-core/fileIOAdapter.d.ts +13 -0
- package/dist-lib/numbl-core/jit/builtins/defs/math/rand.d.ts +2 -0
- package/dist-lib/numbl-core/jitDeclineDiagnostics.d.ts +32 -0
- package/dist-lib/numbl-core/jsUserFunctions.d.ts +13 -0
- package/dist-lib/numbl-core/version.d.ts +1 -1
- package/dist-lib/vfs/BrowserFileIOAdapter.d.ts +54 -0
- package/dist-lib/vfs/BrowserSystemAdapter.d.ts +27 -0
- package/dist-lib/vfs/VirtualFileSystem.d.ts +66 -0
- package/dist-site-viewer/assets/{index-RucHpf4b.js → index-C-wfkZK0.js} +339 -336
- package/dist-site-viewer/assets/{numbl-worker-IO39kohI.js → numbl-worker-Bnbz2rMQ.js} +87 -87
- package/dist-site-viewer/index.html +1 -1
- package/package.json +1 -1
|
@@ -23,5 +23,9 @@ import type { Runtime } from "../../runtime/runtime.js";
|
|
|
23
23
|
export interface JitHostHelpers {
|
|
24
24
|
write: (s: string) => void;
|
|
25
25
|
plotDispatch: (name: string, args: unknown[]) => void;
|
|
26
|
+
/** One uniform double in [0, 1). Backed by numbl's process-global PRNG
|
|
27
|
+
* (the same `rngRandom` the interpreter uses), so JIT'd and interpreted
|
|
28
|
+
* `rand` draw from one shared, `rng(seed)`-controllable stream. */
|
|
29
|
+
rand: () => number;
|
|
26
30
|
}
|
|
27
31
|
export declare function buildHostHelpers(rt: Runtime): JitHostHelpers;
|
|
@@ -15,6 +15,15 @@ export interface WebOptions {
|
|
|
15
15
|
keyName?: string;
|
|
16
16
|
keyValue?: string;
|
|
17
17
|
}
|
|
18
|
+
/** Subset of MATLAB's fileattrib attribute struct. `Name` is the resolved
|
|
19
|
+
* absolute path. */
|
|
20
|
+
export interface FileAttribInfo {
|
|
21
|
+
Name: string;
|
|
22
|
+
directory: boolean;
|
|
23
|
+
UserRead: boolean;
|
|
24
|
+
UserWrite: boolean;
|
|
25
|
+
UserExecute: boolean;
|
|
26
|
+
}
|
|
18
27
|
export interface FileIOAdapter {
|
|
19
28
|
/** Open a file, returns an integer file identifier (fid). */
|
|
20
29
|
fopen(filename: string, permission: string): number;
|
|
@@ -58,6 +67,10 @@ export interface FileIOAdapter {
|
|
|
58
67
|
rmdir?(dirPath: string, recursive: boolean): boolean;
|
|
59
68
|
/** Move or rename a file or folder. If force is true, overwrites read-only files. Returns true on success. Optional. */
|
|
60
69
|
movefile?(source: string, destination: string, force: boolean): boolean;
|
|
70
|
+
/** Copy a file or folder. If force is true, overwrites read-only files. Returns true on success. Optional. */
|
|
71
|
+
copyfile?(source: string, destination: string, force: boolean): boolean;
|
|
72
|
+
/** Resolve a file/dir to its absolute path and attributes, or null if it does not exist. Optional. */
|
|
73
|
+
fileattrib?(path: string): FileAttribInfo | null;
|
|
61
74
|
/** Extract a ZIP file to an output folder. Returns list of extracted file paths. Optional. */
|
|
62
75
|
unzip?(zipfilename: string, outputfolder: string): string[];
|
|
63
76
|
/** Return the temporary directory path. Optional. */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic sink for the most recent JIT decline reason.
|
|
3
|
+
*
|
|
4
|
+
* When a JIT executor cannot compile a unit it catches the
|
|
5
|
+
* `UnsupportedConstruct` / `JitTypeError` thrown during lowering/codegen and
|
|
6
|
+
* declines (returns `null`), letting the dispatcher fall through to the
|
|
7
|
+
* interpreter. That message is normally lost. We stash the most recent one
|
|
8
|
+
* here so a failing `%!numbl:assert_jit` can report *why* the unit declined,
|
|
9
|
+
* not merely that it ran in the interpreter.
|
|
10
|
+
*
|
|
11
|
+
* This is a best-effort, process-global "last decline" — when an assert fires,
|
|
12
|
+
* the unit it guards declined immediately beforehand, so the most recent
|
|
13
|
+
* recorded reason is the relevant one. It is a diagnostic aid, not a precise
|
|
14
|
+
* per-unit binding.
|
|
15
|
+
*
|
|
16
|
+
* Leaf module: no imports, so it can be shared by the executors
|
|
17
|
+
* (`executors/jit/*`) and the interpreter (`interpreter/*`) without cycles.
|
|
18
|
+
*/
|
|
19
|
+
export interface JitDecline {
|
|
20
|
+
/** The thrown error's message (e.g. "unsupported builtin 'rand'"). */
|
|
21
|
+
message: string;
|
|
22
|
+
/** Error class name: "UnsupportedConstruct" | "JitTypeError". */
|
|
23
|
+
kind: string;
|
|
24
|
+
/** Which executor declined: "jit-top-level" | "jit-call" | "jit-loop". */
|
|
25
|
+
where: string;
|
|
26
|
+
}
|
|
27
|
+
/** Record a swallowed JIT decline reason (called from executor catch blocks). */
|
|
28
|
+
export declare function recordJitDecline(d: JitDecline): void;
|
|
29
|
+
/** The most recent recorded JIT decline, or null if none seen. */
|
|
30
|
+
export declare function getLastJitDecline(): JitDecline | null;
|
|
31
|
+
/** Forget the last decline (e.g. so an unrelated stale reason isn't reported). */
|
|
32
|
+
export declare function clearJitDecline(): void;
|
|
@@ -13,6 +13,19 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { WorkspaceFile, NativeBridge } from "./workspace/index.js";
|
|
15
15
|
import type { IBuiltin } from "./interpreter/builtins/types.js";
|
|
16
|
+
/**
|
|
17
|
+
* Per-WASM-instance registry that exposes numbl function handles to WASM as
|
|
18
|
+
* integer ids. A `.numbl.js` apply registers a JS thunk (closing over a
|
|
19
|
+
* handle + `callHandle`) with `add()`, passes the returned id into a WASM
|
|
20
|
+
* export, and removes it once the export returns. Inside WASM the handle is
|
|
21
|
+
* invoked by calling the host-provided `env.numbl_cb_d(id, x)` import.
|
|
22
|
+
*/
|
|
23
|
+
export interface WasmCallbackRegistry {
|
|
24
|
+
/** Register a callback thunk; returns its integer id. */
|
|
25
|
+
add(fn: (...args: number[]) => number): number;
|
|
26
|
+
/** Drop a previously registered callback. */
|
|
27
|
+
remove(id: number): void;
|
|
28
|
+
}
|
|
16
29
|
/** A loaded JS user function ready for registration in the workspace. */
|
|
17
30
|
export interface LoadedJsUserFunction {
|
|
18
31
|
name: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Numbl version, used for JIT disk cache invalidation. */
|
|
2
|
-
export declare const NUMBL_VERSION = "0.4.
|
|
2
|
+
export declare const NUMBL_VERSION = "0.4.8";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser implementation of FileIOAdapter using an in-memory VirtualFileSystem.
|
|
3
|
+
* Mirrors NodeFileIOAdapter patterns from cli-fileio.ts.
|
|
4
|
+
*/
|
|
5
|
+
import type { FileIOAdapter, WebOptions, FileAttribInfo } from "../numbl-core/fileIOAdapter.js";
|
|
6
|
+
import type { WorkspaceFile } from "../numbl-core/workspace/index.js";
|
|
7
|
+
import { VirtualFileSystem, type VfsChanges } from "./VirtualFileSystem.js";
|
|
8
|
+
export declare class BrowserFileIOAdapter implements FileIOAdapter {
|
|
9
|
+
private vfs;
|
|
10
|
+
private nextFid;
|
|
11
|
+
private openFiles;
|
|
12
|
+
constructor(vfs: VirtualFileSystem);
|
|
13
|
+
fopen(filename: string, permission: string): number;
|
|
14
|
+
fclose(fidOrAll: number | "all"): number;
|
|
15
|
+
fgetl(fid: number): string | number;
|
|
16
|
+
fgets(fid: number): string | number;
|
|
17
|
+
fileread(filename: string): string;
|
|
18
|
+
feof(fid: number): number;
|
|
19
|
+
ferror(fid: number): string;
|
|
20
|
+
fwrite(fid: number, text: string): void;
|
|
21
|
+
freadBytes(fid: number, count: number): Uint8Array;
|
|
22
|
+
fwriteBytes(fid: number, data: Uint8Array): number;
|
|
23
|
+
fseek(fid: number, offset: number, origin: number): number;
|
|
24
|
+
ftell(fid: number): number;
|
|
25
|
+
scanDirectory(dirPath: string): WorkspaceFile[];
|
|
26
|
+
resolvePath(dirPath: string): string;
|
|
27
|
+
existsPath(path: string): "file" | "dir" | null;
|
|
28
|
+
mkdir(dirPath: string): boolean;
|
|
29
|
+
tempdir(): string;
|
|
30
|
+
userpath(): string;
|
|
31
|
+
deleteFile(pattern: string): void;
|
|
32
|
+
rmdir(dirPath: string, recursive: boolean): boolean;
|
|
33
|
+
movefile(source: string, destination: string): boolean;
|
|
34
|
+
copyfile(source: string, destination: string): boolean;
|
|
35
|
+
fileattrib(path: string): FileAttribInfo | null;
|
|
36
|
+
listDir(dirPath: string): {
|
|
37
|
+
name: string;
|
|
38
|
+
folder: string;
|
|
39
|
+
bytes: number;
|
|
40
|
+
isdir: boolean;
|
|
41
|
+
mtimeMs: number;
|
|
42
|
+
}[];
|
|
43
|
+
websave(url: string, filename: string, options?: WebOptions): void;
|
|
44
|
+
webread(url: string, options?: WebOptions): string;
|
|
45
|
+
unzip(zipfilename: string, outputfolder: string): string[];
|
|
46
|
+
/** Get the VFS changes for syncing back to the main thread. */
|
|
47
|
+
getChanges(): VfsChanges;
|
|
48
|
+
private getEntry;
|
|
49
|
+
private flushEntry;
|
|
50
|
+
private writeBytes;
|
|
51
|
+
private readLine;
|
|
52
|
+
private listDirGlob;
|
|
53
|
+
private listDirRecursive;
|
|
54
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser implementation of SystemAdapter using in-memory state.
|
|
3
|
+
*
|
|
4
|
+
* The current working directory is delegated to the VFS so that
|
|
5
|
+
* `cd` (system cwd) and relative-path resolution inside the VFS stay
|
|
6
|
+
* in sync. Without this, project files written at "folder1/foo.m"
|
|
7
|
+
* would land under VFS.cwd ("/project") while `cd folder1` would
|
|
8
|
+
* resolve against the system adapter's own root, producing "/folder1"
|
|
9
|
+
* — a directory that contains nothing.
|
|
10
|
+
*/
|
|
11
|
+
import type { SystemAdapter } from "../numbl-core/systemAdapter.js";
|
|
12
|
+
import type { VirtualFileSystem } from "./VirtualFileSystem.js";
|
|
13
|
+
export declare class BrowserSystemAdapter implements SystemAdapter {
|
|
14
|
+
private vars;
|
|
15
|
+
private vfs;
|
|
16
|
+
private fallbackCwd;
|
|
17
|
+
constructor(vfs?: VirtualFileSystem);
|
|
18
|
+
/** Attach (or replace) the VFS used as the cwd source of truth. */
|
|
19
|
+
setVfs(vfs: VirtualFileSystem): void;
|
|
20
|
+
getEnv(name: string): string | undefined;
|
|
21
|
+
getAllEnv(): Record<string, string>;
|
|
22
|
+
setEnv(name: string, value: string): void;
|
|
23
|
+
cwd(): string;
|
|
24
|
+
chdir(dir: string): void;
|
|
25
|
+
platform(): string;
|
|
26
|
+
arch(): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory virtual file system for browser execution.
|
|
3
|
+
* Pure TypeScript — no browser or Node.js APIs.
|
|
4
|
+
* All file content stored as Uint8Array internally.
|
|
5
|
+
*/
|
|
6
|
+
export interface VFSFile {
|
|
7
|
+
content: Uint8Array;
|
|
8
|
+
mtimeMs: number;
|
|
9
|
+
}
|
|
10
|
+
export interface VfsChanges {
|
|
11
|
+
created: {
|
|
12
|
+
path: string;
|
|
13
|
+
content: Uint8Array;
|
|
14
|
+
}[];
|
|
15
|
+
modified: {
|
|
16
|
+
path: string;
|
|
17
|
+
content: Uint8Array;
|
|
18
|
+
}[];
|
|
19
|
+
deleted: string[];
|
|
20
|
+
}
|
|
21
|
+
export declare class VirtualFileSystem {
|
|
22
|
+
private files;
|
|
23
|
+
private directories;
|
|
24
|
+
private cwd;
|
|
25
|
+
private createdFiles;
|
|
26
|
+
private modifiedFiles;
|
|
27
|
+
private deletedFiles;
|
|
28
|
+
/** Clear change tracking. Call after populating the VFS with initial files. */
|
|
29
|
+
clearChangeTracking(): void;
|
|
30
|
+
/** Normalize a path to absolute form. */
|
|
31
|
+
normalizePath(p: string): string;
|
|
32
|
+
getCwd(): string;
|
|
33
|
+
setCwd(dir: string): void;
|
|
34
|
+
readFile(path: string): Uint8Array;
|
|
35
|
+
writeFile(path: string, content: Uint8Array): void;
|
|
36
|
+
deleteFile(path: string): boolean;
|
|
37
|
+
exists(path: string): "file" | "dir" | null;
|
|
38
|
+
fileSize(path: string): number;
|
|
39
|
+
mkdir(dirPath: string): boolean;
|
|
40
|
+
/** Move/rename a file or directory tree. Returns true on success. */
|
|
41
|
+
movefile(source: string, destination: string): boolean;
|
|
42
|
+
/** Copy a file or directory tree (source is left in place). True on success. */
|
|
43
|
+
copyfile(source: string, destination: string): boolean;
|
|
44
|
+
/** Resolve a path to its (normalized) absolute path + attributes, or null. */
|
|
45
|
+
fileattrib(path: string): {
|
|
46
|
+
Name: string;
|
|
47
|
+
directory: boolean;
|
|
48
|
+
UserRead: boolean;
|
|
49
|
+
UserWrite: boolean;
|
|
50
|
+
UserExecute: boolean;
|
|
51
|
+
} | null;
|
|
52
|
+
rmdir(dirPath: string, recursive: boolean): boolean;
|
|
53
|
+
/** List entries in a directory. */
|
|
54
|
+
listDir(dirPath: string): {
|
|
55
|
+
name: string;
|
|
56
|
+
folder: string;
|
|
57
|
+
bytes: number;
|
|
58
|
+
isdir: boolean;
|
|
59
|
+
mtimeMs: number;
|
|
60
|
+
}[];
|
|
61
|
+
/** List all file paths in the VFS. */
|
|
62
|
+
allFiles(): string[];
|
|
63
|
+
/** Get the changes since the VFS was created. */
|
|
64
|
+
getChanges(): VfsChanges;
|
|
65
|
+
private ensureParentDirs;
|
|
66
|
+
}
|