Skip to content

Commit

Permalink
Removed broken code. Update formatter for precision. Fix of panic.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 5, 2023
1 parent 69418ba commit e3412da
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1,354 deletions.
2 changes: 1 addition & 1 deletion lib/std/core/builtin.c3
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct CallstackElement
fn void default_panic(String message, String file, String function, uint line)
{
CallstackElement* stack = $$stacktrace();
$if $defined(io::stderr) && $defined(File.printf):
$if $defined(io::stderr) && $defined(Stream.printf):
if (stack) stack = stack.prev;
if (stack)
{
Expand Down
45 changes: 21 additions & 24 deletions lib/std/io/formatter.c3
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ fn usz! Formatter.out_str(&self, any arg) @private
unreachable();
case SIGNED_INT:
case UNSIGNED_INT:
PrintFlags flags = self.flags;
defer self.flags = flags;
self.flags = {};
return self.ntoa_any(arg, 10);
case FLOAT:
PrintFlags flags = self.flags;
defer self.flags = flags;
self.flags = {};
return self.ftoa(float_from_any(arg)!!);
case BOOL:
return self.out_substr(*(bool*)arg.ptr ? "true" : "false");
Expand Down Expand Up @@ -163,9 +169,15 @@ fn usz! Formatter.out_str(&self, any arg) @private
}
return self.out_str(any { arg.ptr, arg.type.inner });
case POINTER:
PrintFlags flags = self.flags;
self.flags = {};
defer self.flags = flags;
return self.ntoa_any(arg, 16);
case ARRAY:
// this is SomeType[*] so grab the "SomeType"
PrintFlags flags = self.flags;
defer self.flags = flags;
self.flags = {};
typeid inner = arg.type.inner;
usz size = inner.sizeof;
usz alen = arg.type.len;
Expand All @@ -181,6 +193,9 @@ fn usz! Formatter.out_str(&self, any arg) @private
len += self.out(']')!;
return len;
case VECTOR:
PrintFlags flags = self.flags;
defer self.flags = flags;
self.flags = {};
// this is SomeType[*] so grab the "SomeType"
typeid inner = arg.type.inner;
usz size = inner.sizeof;
Expand All @@ -204,6 +219,9 @@ fn usz! Formatter.out_str(&self, any arg) @private
return self.out_substr(*(String*)arg);
}
if (inner == void.typeid) inner = char.typeid;
PrintFlags flags = self.flags;
defer self.flags = flags;
self.flags = {};
usz size = inner.sizeof;
// Pretend this is a String
String* temp = (void*)arg.ptr;
Expand Down Expand Up @@ -347,38 +365,17 @@ fn usz! Formatter.vprintf(&self, String format, any[] anys)
self.out_char(current)!;
continue;
case 's':
PrintFlags flags = self.flags;
uint width = self.width;
String str;
if (flags.precision)
{
switch (s = current)
{
case String:
if (s.len > self.prec)
{
str = (*s)[:self.prec];
current = &str;
}
}
}
defer {
self.flags = flags;
self.width = width;
}
self.flags = {};
self.width = 0;
if (flags.left)
if (self.flags.left)
{
usz len = self.out_str(current)!;
self.pad(' ', width, len)!;
self.pad(' ', self.width, len)!;
continue;
}
OutputFn out_fn = self.out_fn;
self.out_fn = (OutputFn)&out_null_fn;
usz len = self.out_str(current)!;
self.out_fn = out_fn;
self.pad(' ', width, len)!;
self.pad(' ', self.width, len)!;
self.out_str(current)!;
continue;
case 'p':
Expand Down
259 changes: 0 additions & 259 deletions resources/testfragments/sdl2.c3

This file was deleted.

Loading

0 comments on commit e3412da

Please sign in to comment.