Updated License
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
# The No Vibe Coders Open Source License
|
||||
|
||||
```
|
||||
Copyright (C) 2025 William Welna (wwelna@occultusterra.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following condition.
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
In addition, the following restrictions apply:
|
||||
|
||||
* The software, either in source or compiled binary form, with or without any
|
||||
modification, may not be used with or incorporated into any other software
|
||||
that used an Artificial Intelligence (AI) model and/or Large Language Model
|
||||
(LLM) to generate any portion of that other software's source code, binaries,
|
||||
or artwork.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
```
|
||||
@@ -2,19 +2,28 @@
|
||||
# bfz
|
||||
A simple BF interpreter coded in zig.
|
||||
|
||||
## License
|
||||
## The No Vibe Coders Open Source License
|
||||
|
||||
Copyright (C) 2023 William Welna (wwelna@occultusterra.com)
|
||||
```
|
||||
Copyright (C) 2025 William Welna (wwelna@occultusterra.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
furnished to do so, subject to the following condition.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
In addition, the following restrictions apply:
|
||||
|
||||
* The software, either in source or compiled binary form, with or without any
|
||||
modification, may not be used with or incorporated into any other software
|
||||
that used an Artificial Intelligence (AI) model and/or Large Language Model
|
||||
(LLM) to generate any portion of that other software's source code, binaries,
|
||||
or artwork.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
@@ -23,3 +32,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
```
|
||||
|
||||
+65
-42
@@ -1,14 +1,22 @@
|
||||
// Copyright (C) 2023 William Welna (wwelna@occultusterra.com)
|
||||
// Copyright (C) 2025 William Welna (wwelna@occultusterra.com)
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// furnished to do so, subject to the following condition.
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
// * The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
|
||||
// In addition, the following restrictions apply:
|
||||
|
||||
// * The software, either in source or compiled binary form, with or without any
|
||||
// modification, may not be used with or incorporated into any other software
|
||||
// that used an Artificial Intelligence (AI) model and/or Large Language Model
|
||||
// (LLM) to generate any portion of that other software's source code, binaries,
|
||||
// or artwork.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
@@ -25,24 +33,21 @@ var stdin_buffer: [256]u8 = undefined;
|
||||
|
||||
const bf_machine = struct {
|
||||
const Self = @This();
|
||||
const size:usize = 30000;
|
||||
const size: usize = 30000;
|
||||
const exeParam = struct {
|
||||
program_pos:usize = 0,
|
||||
loop:bool = false,
|
||||
loop_start:usize = 0,
|
||||
program_pos: usize = 0,
|
||||
loop: bool = false,
|
||||
loop_start: usize = 0,
|
||||
};
|
||||
const Fail = error {
|
||||
Odd_Brackets,
|
||||
Odd_Brackets_Overflow
|
||||
};
|
||||
mem:[]u8,
|
||||
pos:usize,
|
||||
program:[]const u8,
|
||||
allocator:std.mem.Allocator,
|
||||
stdout:*std.io.Writer,
|
||||
stdin:*std.io.Reader,
|
||||
const Fail = error{ Odd_Brackets, Odd_Brackets_Overflow };
|
||||
mem: []u8,
|
||||
pos: usize,
|
||||
program: []const u8,
|
||||
allocator: std.mem.Allocator,
|
||||
stdout: *std.io.Writer,
|
||||
stdin: *std.io.Reader,
|
||||
|
||||
pub fn init(allocator:std.mem.Allocator, program:[]const u8, stdin:*std.io.Reader, stdout:*std.io.Writer) !Self {
|
||||
pub fn init(allocator: std.mem.Allocator, program: []const u8, stdin: *std.io.Reader, stdout: *std.io.Writer) !Self {
|
||||
const mem = try allocator.alloc(u8, size);
|
||||
@memset(mem, 0);
|
||||
return .{
|
||||
@@ -55,47 +60,65 @@ const bf_machine = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn execute(self:*Self, param:exeParam) !usize {
|
||||
pub fn execute(self: *Self, param: exeParam) !usize {
|
||||
var program_pos = param.program_pos;
|
||||
while(program_pos < self.program.len) {
|
||||
switch(self.program[program_pos]) {
|
||||
'>' => {self.pos += 1; program_pos += 1;},
|
||||
'<' => {self.pos -= 1; program_pos += 1;},
|
||||
'+' => {self.mem[self.pos] +%= 1; program_pos += 1;},
|
||||
'-' => {self.mem[self.pos] -%= 1; program_pos += 1;},
|
||||
'.' => {try self.stdout.print("{c}", .{self.mem[self.pos]}); try self.stdout.flush(); program_pos += 1;},
|
||||
while (program_pos < self.program.len) {
|
||||
switch (self.program[program_pos]) {
|
||||
'>' => {
|
||||
self.pos += 1;
|
||||
program_pos += 1;
|
||||
},
|
||||
'<' => {
|
||||
self.pos -= 1;
|
||||
program_pos += 1;
|
||||
},
|
||||
'+' => {
|
||||
self.mem[self.pos] +%= 1;
|
||||
program_pos += 1;
|
||||
},
|
||||
'-' => {
|
||||
self.mem[self.pos] -%= 1;
|
||||
program_pos += 1;
|
||||
},
|
||||
'.' => {
|
||||
try self.stdout.print("{c}", .{self.mem[self.pos]});
|
||||
try self.stdout.flush();
|
||||
program_pos += 1;
|
||||
},
|
||||
',' => {
|
||||
const i:u8 = try self.stdin.takeByte();
|
||||
const i: u8 = try self.stdin.takeByte();
|
||||
self.mem[self.pos] = i;
|
||||
program_pos += 1;
|
||||
},
|
||||
'[' => {
|
||||
if(self.mem[self.pos] == 0) {
|
||||
var nested:usize = 1;
|
||||
if (self.mem[self.pos] == 0) {
|
||||
var nested: usize = 1;
|
||||
program_pos += 1;
|
||||
while(nested > 0 and program_pos < self.program.len) : (program_pos += 1) {
|
||||
if(self.program[program_pos] == ']') nested -= 1 else if (self.program[program_pos] == '[') nested += 1;
|
||||
while (nested > 0 and program_pos < self.program.len) : (program_pos += 1) {
|
||||
if (self.program[program_pos] == ']') nested -= 1 else if (self.program[program_pos] == '[') nested += 1;
|
||||
}
|
||||
if(nested != 0) return Fail.Odd_Brackets_Overflow;
|
||||
if (nested != 0) return Fail.Odd_Brackets_Overflow;
|
||||
} else {
|
||||
program_pos += 1;
|
||||
program_pos = try self.execute(.{.program_pos = program_pos, .loop = true, .loop_start = program_pos});
|
||||
program_pos = try self.execute(.{ .program_pos = program_pos, .loop = true, .loop_start = program_pos });
|
||||
}
|
||||
},
|
||||
']' => {
|
||||
if(param.loop == true) {
|
||||
if(self.mem[self.pos] == 0) {
|
||||
if (param.loop == true) {
|
||||
if (self.mem[self.pos] == 0) {
|
||||
return program_pos + 1;
|
||||
} else program_pos = param.loop_start;
|
||||
} else return Fail.Odd_Brackets; // Loop / Bracket count not even
|
||||
},
|
||||
else => {program_pos += 1;},
|
||||
else => {
|
||||
program_pos += 1;
|
||||
},
|
||||
}
|
||||
}
|
||||
return self.program.len-1;
|
||||
return self.program.len - 1;
|
||||
}
|
||||
|
||||
pub fn deinit(self:*Self) void {
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.allocator.free(self.mem);
|
||||
}
|
||||
};
|
||||
@@ -112,7 +135,7 @@ pub fn main() !void {
|
||||
var stdin_reader_wrapper = std.fs.File.stdin().reader(&stdin_buffer);
|
||||
const stdin: *std.io.Reader = &stdin_reader_wrapper.interface;
|
||||
|
||||
if(args.len != 2) {
|
||||
if (args.len != 2) {
|
||||
std.debug.print("Filename as first argument required!\n", .{});
|
||||
} else {
|
||||
var f = try std.fs.cwd().openFile(args[1], .{});
|
||||
@@ -121,7 +144,7 @@ pub fn main() !void {
|
||||
const d = try allocator.alloc(u8, s.size);
|
||||
defer allocator.free(d);
|
||||
|
||||
if(try f.readAll(d)<=0) {
|
||||
if (try f.readAll(d) <= 0) {
|
||||
std.debug.print("File is Empty!\n", .{});
|
||||
return;
|
||||
}
|
||||
@@ -132,4 +155,4 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
try stdout.flush();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user