Rename preinit to init and add more instructions
This commit is contained in:
parent
8c740f3793
commit
8282a299b1
5 changed files with 34 additions and 37 deletions
|
|
@ -318,8 +318,8 @@ pub fn parseModule(self: *Parser) !void {
|
|||
else => return Error.invalid_section,
|
||||
};
|
||||
}
|
||||
if (self.exports.preinit != null and self.exports.preinit.? != 0){
|
||||
self.exports.preinit.? -= self.importCount;
|
||||
if (self.exports.init != null and self.exports.init.? != 0){
|
||||
self.exports.init.? -= self.importCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -385,7 +385,7 @@ fn parseImportsec(self: *Parser) !void {
|
|||
} else if (std.mem.eql(u8, i.name, "logErr")) {
|
||||
self.exports.logErr = index;
|
||||
} else {
|
||||
std.log.warn("imported function {s} not supported\n", .{i.name});
|
||||
std.debug.panic("imported function {s} not supported\n", .{i.name});
|
||||
}
|
||||
index += 1;
|
||||
},
|
||||
|
|
@ -546,8 +546,8 @@ fn parseExportsec(self: *Parser) !void {
|
|||
for (exports) |e| {
|
||||
switch (e.exportdesc) {
|
||||
.func => {
|
||||
if (std.mem.eql(u8, e.name, "preinit")) {
|
||||
self.exports.preinit = e.exportdesc.func;
|
||||
if (std.mem.eql(u8, e.name, "init")) {
|
||||
self.exports.init = e.exportdesc.func;
|
||||
} else {
|
||||
std.log.warn("exported function {s} not supported\n", .{e.name});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ pub const Function = struct { func_type: Functype, typ: union(enum) {
|
|||
} };
|
||||
|
||||
pub const ExportFunction = enum {
|
||||
preinit,
|
||||
init,
|
||||
logErr,
|
||||
logWarn,
|
||||
logInfo,
|
||||
logDebug,
|
||||
};
|
||||
pub const Exports = struct {
|
||||
preinit: ?u32 = null,
|
||||
init: ?u32 = null,
|
||||
logErr: ?u32 = null,
|
||||
logWarn: ?u32 = null,
|
||||
logInfo: ?u32 = null,
|
||||
|
|
@ -372,13 +372,21 @@ pub const Runtime = struct {
|
|||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = @intCast(@as(u1, @bitCast(b > a))) });
|
||||
},
|
||||
.i32_le_s => @panic("UNIMPLEMENTED"),
|
||||
.i32_le_s => {
|
||||
const a = self.stack.pop().?.i32;
|
||||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = @intCast(@as(u1, @bitCast(b <= a))) });
|
||||
},
|
||||
.i32_le_u => {
|
||||
const a = self.stack.pop().?.i32;
|
||||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = @intCast(@as(u1, @bitCast(b <= a))) });
|
||||
},
|
||||
.i32_ge_s => @panic("UNIMPLEMENTED"),
|
||||
.i32_ge_s => {
|
||||
const a = self.stack.pop().?.i32;
|
||||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = @intCast(@as(u1, @bitCast(b >= a))) });
|
||||
},
|
||||
.i32_ge_u => {
|
||||
const a = self.stack.pop().?.i32;
|
||||
const b = self.stack.pop().?.i32;
|
||||
|
|
@ -471,8 +479,16 @@ pub const Runtime = struct {
|
|||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = (b << @as(u5, @intCast(a))) });
|
||||
},
|
||||
.i32_shr_s => @panic("UNIMPLEMENTED"),
|
||||
.i32_shr_u => @panic("UNIMPLEMENTED"),
|
||||
.i32_shr_s => {
|
||||
const a = self.stack.pop().?.i32;
|
||||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = (b >> @as(u5, @intCast(a))) });
|
||||
},
|
||||
.i32_shr_u => {
|
||||
const a = self.stack.pop().?.i32;
|
||||
const b = self.stack.pop().?.i32;
|
||||
try self.stack.append(Value{ .i32 = (b >> @as(u5, @intCast(a))) });
|
||||
},
|
||||
.i32_rotl => @panic("UNIMPLEMENTED"),
|
||||
.i32_rotr => @panic("UNIMPLEMENTED"),
|
||||
|
||||
|
|
@ -581,11 +597,11 @@ pub const Runtime = struct {
|
|||
// TODO: Do name resolution at parseTime
|
||||
pub fn callExternal(self: *Runtime, allocator: Allocator, name: ExportFunction, parameters: []Value) !void {
|
||||
switch (name) {
|
||||
.preinit => {
|
||||
if (self.module.exports.preinit) |func| {
|
||||
.init => {
|
||||
if (self.module.exports.init) |func| {
|
||||
try self.call(allocator, func, parameters);
|
||||
} else {
|
||||
std.debug.panic("Function preinit unavailable\n", .{});
|
||||
std.debug.panic("Function init unavailable\n", .{});
|
||||
}
|
||||
},
|
||||
else => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue