Merge branch 'feature/WASI' into develop
This commit is contained in:
commit
757d762faf
121 files changed
+5394
-270
No files matched your search
@@ -2,3 +2,5 @@
|
|||||||
lib
|
lib
|
||||||
AGENTS.md
|
AGENTS.md
|
||||||
GAP_ANALYSIS.md
|
GAP_ANALYSIS.md
|
||||||
|
*.pdf
|
||||||
|
doc/WASI.md
|
||||||
@@ -4,7 +4,8 @@ param(
|
|||||||
[switch]$Clean,
|
[switch]$Clean,
|
||||||
[switch]$Run,
|
[switch]$Run,
|
||||||
[switch]$Help,
|
[switch]$Help,
|
||||||
[switch]$Debug
|
[switch]$Debug,
|
||||||
|
[switch]$E2E
|
||||||
)
|
)
|
||||||
|
|
||||||
# Also accept positional string args (e.g. .\build.ps1 clean test run)
|
# Also accept positional string args (e.g. .\build.ps1 clean test run)
|
||||||
@@ -15,6 +16,7 @@ foreach ($a in $args) {
|
|||||||
'run' { $Run = $true }
|
'run' { $Run = $true }
|
||||||
'debug' { $Debug = $true }
|
'debug' { $Debug = $true }
|
||||||
'help' { $Help = $true }
|
'help' { $Help = $true }
|
||||||
|
'e2e' { $E2E = $true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ if ($Help) {
|
|||||||
Write-Host ' test - Build with tests enabled'
|
Write-Host ' test - Build with tests enabled'
|
||||||
Write-Host ' clean - Clean build outputs'
|
Write-Host ' clean - Clean build outputs'
|
||||||
Write-Host ' run - Run the built executable after building'
|
Write-Host ' run - Run the built executable after building'
|
||||||
|
Write-Host ' e2e - Run end-to-end wat tests'
|
||||||
Write-Host ' debug - Build with debug info and assertions enabled'
|
Write-Host ' debug - Build with debug info and assertions enabled'
|
||||||
Write-Host ' help - Show this help message'
|
Write-Host ' help - Show this help message'
|
||||||
exit 0
|
exit 0
|
||||||
@@ -35,11 +38,16 @@ $Bin = Join-Path $Root 'bin'
|
|||||||
$Lib = Join-Path $Root 'lib'
|
$Lib = Join-Path $Root 'lib'
|
||||||
$FPC = 'C:\Lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe'
|
$FPC = 'C:\Lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe'
|
||||||
|
|
||||||
|
if (($Test -and $E2E) -or ($Run -and $E2E)) {
|
||||||
|
Write-Host 'Error: --e2e cannot be combined with --test or --run. E2E implies a run of E2E wat tests.' -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# ── Clean ────────────────────────────────────────────────────────────
|
# ── Clean ────────────────────────────────────────────────────────────
|
||||||
if ($Clean) {
|
if ($Clean) {
|
||||||
Write-Host 'Cleaning build outputs...'
|
Write-Host 'Cleaning build outputs...'
|
||||||
if (Test-Path $Bin) { Remove-Item $Bin -Recurse -Force }
|
if (Test-Path $Bin) { Remove-Item "$Bin\*" -Recurse -Force }
|
||||||
if (Test-Path $Lib) { Remove-Item $Lib -Recurse -Force }
|
if (Test-Path $Lib) { Remove-Item "$Lib\*" -Recurse -Force }
|
||||||
Write-Host 'Clean complete.'
|
Write-Host 'Clean complete.'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +65,7 @@ if ($Debug) { $TestFlags += '-dDEBUG_OUTPUT' }
|
|||||||
|
|
||||||
$fpcArgs = @(
|
$fpcArgs = @(
|
||||||
$TestFlags
|
$TestFlags
|
||||||
|
"-v0ew"
|
||||||
"-FE$Bin"
|
"-FE$Bin"
|
||||||
"-FU$Lib"
|
"-FU$Lib"
|
||||||
"-Fu$Src\emu"
|
"-Fu$Src\emu"
|
||||||
@@ -71,13 +80,14 @@ $fpcArgs = @(
|
|||||||
"-Fu$Src\wasm\types"
|
"-Fu$Src\wasm\types"
|
||||||
"-Fu$Src\wasm\vm"
|
"-Fu$Src\wasm\vm"
|
||||||
"-Fu$Src\wasm\vm\opcodes"
|
"-Fu$Src\wasm\vm\opcodes"
|
||||||
|
"-Fu$Src\wasm\wasi"
|
||||||
|
"-Fu$Src\wasm\wasi\preview1"
|
||||||
|
"-Fu$Src\wasm\test\wasi"
|
||||||
'-gw3'
|
'-gw3'
|
||||||
"-o$Bin\WASURO.exe"
|
"-o$Bin\WASURO.exe"
|
||||||
"$Src\project\WASURO.lpr"
|
"$Src\project\WASURO.lpr"
|
||||||
)
|
)
|
||||||
|
|
||||||
Write-Output $fpcArgs
|
|
||||||
|
|
||||||
& $FPC @fpcArgs
|
& $FPC @fpcArgs
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "Build failed with error code $LASTEXITCODE"
|
Write-Host "Build failed with error code $LASTEXITCODE"
|
||||||
@@ -91,3 +101,13 @@ if ($Run) {
|
|||||||
Write-Host 'Running WASURO...'
|
Write-Host 'Running WASURO...'
|
||||||
& "$Bin\WASURO.exe"
|
& "$Bin\WASURO.exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($E2E) {
|
||||||
|
Write-Host 'Running end-to-end WAT tests...'
|
||||||
|
& (Join-Path $Root 'wat.ps1')
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "WAT tests failed with error code $LASTEXITCODE"
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
}
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
unit leb128;
|
|
||||||
|
|
||||||
interface
|
|
||||||
|
|
||||||
uses
|
|
||||||
types;
|
|
||||||
|
|
||||||
function read_leb128_to_uint64(buf : puint8; buf_end : puint8; res : puint64) : uint8;
|
|
||||||
function read_leb128_to_uint32(buf : puint8; buf_end : puint8; res : puint32) : uint8;
|
|
||||||
|
|
||||||
implementation
|
|
||||||
|
|
||||||
function read_leb128_to_uint64(buf: puint8; buf_end: puint8; res: puint64): uint8;
|
|
||||||
var
|
|
||||||
ptr : puint8;
|
|
||||||
shift : uint32;
|
|
||||||
localResult : uint64;
|
|
||||||
currentByte : uint8;
|
|
||||||
|
|
||||||
begin
|
|
||||||
ptr:= buf;
|
|
||||||
shift:= 0;
|
|
||||||
localResult:= 0;
|
|
||||||
while (true) do begin
|
|
||||||
if (ptr >= buf_end) then begin
|
|
||||||
read_leb128_to_uint64:= 0;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
currentByte:= ptr^;
|
|
||||||
inc(ptr);
|
|
||||||
localResult:= localResult or uint64(currentByte and $7F) SHL Shift;
|
|
||||||
if ((currentByte AND $80) = 0) then break;
|
|
||||||
Inc(Shift, 7);
|
|
||||||
end;
|
|
||||||
res^:= localResult;
|
|
||||||
read_leb128_to_uint64:= uint8(ptr - buf);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function read_leb128_to_uint32(buf: puint8; buf_end: puint8; res: puint32): uint8;
|
|
||||||
var
|
|
||||||
ptr : puint8;
|
|
||||||
shift : uint32;
|
|
||||||
localResult : uint32;
|
|
||||||
currentByte : uint8;
|
|
||||||
|
|
||||||
begin
|
|
||||||
ptr:= buf;
|
|
||||||
shift:= 0;
|
|
||||||
localResult:= 0;
|
|
||||||
while (true) do begin
|
|
||||||
if (ptr >= buf_end) then begin
|
|
||||||
read_leb128_to_uint32:= 0;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
currentByte:= ptr^;
|
|
||||||
inc(ptr);
|
|
||||||
localResult:= localResult or uint64(currentByte and $7F) SHL Shift;
|
|
||||||
if ((currentByte AND $80) = 0) then break;
|
|
||||||
Inc(Shift, 7);
|
|
||||||
end;
|
|
||||||
res^:= localResult;
|
|
||||||
read_leb128_to_uint32:= uint8(ptr - buf);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
|
||||||
|
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
{ Emulator-layer WASI OS hook implementations.
|
||||||
|
This unit provides native hook callbacks for running WASI programs
|
||||||
|
on a host OS (Windows/Linux). On bare-metal (Asuro), these would be
|
||||||
|
replaced by kernel-level implementations.
|
||||||
|
|
||||||
|
Hooks are registered per-context via PWASMProcessContext.
|
||||||
|
This unit has NO knowledge of WASM internals (no stacks, no linear memory). }
|
||||||
|
unit wasi.emu.hooks;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
wasm.types.context;
|
||||||
|
|
||||||
|
procedure register_emu_hooks(ctx : PWASMProcessContext);
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
wasm.types.builtin,
|
||||||
|
wasm.wasi.hooks,
|
||||||
|
wasm.types.wasi;
|
||||||
|
|
||||||
|
{ fd_write: write buf to stdout (fd=1) or stderr (fd=2) }
|
||||||
|
function emu_fd_write(fd: TWASMUInt32;
|
||||||
|
buf: TWASMPUInt8;
|
||||||
|
len: TWASMUInt32): TWASMUInt32;
|
||||||
|
var
|
||||||
|
i: TWASMUInt32;
|
||||||
|
begin
|
||||||
|
if (fd = 1) or (fd = 2) then begin
|
||||||
|
for i := 0 to len - 1 do
|
||||||
|
Write(TWASMChar(buf[i]));
|
||||||
|
emu_fd_write := len;
|
||||||
|
end else
|
||||||
|
emu_fd_write := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ fd_read: stub — no stdin support in emu layer yet }
|
||||||
|
function emu_fd_read(fd: TWASMUInt32;
|
||||||
|
buf: TWASMPUInt8;
|
||||||
|
len: TWASMUInt32): TWASMUInt32;
|
||||||
|
begin
|
||||||
|
emu_fd_read := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ fd_close: no-op for emu layer }
|
||||||
|
function emu_fd_close(fd: TWASMUInt32): TWASMUInt32;
|
||||||
|
begin
|
||||||
|
emu_fd_close := 0; { ESUCCESS }
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ proc_exit: halt the program with the given exit code }
|
||||||
|
procedure emu_proc_exit(code: TWASMUInt32);
|
||||||
|
begin
|
||||||
|
{ The glue layer already sets Running := false and ExitCode.
|
||||||
|
On the emu layer, we also halt the host process. }
|
||||||
|
halt(code);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ clock_time_get: return current time in nanoseconds }
|
||||||
|
function emu_clock_time_get(clock_id: TWASMUInt32;
|
||||||
|
precision: TWASMUInt64;
|
||||||
|
var time: TWASMUInt64): TWASMUInt32;
|
||||||
|
begin
|
||||||
|
{ Stub: return 0 nanoseconds. On a real OS we would query the system clock.
|
||||||
|
Bare-metal would use RDTSC or PIT. }
|
||||||
|
time := 0;
|
||||||
|
emu_clock_time_get := WASI_ESUCCESS;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ clock_res_get: return clock resolution in nanoseconds }
|
||||||
|
function emu_clock_res_get(clock_id: TWASMUInt32;
|
||||||
|
var resolution: TWASMUInt64): TWASMUInt32;
|
||||||
|
begin
|
||||||
|
{ Stub: report 1ms resolution }
|
||||||
|
resolution := 1000000;
|
||||||
|
emu_clock_res_get := WASI_ESUCCESS;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ random_get: fill buffer with random bytes }
|
||||||
|
function emu_random_get(buf: TWASMPUInt8;
|
||||||
|
len: TWASMUInt32): TWASMUInt32;
|
||||||
|
var
|
||||||
|
i: TWASMUInt32;
|
||||||
|
state: TWASMUInt32;
|
||||||
|
begin
|
||||||
|
{ Simple xorshift PRNG — not cryptographic, but deterministic
|
||||||
|
and works without RTL. On bare-metal, use RDRAND. }
|
||||||
|
state := 2463534242; { seed }
|
||||||
|
for i := 0 to len - 1 do begin
|
||||||
|
state := state xor (state shl 13);
|
||||||
|
state := state xor (state shr 17);
|
||||||
|
state := state xor (state shl 5);
|
||||||
|
buf[i] := TWASMUInt8(state and $FF);
|
||||||
|
end;
|
||||||
|
emu_random_get := WASI_ESUCCESS;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure register_emu_hooks(ctx : PWASMProcessContext);
|
||||||
|
begin
|
||||||
|
wasm.wasi.hooks.init_hook_table(ctx);
|
||||||
|
wasm.wasi.hooks.register_fd_write(ctx, @emu_fd_write);
|
||||||
|
wasm.wasi.hooks.register_fd_read(ctx, @emu_fd_read);
|
||||||
|
wasm.wasi.hooks.register_fd_close(ctx, @emu_fd_close);
|
||||||
|
wasm.wasi.hooks.register_proc_exit(ctx, @emu_proc_exit);
|
||||||
|
wasm.wasi.hooks.register_clock_time_get(ctx, @emu_clock_time_get);
|
||||||
|
wasm.wasi.hooks.register_clock_res_get(ctx, @emu_clock_res_get);
|
||||||
|
wasm.wasi.hooks.register_random_get(ctx, @emu_random_get);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
+38
-28
@@ -2,14 +2,14 @@ program WASURO;
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
sysutils,
|
sysutils,
|
||||||
|
|
||||||
console,
|
console,
|
||||||
|
|
||||||
wasm.types.builtin,
|
wasm.types.builtin,
|
||||||
wasm.types.context,
|
wasm.types.context,
|
||||||
wasm.types.stack,
|
wasm,
|
||||||
wasm.parser,
|
|
||||||
wasm.vm
|
{ Emu-layer OS hooks }
|
||||||
|
wasi.emu.hooks
|
||||||
|
|
||||||
{$IFDEF RUN_TESTS}
|
{$IFDEF RUN_TESTS}
|
||||||
, wasm.test
|
, wasm.test
|
||||||
, wasm.test.framework
|
, wasm.test.framework
|
||||||
@@ -24,12 +24,15 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF RUN_TESTS}
|
{$IFDEF RUN_TESTS}
|
||||||
wasm.vm.init();
|
wasm.wasm_init;
|
||||||
wasm.test.run_all_tests;
|
wasm.test.run_all_tests;
|
||||||
halt(wasm.test.framework.FailedTests);
|
halt(wasm.test.framework.FailedTests);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
console.writestringln('WASURO - WebAssembly Runtime in Object Pascal');
|
console.writestringln('WASURO - WebAssembly Runtime in Object Pascal');
|
||||||
wasm.vm.init();
|
{$ENDIF}
|
||||||
|
wasm.wasm_init;
|
||||||
|
|
||||||
if ParamCount > 0 then begin
|
if ParamCount > 0 then begin
|
||||||
if not FileExists(ParamStr(1)) then begin
|
if not FileExists(ParamStr(1)) then begin
|
||||||
console.writestringln('File not found.');
|
console.writestringln('File not found.');
|
||||||
@@ -41,28 +44,35 @@ begin
|
|||||||
GetMem(ModuleBuffer, ModuleSize);
|
GetMem(ModuleBuffer, ModuleSize);
|
||||||
BlockRead(ModuleFile, ModuleBuffer^, ModuleSize);
|
BlockRead(ModuleFile, ModuleBuffer^, ModuleSize);
|
||||||
Close(ModuleFile);
|
Close(ModuleFile);
|
||||||
console.writestringln('Module loaded.');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
Context := wasm.parser.parse(ModuleBuffer, TWASMPUInt8(ModuleBuffer + ModuleSize));
|
write('Module loaded from file: ');
|
||||||
while wasm.vm.tick(Context) do ;
|
writeln(ParamStr(1));
|
||||||
console.writestringln('Execution finished.');
|
{$ENDIF}
|
||||||
console.writestringln('');
|
|
||||||
console.writestringln('--- VM State ---');
|
{ Load, configure, and run the WASM module }
|
||||||
writeln('IP: ', Context^.ExecutionState.IP);
|
Context := wasm.wasm_load(ModuleBuffer, TWASMPUInt8(ModuleBuffer + ModuleSize));
|
||||||
writeln('Running: ', Context^.ExecutionState.Running);
|
|
||||||
writeln('');
|
if not Context^.ValidBinary then begin
|
||||||
writeln('Operand Stack (', Context^.ExecutionState.Operand_Stack^.Top, ' entries):');
|
console.writestringln('Error: Invalid WASM binary.');
|
||||||
if Context^.ExecutionState.Operand_Stack^.Top > 0 then
|
halt(1);
|
||||||
wasm.types.stack.walk(Context^.ExecutionState.Operand_Stack)
|
end;
|
||||||
else
|
|
||||||
console.writestringln(' (empty)');
|
{ Register emu-layer OS hooks and WASI preview1 into context }
|
||||||
writeln('');
|
wasi.emu.hooks.register_emu_hooks(Context);
|
||||||
writeln('Control Stack (', Context^.ExecutionState.Control_Stack^.Top, ' entries):');
|
wasm.wasm_register_wasi_preview1(Context);
|
||||||
if Context^.ExecutionState.Control_Stack^.Top > 0 then
|
|
||||||
wasm.types.stack.walk(Context^.ExecutionState.Control_Stack)
|
{ Find _start and run to completion }
|
||||||
else
|
if not wasm.wasm_start(Context) then begin
|
||||||
console.writestringln(' (empty)');
|
console.writestringln('No _start export found.');
|
||||||
console.writestringln('----------------');
|
halt(1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
|
wasm.wasm_dump_state(Context);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
FreeMem(ModuleBuffer);
|
FreeMem(ModuleBuffer);
|
||||||
|
halt(Context^.ExitCode);
|
||||||
end else begin
|
end else begin
|
||||||
console.writestringln('Usage: WASURO <module.wasm>');
|
console.writestringln('Usage: WASURO <module.wasm>');
|
||||||
halt(1);
|
halt(1);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.codeSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.enums, wasm.types.values, wasm.types.sections, wasm.types.context;
|
wasm.types.enums, wasm.types.values, wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.customSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.context;
|
wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMPro
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses console, leb128, lmemorymanager, wasm.types.sections;
|
uses console, wasm.types.leb128, lmemorymanager, wasm.types.sections;
|
||||||
|
|
||||||
{ DataCount section (ID 12): contains a single u32 count of data segments.
|
{ DataCount section (ID 12): contains a single u32 count of data segments.
|
||||||
Pre-allocates the DataSegments array so that bulk memory opcodes
|
Pre-allocates the DataSegments array so that bulk memory opcodes
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.dataSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.sections, wasm.types.context, wasm.types.heap;
|
wasm.types.sections, wasm.types.context, wasm.types.heap;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.elementSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.sections, wasm.types.context;
|
wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.exportSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.functionSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.sections, wasm.types.context;
|
wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.globalSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.importSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.memorySection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.sections, wasm.types.context, wasm.types.heap;
|
wasm.types.sections, wasm.types.context, wasm.types.heap;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.startSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.context;
|
wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.tableSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.sections, wasm.types.context;
|
wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.typeSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.enums, wasm.types.values, wasm.types.sections, wasm.types.context;
|
wasm.types.enums, wasm.types.values, wasm.types.sections, wasm.types.context;
|
||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||||
wasm.types.enums, wasm.types.sections, wasm.types.context, wasm.types.heap, wasm.types.stack,
|
wasm.types.enums, wasm.types.sections, wasm.types.context, wasm.types.heap, wasm.types.stack,
|
||||||
wasm.parser.sections, wasm.types.constants;
|
wasm.parser.sections, wasm.types.constants;
|
||||||
|
|
||||||
@@ -63,6 +63,30 @@ begin
|
|||||||
ctx^.ExecutionState.ElementSegments^.SegmentCount:= 0;
|
ctx^.ExecutionState.ElementSegments^.SegmentCount:= 0;
|
||||||
ctx^.ExecutionState.ElementSegments^.Segments:= nil;
|
ctx^.ExecutionState.ElementSegments^.Segments:= nil;
|
||||||
|
|
||||||
|
// Initialize WASI/import support
|
||||||
|
ctx^.ExitCode := 0;
|
||||||
|
ctx^.ResolvedImports.Count := 0;
|
||||||
|
ctx^.ResolvedImports.Imports := nil;
|
||||||
|
|
||||||
|
// Initialize WASI hooks (all nil)
|
||||||
|
ctx^.WASIHooks.OnFdWrite := nil;
|
||||||
|
ctx^.WASIHooks.OnFdRead := nil;
|
||||||
|
ctx^.WASIHooks.OnFdClose := nil;
|
||||||
|
ctx^.WASIHooks.OnFdSeek := nil;
|
||||||
|
ctx^.WASIHooks.OnProcExit := nil;
|
||||||
|
ctx^.WASIHooks.OnClockTimeGet := nil;
|
||||||
|
ctx^.WASIHooks.OnClockResGet := nil;
|
||||||
|
ctx^.WASIHooks.OnRandomGet := nil;
|
||||||
|
ctx^.WASIHooks.OnArgsSizesGet := nil;
|
||||||
|
ctx^.WASIHooks.OnArgsGet := nil;
|
||||||
|
ctx^.WASIHooks.OnEnvironSizesGet := nil;
|
||||||
|
ctx^.WASIHooks.OnEnvironGet := nil;
|
||||||
|
|
||||||
|
// Initialize host function registry (empty, lazy-init on first register)
|
||||||
|
ctx^.HostFuncRegistry.Count := 0;
|
||||||
|
ctx^.HostFuncRegistry.Capacity := 0;
|
||||||
|
ctx^.HostFuncRegistry.Entries := nil;
|
||||||
|
|
||||||
newContext:= ctx;
|
newContext:= ctx;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loaded 20 of 121 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user