Skip to content

Commit bd09e1c

Browse files
committed
Fixes and refactoring
1 parent 9cc600a commit bd09e1c

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/main.zig

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn main() !void {
6666
const args = try std.process.argsAlloc(allocator);
6767
defer std.process.argsFree(allocator, args);
6868
arguments(allocator, vm) catch |err| {
69-
Reporter.printErr("Chyba: {}", .{err}) catch @panic("Hodnotu se nepodařilo vypsat");
69+
vm.reporter.printErr("Chyba: {}", .{err}) catch @panic("Hodnotu se nepodařilo vypsat");
7070
};
7171

7272
if (debug.benchmark) {
@@ -123,10 +123,7 @@ fn arguments(allocator: Allocator, vm: *VM) !void {
123123

124124
if (res.positionals.len > 0 and res.positionals[0].len > 0) {
125125
vm.reporter.file = res.positionals[0][0];
126-
runFile(allocator, res.positionals[0][0], vm) catch |err| {
127-
Reporter.printErr("Chyba při běhu skriptu: {}", .{err}) catch {};
128-
std.process.exit(1);
129-
};
126+
runFile(allocator, res.positionals[0][0], vm) catch {};
130127
} else {
131128
vm.reporter.file = "REPL";
132129
repl(allocator, vm) catch {};
@@ -172,7 +169,7 @@ fn repl(allocator: Allocator, vm: *VM) !void {
172169
const input = std.mem.trim(u8, buf_stream.getWritten(), "\n\r");
173170

174171
if (input.len == buf.len) {
175-
try Reporter.printErr("Vstup je příliš dlouhý", .{});
172+
try vm.reporter.printErr("Vstup je příliš dlouhý", .{});
176173
try stdin_file.reader(&stdin_buf).skipUntilDelimiterOrEof('\n');
177174
continue;
178175
}
@@ -217,7 +214,7 @@ fn runFile(allocator: Allocator, filename: []const u8, vm: *VM) !void {
217214
filename,
218215
1024 * 1024,
219216
) catch {
220-
Reporter.printErr("Soubor nebyl nalezen", .{}) catch {
217+
vm.reporter.printErr("Soubor nebyl nalezen", .{}) catch {
221218
@panic("Hodnotu se nepodařilo vypsat");
222219
};
223220
return;

src/reporter.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,15 @@ pub fn warn(self: *Reporter, token: *Token, message: []const u8) void {
322322
}
323323

324324
pub fn printErr(
325+
self: *Reporter,
325326
comptime message: []const u8,
326327
args: anytype,
327328
) !void {
328-
try shared.stdout.print("\x1b[31mChyba:\x1b[0m ", .{});
329-
try shared.stdout.print(message ++ "\n", args);
329+
if (self.nocolor) {
330+
try shared.stdout.print("Chyba: ", .{});
331+
try shared.stdout.print(message ++ "\n", args);
332+
} else {
333+
try shared.stdout.print("\x1b[31mChyba:\x1b[0m ", .{});
334+
try shared.stdout.print(message ++ "\n", args);
335+
}
330336
}

tests/gc_pressure.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
prm l = [];
2-
opakuj prm i = 0; .i < 50000; .i += 1: {
2+
opakuj prm i = 0; .i < 10000; .i += 1: {
33
.přidat(.l; "long string to take up space " + .naŘetězec(.i));
44
pokud .délka(.l) > 100: {
55
.vyjmout(.l);

tests/tester.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ def run_test(test_filepath):
8282
print(f"{Fore.RED}Test Failed:{Style.RESET_ALL} {test_filepath}")
8383
print(f"Expected Output:\n{expected_output}")
8484
print(f"Actual Output:\n{actual_output}")
85-
print(f"Exit Code: {process.returncode}")
86-
if process.stderr:
87-
print(f"Stderr:\n{process.stderr}")
8885
return 1
8986

9087
except Exception as e:

vyq

-1.48 KB
Binary file not shown.

0 commit comments

Comments
 (0)