Bugfix for say() when length is >512, and added back the newline
optional parameter (default=yes)
This commit is contained in:
parent
dceb925573
commit
a197875214
@ -233,14 +233,16 @@ public void end_test(void *expr, const TypeInfo *type, CORD expected, const char
|
||||
}
|
||||
}
|
||||
|
||||
public void say(CORD text)
|
||||
public void say(CORD text, bool newline)
|
||||
{
|
||||
uint8_t buf[512] = {0};
|
||||
size_t buf_len = sizeof(buf)-1;
|
||||
const char *str = CORD_to_const_char_star(text);
|
||||
uint8_t *normalized = u8_normalize(UNINORM_NFD, (uint8_t*)str, strlen(str), buf, &buf_len);
|
||||
if (normalized) {
|
||||
puts((char*)normalized);
|
||||
write(STDOUT_FILENO, normalized, buf_len);
|
||||
if (newline)
|
||||
write(STDOUT_FILENO, "\n", 1);
|
||||
if (normalized != buf)
|
||||
free(normalized);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ void end_test(void *expr, const TypeInfo *type, CORD expected, const char *filen
|
||||
#define test(expr, type, expected, filename, start, end) {\
|
||||
start_test(filename, start, end); \
|
||||
end_test(expr, type, expected, filename, start, end); }
|
||||
void say(CORD text);
|
||||
void say(CORD text, bool newline);
|
||||
|
||||
uint32_t generic_hash(const void *obj, const TypeInfo *type);
|
||||
int32_t generic_compare(const void *x, const void *y, const TypeInfo *type);
|
||||
|
@ -832,7 +832,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
|
||||
}
|
||||
if (chunk->next) code = CORD_cat(code, ", ");
|
||||
}
|
||||
return CORD_cat(code, "));");
|
||||
return CORD_cat(code, "), yes);");
|
||||
}
|
||||
case Return: {
|
||||
if (!env->fn_ctx) code_err(ast, "This return statement is not inside any function");
|
||||
|
@ -31,7 +31,8 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
const char *name;
|
||||
binding_t binding;
|
||||
} global_vars[] = {
|
||||
{"say", {.code="say", .type=Type(FunctionType, .args=new(arg_t, .name="text", .type=TEXT_TYPE), .ret=Type(VoidType))}},
|
||||
{"say", {.code="say", .type=Type(FunctionType, .args=new(arg_t, .name="text", .type=TEXT_TYPE,
|
||||
.next=new(arg_t, .name="newline", .type=Type(BoolType), .default_val=FakeAST(Bool, true))), .ret=Type(VoidType))}},
|
||||
{"fail", {.code="fail", .type=Type(FunctionType, .args=new(arg_t, .name="message", .type=TEXT_TYPE), .ret=Type(AbortType))}},
|
||||
{"USE_COLOR", {.code="USE_COLOR", .type=Type(BoolType)}},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user