ai: 生成代码准备重构前的一次提交
This commit is contained in:
1 parent
936a8d0e88
commit
032102f1d7
375 files changed
+4619
-7609
No files matched your search
@@ -55,6 +55,9 @@
|
||||
type .{ .Allocator, .AllocError, .Layout } = @import("core/alloc.spl");
|
||||
type .{ .Writer, .Reader, .IOError } = @import("core/io.spl");
|
||||
type .{ .Result } = @import("core/error.spl");
|
||||
type .{ .File, .FileMode, .Time, .Memory, .Process, .VM } = @import("./shape.spl");
|
||||
// type .{} = @import("");
|
||||
type ptr = @import("core/ptr.spl");
|
||||
|
||||
pub fn strlen(str: *const u8): usize {
|
||||
var len: usize = 0;
|
||||
@@ -118,9 +121,6 @@ pub type VMWriter = struct: Writer {
|
||||
}
|
||||
}
|
||||
|
||||
type .{ .File, .FileMode, .Time, .Memory, .Process, .VM } = @import("./shape.spl");
|
||||
type ptr = @import("core/ptr.spl");
|
||||
|
||||
type VMFile = struct: File {
|
||||
file: *any;
|
||||
|
||||
@@ -194,4 +194,12 @@ type VMFile = struct: File {
|
||||
}
|
||||
ret .(.Ok(()));
|
||||
}
|
||||
|
||||
pub fn putchar(@Self _self: *@self, ch: u8): bool {
|
||||
vm_putchar(ch as i32);
|
||||
}
|
||||
}
|
||||
|
||||
// type VMFormat = struct: Formatter {
|
||||
|
||||
// }
|
||||
+58
-1
@@ -1,3 +1,5 @@
|
||||
type .{ .Result } = @import("./error.spl");
|
||||
|
||||
pub type Display = shape {
|
||||
fn fmt(@Self self: *@self, out: @[*Sink]): bool;
|
||||
};
|
||||
@@ -12,12 +14,67 @@ pub type Sink = shape {
|
||||
// TODO shape default value for `fn write_bytes(@Self self: *@self, bytes: []const u8): bool;`
|
||||
};
|
||||
|
||||
pub comptime fn Formatter(S: Sink): type {
|
||||
pub type Spec = struct {
|
||||
align: enum { Left, Center, Right },
|
||||
width: usize,
|
||||
fill: u8,
|
||||
// attrs: enum {
|
||||
// number: struct {},
|
||||
// }
|
||||
};
|
||||
|
||||
pub type Error = enum {
|
||||
WriteFailed,
|
||||
UnclosedLeftBrace,
|
||||
UnclosedRightBrace,
|
||||
UnknownSpec,
|
||||
MissingArg,
|
||||
TooManyArgs,
|
||||
};
|
||||
|
||||
// not have { and }
|
||||
pub fn parse_spec(pattern: []const u8): @Result(Spec, Error) {
|
||||
var res = Spec {
|
||||
.fill = ' ',
|
||||
.width = 0,
|
||||
.align = .Left,
|
||||
};
|
||||
ret .Ok(res);
|
||||
}
|
||||
|
||||
pub comptime fn Format(S: Sink): type {
|
||||
ret struct {
|
||||
out: S,
|
||||
|
||||
pub fn with_sink(out: S): @self {
|
||||
ret .{ .out = out };
|
||||
}
|
||||
|
||||
fn write(@Self self: *@self, str: []const u8): bool {
|
||||
var res = true;
|
||||
for i in str {
|
||||
res = self.out.write_byte(i);
|
||||
if (res == false) {
|
||||
ret false;
|
||||
}
|
||||
}
|
||||
ret res;
|
||||
}
|
||||
|
||||
pub fn format(@Self self: *@self, pattern: []const u8, args: []const DisplayArg): Error {
|
||||
var starti = 0;
|
||||
for i in 0..pattern.len() {
|
||||
var ch = pattern[i];
|
||||
match pattern[i] {
|
||||
'{' => {
|
||||
|
||||
},
|
||||
'}' => {
|
||||
|
||||
},
|
||||
_ => { continue; },
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,8 +1,22 @@
|
||||
type .{ .VMWriter, .VMFile, .strlen, .VMAllocator } = @import("compiler/vm.spl");
|
||||
type .{ .Vec } = @import("core/vec.spl");
|
||||
|
||||
type .{ .OptParse } = @import("compiler/optparse.spl");
|
||||
type .{ .Source, .SourceError } = @import("lexer/source.spl");
|
||||
|
||||
fn test() {
|
||||
var args: []const []const u8 = .["program", "-h"];
|
||||
var parser = OptParse.with_args(args);
|
||||
|
||||
@assert(parser.args.len() == 2, "args len != 2");
|
||||
@assert(parser.args.as_ptr() == args.as_ptr(), "args not assign");
|
||||
@assert(parser.current.handle_positional == false, "handle_position");
|
||||
@assert(parser.current.arg_pos == 1, "args pos need 1");
|
||||
@assert(parser.current.opt_pos == 0, "opts pos need 0");
|
||||
@assert(parser.current.opt == null, "current pot need null");
|
||||
@assert(parser.opts.as_ptr() == null, "opts need null");
|
||||
}
|
||||
|
||||
fn spl_main(args: const[] const[] u8): i32 {
|
||||
var alloc = VMAllocator{};
|
||||
|
||||
@@ -29,6 +43,7 @@ fn spl_main(args: const[] const[] u8): i32 {
|
||||
ret 1;
|
||||
};
|
||||
|
||||
test();
|
||||
}
|
||||
|
||||
fn main(argc: i32, _argv: const **u8, envp: const **u8): i32 {
|
||||
|
||||
Reference in new issue
Block a user