Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: host takes ownership of memory blocks it gets as arguments #90

Merged
merged 8 commits into from
Sep 23, 2024
10 changes: 9 additions & 1 deletion src/call-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class CallContext {
return this.alloc(n);
},

free: (addr: number): void => {
free: (addr: number | bigint): void => {
this.#blocks[Block.addressToIndex(addr)] = null;
},

Expand Down Expand Up @@ -296,6 +296,8 @@ export class CallContext {

const key = item.string();

this[ENV].free(addr);

if (key in this.#config) {
return this.store(this.#config[key]);
}
Expand All @@ -311,6 +313,8 @@ export class CallContext {
}

const key = item.string();
this[ENV].free(addr);

const result = this.getVariable(key);
const stored = result ? this[STORE](result.bytes()) || 0 : 0;
return Block.indexToAddress(stored)
Expand Down Expand Up @@ -380,6 +384,7 @@ export class CallContext {
}
const text = this.#decoder.decode(block.buffer);
this.#logger.warn(text);
this[ENV].free(addr);
},

log_info: (addr: bigint) => {
Expand All @@ -393,6 +398,7 @@ export class CallContext {
}
const text = this.#decoder.decode(block.buffer);
this.#logger.info(text);
this[ENV].free(addr);
},

log_debug: (addr: bigint) => {
Expand All @@ -406,6 +412,7 @@ export class CallContext {
}
const text = this.#decoder.decode(block.buffer);
this.#logger.debug(text);
this[ENV].free(addr);
},

log_error: (addr: bigint) => {
Expand All @@ -419,6 +426,7 @@ export class CallContext {
}
const text = this.#decoder.decode(block.buffer);
this.#logger.error(text);
this[ENV].free(addr);
},
};

Expand Down
Loading