retval = (AstTyped *) this_package;
break;
}
+ else if (parse_possible_directive(parser, "Self")) {
+ if (parser->injection_point == NULL) {
+ onyx_report_error((parser->curr - 2)->pos, Error_Critical, "#Self is only allowed in an #inject block.");
+ }
+
+ retval = parser->injection_point;
+ break;
+ }
onyx_report_error(parser->curr->pos, Error_Critical, "Invalid directive in expression.");
return NULL;
break;
}
+ case '#': {
+ if (parse_possible_directive(parser, "Self")) {
+ if (parser->injection_point == NULL) {
+ onyx_report_error((parser->curr - 2)->pos, Error_Critical, "#Self is only allowed in an #inject block.");
+ }
+
+ *next_insertion = (AstType *) parser->injection_point;
+ next_insertion = NULL;
+ break;
+ }
+ }
+
default:
onyx_report_error(parser->curr->pos, Error_Critical, "unexpected token '%b'.", parser->curr->text, parser->curr->length);
consume_token(parser);
// - REP
// - SET, REP 0
static void debug_emit_instruction(OnyxWasmModule *mod, OnyxToken *token) {
+ if (!context.options->debug_enabled) {
+ return;
+ }
+
DebugContext *ctx = mod->debug_context;
assert(ctx && ctx->last_token);
bh_buffer_append(buffer, WASM_VERSION, 4);
#ifdef ENABLE_DEBUG_INFO
- output_ovm_debug_sections(module, buffer);
+ if (context.options->debug_enabled) {
+ output_ovm_debug_sections(module, buffer);
+ }
#endif
output_typesection(module, buffer);
output_importsection(module, buffer);
//
// Extract the data out of a C pointer into a buffer in the Onyx memory.
- read :: (this: cptr($T)) -> T {
- buf: [sizeof T] u8;
- __cptr_read(this.data, ~~buf, sizeof T);
- return *cast(^T) buf;
+ read :: #match {
+ //
+ // Special, error-inducing case for cptr(void)
+ (this: cptr(void)) -> void { },
+
+ (this: cptr($T)) -> T {
+ buf: [sizeof T] u8;
+ __cptr_read(this.data, ~~buf, sizeof T);
+ return *cast(^T) buf;
+ }
}
//
// to the memory address 0, not the base address for the WASM
// memory.
mem_base_ptr := __cptr_make(cast(rawptr) 1);
- assert(mem_base_ptr <= this.data + 1 && this.data + 1 <= mem_base_ptr + ~~(wasm.memory_size() << 16), "Invalid conversion from cptr to rawptr: pointer value out of Onyx memory range.");
+ assert(mem_base_ptr <= this.data + 1 && (this.data + 1) >> 16 <= mem_base_ptr + ~~(wasm.memory_size()), "Invalid conversion from cptr to rawptr: pointer value out of Onyx memory range.");
return ~~(this.data - mem_base_ptr + 1);
}
+ as :: (this: cptr($T), $new_type: type_expr) -> cptr(new_type) {
+ return .{ this.data };
+ }
+
+ at :: (this: cptr($T), index: i32) -> T {
+ elem := this + index;
+ return elem->read();
+ }
+
format :: (output: ^conv.Format_Output, format: ^conv.Format, p: ^cptr($T)) {
conv.format(output, "cptr({})[0x{b16}]", T, p.data);
}
//
OVMI_INSTR_EXEC(mem_size) {
- VAL(instr->r).u32 = (u32) state->engine->memory_size / 65536;
+ VAL(instr->r).u32 = (u32) (state->engine->memory_size / 65536);
VAL(instr->r).type = OVM_TYPE_I32;
NEXT_OP;
}
OVMI_INSTR_EXEC(mem_grow) {
ovm_assert(VAL(instr->a).type == OVM_TYPE_I32);
VAL(instr->r).type = OVM_TYPE_I32;
- VAL(instr->r).u32 = (u32) state->engine->memory_size / 65536;
+ VAL(instr->r).u32 = (u32) (state->engine->memory_size / 65536);
if (!ovm_engine_memory_ensure_capacity(state->engine,
state->engine->memory_size + VAL(instr->a).u32 * 65536)) {