Update code to work with zig master

This commit is contained in:
Sam Tebbs 2020-01-01 19:12:36 +00:00
parent 4b870d3a65
commit 91b2a61acf
26 changed files with 476 additions and 438 deletions

View file

@ -36,47 +36,47 @@ pub const InterruptContext = struct {
};
pub fn outb(port: u16, data: u8) void {
return mock_framework.performAction("outb", void, port, data);
return mock_framework.performAction("outb", void, .{ port, data });
}
pub fn inb(port: u16) u8 {
return mock_framework.performAction("inb", u8, port);
return mock_framework.performAction("inb", u8, .{port});
}
pub fn ioWait() void {
return mock_framework.performAction("ioWait", void);
return mock_framework.performAction("ioWait", void, .{});
}
pub fn lgdt(gdt_ptr: *const gdt.GdtPtr) void {
return mock_framework.performAction("lgdt", void, gdt_ptr);
return mock_framework.performAction("lgdt", void, .{gdt_ptr});
}
pub fn sgdt() gdt.GdtPtr {
return mock_framework.performAction("sgdt", gdt.GdtPtr);
return mock_framework.performAction("sgdt", gdt.GdtPtr, .{});
}
pub fn ltr(offset: u16) void {
return mock_framework.performAction("ltr", void, offset);
return mock_framework.performAction("ltr", void, .{offset});
}
pub fn lidt(idt_ptr: *const idt.IdtPtr) void {
return mock_framework.performAction("lidt", void, idt_ptr);
return mock_framework.performAction("lidt", void, .{idt_ptr});
}
pub fn sidt() idt.IdtPtr {
return mock_framework.performAction("sidt", idt.IdtPtr);
return mock_framework.performAction("sidt", idt.IdtPtr, .{});
}
pub fn enableInterrupts() void {
return mock_framework.performAction("enableInterrupts", void);
return mock_framework.performAction("enableInterrupts", void, .{});
}
pub fn disableInterrupts() void {
return mock_framework.performAction("disableInterrupts", void);
return mock_framework.performAction("disableInterrupts", void, .{});
}
pub fn halt() void {
return mock_framework.performAction("halt", void);
return mock_framework.performAction("halt", void, .{});
}
pub fn spinWait() noreturn {

View file

@ -39,7 +39,7 @@ const NUMBER_OF_ENTRIES: u16 = 256;
const TABLE_SIZE: u16 = @sizeOf(IdtEntry) * NUMBER_OF_ENTRIES - 1;
pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void {
return mock_framework.performAction("openInterruptGate", IdtError!void, index, handler);
return mock_framework.performAction("openInterruptGate", IdtError!void, .{ index, handler });
}
pub fn init() void {

View file

@ -12,22 +12,22 @@ pub const Level = enum {
ERROR,
};
pub fn log(comptime level: Level, comptime format: []const u8, args: ...) void {
pub fn log(comptime level: Level, comptime format: []const u8, args: var) void {
//return mock_framework.performAction("log", void, level, format, args);
}
pub fn logInfo(comptime format: []const u8, args: ...) void {
pub fn logInfo(comptime format: []const u8, args: var) void {
//return mock_framework.performAction("logInfo", void, format, args);
}
pub fn logDebug(comptime format: []const u8, args: ...) void {
pub fn logDebug(comptime format: []const u8, args: var) void {
//return mock_framework.performAction("logDebug", void, format, args);
}
pub fn logWarning(comptime format: []const u8, args: ...) void {
pub fn logWarning(comptime format: []const u8, args: var) void {
//return mock_framework.performAction("logWarning", void, format, args);
}
pub fn logError(comptime format: []const u8, args: ...) void {
pub fn logError(comptime format: []const u8, args: var) void {
//return mock_framework.performAction("logError", void, format, args);
}

View file

@ -6,7 +6,7 @@ pub const MemProfile = struct {
physaddr_end: [*]u8,
physaddr_start: [*]u8,
mem_kb: u32,
fixed_alloc_size: u32
fixed_alloc_size: u32,
};
// The virtual/physical start/end of the kernel code
@ -27,6 +27,6 @@ pub fn init(mb_info: *multiboot.multiboot_info_t) MemProfile {
.physaddr_start = @ptrCast([*]u8, &KERNEL_PHYSADDR_START),
// Total memory available including the initial 1MiB that grub doesn't include
.mem_kb = mb_info.mem_upper + mb_info.mem_lower + 1024,
.fixed_alloc_size = FIXED_ALLOC_SIZE
.fixed_alloc_size = FIXED_ALLOC_SIZE,
};
}

View file

@ -145,7 +145,7 @@ fn Mock() type {
/// A DataElement with the data wrapped.
///
fn createDataElement(arg: var) DataElement {
return switch (@typeOf(arg)) {
return switch (@TypeOf(arg)) {
bool => DataElement{ .BOOL = arg },
u4 => DataElement{ .U4 = arg },
u8 => DataElement{ .U8 = arg },
@ -171,7 +171,7 @@ fn Mock() type {
fn (*const idt.IdtPtr) void => DataElement{ .FN_IPTRCONSTIDTPTR_OVOID = arg },
fn (u8, extern fn () void) idt.IdtError!void => DataElement{ .FN_IU8_IEFNOVOID_OERRORIDTERRORVOID = arg },
fn (u8, nakedcc fn () void) idt.IdtError!void => DataElement{ .FN_IU8_INFNOVOID_OERRORIDTERRORVOID = arg },
else => @compileError("Type not supported: " ++ @typeName(@typeOf(arg))),
else => @compileError("Type not supported: " ++ @typeName(@TypeOf(arg))),
};
}
@ -266,11 +266,11 @@ fn Mock() type {
/// Return: type
/// A function type that represents the return type and its arguments.
///
fn getFunctionType(comptime RetType: type, params: ...) type {
fn getFunctionType(comptime RetType: type, params: var) type {
return switch (params.len) {
0 => fn () RetType,
1 => fn (@typeOf(params[0])) RetType,
2 => fn (@typeOf(params[0]), @typeOf(params[1])) RetType,
1 => fn (@TypeOf(params[0])) RetType,
2 => fn (@TypeOf(params[0]), @TypeOf(params[1])) RetType,
else => @compileError("Couldn't generate function type for " ++ params.len ++ "parameters\n"),
};
}
@ -288,7 +288,7 @@ fn Mock() type {
fn expectTest(comptime ExpectedType: type, expected_value: ExpectedType, elem: DataElement) void {
if (ExpectedType == void) {
// Can't test void as it has no value
std.debug.panic("Can not test a value for void\n");
std.debug.panic("Can not test a value for void\n", .{});
}
// Test that the types match
@ -330,7 +330,7 @@ fn Mock() type {
return ret;
} else {
std.debug.panic("No more test values for the return of function: " ++ fun_name ++ "\n");
std.debug.panic("No more test values for the return of function: " ++ fun_name ++ "\n", .{});
}
}
@ -365,7 +365,7 @@ fn Mock() type {
} else {
// Shouldn't get here as we would have just added a new mapping
// But just in case ;)
std.debug.panic("No function name: " ++ fun_name ++ "\n");
std.debug.panic("No function name: " ++ fun_name ++ "\n", .{});
}
}
@ -382,7 +382,7 @@ fn Mock() type {
/// Return: RetType
/// The return value of the mocked function. This can be void.
///
pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: ...) RetType {
pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: var) RetType {
if (self.named_actions.get(fun_name)) |kv_actions_list| {
var action_list = kv_actions_list.value;
// Peak the first action to test the action type
@ -397,7 +397,7 @@ fn Mock() type {
const test_node = action_list.popFirst().?;
const test_action = test_node.data;
const param = params[i];
const param_type = @typeOf(params[i]);
const param_type = @TypeOf(params[i]);
expectTest(param_type, param, test_action.data);
@ -420,8 +420,8 @@ fn Mock() type {
// to be resolved
const expected_function = switch (params.len) {
0 => fn () RetType,
1 => fn (@typeOf(params[0])) RetType,
2 => fn (@typeOf(params[0]), @typeOf(params[1])) RetType,
1 => fn (@TypeOf(params[0])) RetType,
2 => fn (@TypeOf(params[0]), @TypeOf(params[1])) RetType,
else => @compileError("Couldn't generate function type for " ++ params.len ++ "parameters\n"),
};
@ -438,10 +438,10 @@ fn Mock() type {
action_list.destroyNode(test_node, GlobalAllocator);
// The data element will contain the function to call
const r = switch (params.len) {
0 => @noInlineCall(actual_function),
1 => @noInlineCall(actual_function, params[0]),
2 => @noInlineCall(actual_function, params[0], params[1]),
var r = switch (params.len) {
0 => actual_function(),
1 => actual_function(params[0]),
2 => actual_function(params[0], params[1]),
else => @compileError(params.len ++ " or more parameters not supported"),
};
@ -453,8 +453,8 @@ fn Mock() type {
const test_element = action.data;
const expected_function = switch (params.len) {
0 => fn () RetType,
1 => fn (@typeOf(params[0])) RetType,
2 => fn (@typeOf(params[0]), @typeOf(params[1])) RetType,
1 => fn (@TypeOf(params[0])) RetType,
2 => fn (@TypeOf(params[0]), @TypeOf(params[1])) RetType,
else => @compileError("Couldn't generate function type for " ++ params.len ++ "parameters\n"),
};
@ -469,9 +469,9 @@ fn Mock() type {
// The data element will contain the function to call
const r = switch (params.len) {
0 => @noInlineCall(actual_function),
1 => @noInlineCall(actual_function, params[0]),
2 => @noInlineCall(actual_function, params[0], params[1]),
0 => actual_function(),
1 => actual_function(params[0]),
2 => actual_function(params[0], params[1]),
else => @compileError(params.len ++ " or more parameters not supported"),
};
@ -483,10 +483,10 @@ fn Mock() type {
kv_actions_list.value = action_list;
return ret;
} else {
std.debug.panic("No action list elements for function: " ++ fun_name ++ "\n");
std.debug.panic("No action list elements for function: " ++ fun_name ++ "\n", .{});
}
} else {
std.debug.panic("No function name: " ++ fun_name ++ "\n");
std.debug.panic("No function name: " ++ fun_name ++ "\n", .{});
}
}
@ -520,7 +520,7 @@ fn Mock() type {
switch (action.action) {
ActionType.TestValue, ActionType.ConsumeFunctionCall => {
// These need to be all consumed
std.debug.panic("Unused testing value: Type: {}, value: {} for function '{}'\n", action.action, @as(DataElementType, action.data), next.key);
std.debug.panic("Unused testing value: Type: {}, value: {} for function '{}'\n", .{ action.action, @as(DataElementType, action.data), next.key });
},
ActionType.RepeatFunctionCall => {
// As this is a repeat action, the function will still be here
@ -553,7 +553,7 @@ fn getMockObject() *Mock() {
if (mock) |*m| {
return m;
} else {
warn("MOCK object doesn't exists, please initiate this test\n");
warn("MOCK object doesn't exists, please initiate this test\n", .{});
expect(false);
unreachable;
}
@ -565,7 +565,7 @@ fn getMockObject() *Mock() {
pub fn initTest() void {
// Make sure there isn't a mock object
if (mock) |_| {
warn("MOCK object already exists, please free previous test\n");
warn("MOCK object already exists, please free previous test\n", .{});
expect(false);
unreachable;
} else {
@ -596,7 +596,7 @@ pub fn freeTest() void {
/// IN fun_name: []const u8 - The function name to add the test parameters to.
/// IN params: arglist - The parameters to add.
///
pub fn addTestParams(comptime fun_name: []const u8, params: ...) void {
pub fn addTestParams(comptime fun_name: []const u8, params: var) void {
var mock_obj = getMockObject();
comptime var i = 0;
inline while (i < params.len) : (i += 1) {
@ -639,6 +639,6 @@ pub fn addRepeatFunction(comptime fun_name: []const u8, function: var) void {
/// Return: RetType
/// The return value of the mocked function. This can be void.
///
pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: ...) RetType {
pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: var) RetType {
return getMockObject().performAction(fun_name, RetType, params);
}

View file

@ -2,7 +2,7 @@ const builtin = @import("builtin");
const std = @import("std");
const MemProfile = @import("mem_mock.zig").MemProfile;
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: ...) noreturn {
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn {
@setCold(true);
std.debug.panic(format, args);
}

View file

@ -72,19 +72,19 @@ pub const IRQ_FLOATING_POINT_UNIT: u8 = 0x0D;
pub const IRQ_HARD_DISK_CONTROLLER: u8 = 0x0E;
pub fn sendEndOfInterrupt(irq_num: u8) void {
return mock_framework.performAction("sendEndOfInterrupt", void, irq_num);
return mock_framework.performAction("sendEndOfInterrupt", void, .{irq_num});
}
pub fn spuriousIrq(irq_num: u8) bool {
return mock_framework.performAction("spuriousIrq", bool, irq_num);
return mock_framework.performAction("spuriousIrq", bool, .{irq_num});
}
pub fn setMask(irq_num: u16) void {
return mock_framework.performAction("setMask", void, irq_num);
return mock_framework.performAction("setMask", void, .{irq_num});
}
pub fn clearMask(irq_num: u16) void {
return mock_framework.performAction("clearMask", void, irq_num);
return mock_framework.performAction("clearMask", void, .{irq_num});
}
pub fn remapIrq() void {

View file

@ -36,35 +36,35 @@ pub const CursorShape = enum {
};
pub fn entryColour(fg: u4, bg: u4) u8 {
return mock_framework.performAction("entryColour", u8, fg, bg);
return mock_framework.performAction("entryColour", u8, .{ fg, bg });
}
pub fn entry(uc: u8, colour: u8) u16 {
return mock_framework.performAction("entry", u16, uc, colour);
return mock_framework.performAction("entry", u16, .{ uc, colour });
}
pub fn updateCursor(x: u16, y: u16) void {
return mock_framework.performAction("updateCursor", void, x, y);
return mock_framework.performAction("updateCursor", void, .{ x, y });
}
pub fn getCursor() u16 {
return mock_framework.performAction("getCursor", u16);
return mock_framework.performAction("getCursor", u16, .{});
}
pub fn enableCursor() void {
return mock_framework.performAction("enableCursor", void);
return mock_framework.performAction("enableCursor", void, .{});
}
pub fn disableCursor() void {
return mock_framework.performAction("disableCursor", void);
return mock_framework.performAction("disableCursor", void, .{});
}
pub fn setCursorShape(shape: CursorShape) void {
return mock_framework.performAction("setCursorShape", void, shape);
return mock_framework.performAction("setCursorShape", void, .{shape});
}
pub fn init() void {
return mock_framework.performAction("init", void);
return mock_framework.performAction("init", void, .{});
}
// User defined mocked functions