Fix no-entry. Make printf more strict and also fix distinct printing.

This commit is contained in:
Christoffer Lerno
2023-02-14 20:39:15 +01:00
parent 8d306ce64d
commit 8b099293a3
4 changed files with 24 additions and 17 deletions

View File

@@ -1,25 +1,29 @@
module std::io;
fn void! Formatter.left_adjust(Formatter* this, usz len) @private
fn void! Formatter.left_adjust(Formatter* this, usz len) @local
{
if (!this.flags.left) return;
for (usz l = len; l < this.width; l++) this.out(' ')?;
}
fn void! Formatter.right_adjust(Formatter* this, usz len) @private
fn void! Formatter.right_adjust(Formatter* this, usz len) @local
{
if (this.flags.left) return;
for (usz l = len; l < this.width; l++) this.out(' ')?;
}
fn uint128 int_from_variant(variant arg, bool *is_neg) @private
fn uint128! int_from_variant(variant arg, bool *is_neg) @private
{
*is_neg = false;
if (arg.type.kindof == TypeKind.POINTER)
{
return (uint128)(uptr)*(void**)arg.ptr;
}
if (arg.type.kindof == TypeKind.DISTINCT)
{
return int_from_variant(variant { arg.ptr, arg.type.inner }, is_neg);
}
switch (arg)
{
case bool:
@@ -56,11 +60,11 @@ fn uint128 int_from_variant(variant arg, bool *is_neg) @private
double d = *arg;
return (uint128)((*is_neg = d < 0) ? -d : d);
default:
return 0;
return PrintFault.INVALID_ARGUMENT_TYPE!;
}
}
fn FloatType float_from_variant(variant arg) @private
fn FloatType! float_from_variant(variant arg) @private
{
$if (env::F128_SUPPORT):
if (arg.type == float128.typeid) return *((float128*)arg.ptr);
@@ -68,10 +72,9 @@ fn FloatType float_from_variant(variant arg) @private
$if (env::F16_SUPPORT):
if (arg.type == float16.typeid) return *((float16*)arg.ptr);
$endif;
if (arg.type.kindof == TypeKind.POINTER)
if (arg.type.kindof == TypeKind.DISTINCT)
{
return (FloatType)(uptr)(void*)arg.ptr;
return float_from_variant(variant { arg.ptr, arg.type.inner });
}
switch (arg)
{
@@ -102,7 +105,7 @@ fn FloatType float_from_variant(variant arg) @private
case double:
return (FloatType)*arg;
default:
return 0;
return PrintFault.INVALID_ARGUMENT_TYPE!;
}
}
@@ -467,7 +470,7 @@ fn void! Formatter.ntoa_format(Formatter* this, String buf, usz len, bool negati
fn void! Formatter.ntoa_variant(Formatter* this, variant arg, uint base) @private
{
bool is_neg;
uint128 val = int_from_variant(arg, &is_neg);
uint128 val = int_from_variant(arg, &is_neg)!!;
return this.ntoa(val, is_neg, base) @inline;
}

View File

@@ -13,6 +13,7 @@ fault PrintFault
INTERNAL_BUFFER_EXCEEDED,
INVALID_FORMAT_STRING,
MISSING_ARG,
INVALID_ARGUMENT_TYPE,
}
fault FormattingFault
@@ -249,7 +250,7 @@ fn void! Formatter.out_str(Formatter* this, variant arg) @private
case UNSIGNED_INT:
return this.ntoa_variant(arg, 10);
case FLOAT:
return this.ftoa(float_from_variant(arg));
return this.ftoa(float_from_variant(arg)!!);
case ARRAY:
if (this.print_with_function(arg)?) return;
// this is SomeType[*] so grab the "SomeType"
@@ -447,20 +448,20 @@ fn usz! Formatter.vprintf(Formatter* this, String format, variant[] variants)
this.flags.uppercase = true;
nextcase;
case 'f':
this.ftoa(float_from_variant(current))?;
this.ftoa(float_from_variant(current)!!)?;
continue;
case 'E':
this.flags.uppercase = true;
nextcase;
case 'e':
this.etoa(float_from_variant(current))?;
this.etoa(float_from_variant(current)!!)?;
continue;
case 'G':
this.flags.uppercase = true;
nextcase;
case 'g':
this.flags.adapt_exp = true;
this.etoa(float_from_variant(current))?;
this.etoa(float_from_variant(current)!!)?;
continue;
case 'c':
this.out_char(current)?;
@@ -484,7 +485,7 @@ fn usz! Formatter.vprintf(Formatter* this, String format, variant[] variants)
if (this.flags.precision) this.flags.zeropad = false;
bool is_neg;
uint128 v = int_from_variant(current, &is_neg);
uint128 v = int_from_variant(current, &is_neg)!!;
this.ntoa(v, is_neg, base)?;
}

View File

@@ -468,7 +468,10 @@ static bool linker_setup(const char ***args_ref, const char **files_to_link, uns
}
else
{
if (active_target.no_entry) add_arg("--no-entry");
if (linker_type == LINKER_WASM)
{
if (active_target.no_entry) add_arg("--no-entry");
}
add_arg("-o");
add_arg(output_file);
}

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.64"
#define COMPILER_VERSION "0.4.65"