diff --git a/Resources/Linker.wasm b/Resources/Linker.wasm index 271da95..9e711af 100644 Binary files a/Resources/Linker.wasm and b/Resources/Linker.wasm differ diff --git a/Resources/runtime/constants.br b/Resources/runtime/constants.br index 4261769..44d1c09 100644 --- a/Resources/runtime/constants.br +++ b/Resources/runtime/constants.br @@ -1,4 +1,5 @@ // export const heapOffset: i32 = 0n; import wasm print: (f32) => i32 from 'env'; +const testFunction: Function = (t: i32): i32 => 1n; print(1f); export const True: i32 = 1n; \ No newline at end of file diff --git a/Resources/runtime/constants.wasm b/Resources/runtime/constants.wasm index 61e5f67..9a83a08 100644 Binary files a/Resources/runtime/constants.wasm and b/Resources/runtime/constants.wasm differ diff --git a/src/Linker/index.ts b/src/Linker/index.ts index fcdcd37..7c9247f 100644 --- a/src/Linker/index.ts +++ b/src/Linker/index.ts @@ -12,7 +12,7 @@ import { // addElement, // addExport, // addFunction, - // addGlobal, + addGlobal, // addImport, // addMemory, // addType, @@ -129,12 +129,15 @@ class FileDecoder extends Decoder { functionOffset: number, func: number[] ): Promise { + // Check If Anything may need To Be Mapped + const mayNeedMapping = func.some((byte) => byte == 0x23 || byte == 0x24 || 0x10); // Global.get, Global.set, call + console.log(mayNeedMapping); // Get Names From Parent Function // TODO: Remap Globals // TODO: Remap Calls // const func = createFunction(); // TODO: Return The Function - return createFunction(functionOffset); + // return createFunction(functionOffset); } // Link Function public async link(filePath: string): Promise { @@ -147,6 +150,9 @@ class FileDecoder extends Decoder { let functionCount = 1; // Set to 1 for the New Main Function // For Each Module for (const [importPath, briskImport] of depTree) { + // TODO: Remap External Imports + // TODO: Map Brisk Imports + // TODO: Replace The Function Index // TODO: Combine The Function Tables if (briskImport.tableSection.length != 0) { const tableDecoder = new Decoder(briskImport.tableSection, 1); @@ -156,9 +162,19 @@ class FileDecoder extends Decoder { } // TODO: Move The Table Elements // TODO: Set The Function Offset - // TODO: Resolve Imports // TODO: Rename The Globals And Functions // TODO: Remap Each Function + const codeDecoder = new Decoder(briskImport.codeSection, 0); + const functionCount = codeDecoder.decodeUnSignedLeb128(); + for (let i = 0; i < functionCount; i++) { + const functionSize = codeDecoder.decodeUnSignedLeb128(); + const functionBody = codeDecoder.getCurrentSlice(functionSize); + console.log(functionSize); + console.log(functionBody); + console.log(functionBody.length); + } + // console.log(codeDecoder); + // console.log(functionCount); // TODO: Move Over Data Sections // Combine The Other Parts // TODO: Remap Name Function