Fix Linux constant in posix.c3. Address issue #1009. Sanitizes the module name in generated project.

This commit is contained in:
Christoffer Lerno
2023-09-22 15:15:47 +02:00
parent 8dad8f2b1c
commit e706a8acd0
5 changed files with 61 additions and 13 deletions

View File

@@ -4,10 +4,10 @@ def Pid_t = int;
def Uid_t = uint;
def Gid_t = uint;
const CInt SA_ONSTACK = env::LINUX ? 0x08000000 : 0x0001;
const CInt SA_RESTART = env::LINUX ? 0x10000000 : 0x0002;
const CInt SA_RESETHAND = env::LINUX ? 0x80000000 : 0x0004;
const CInt SA_SIGINFO = env::LINUX ? 0x00000004 : 0x0040;
const CUInt SA_ONSTACK = env::LINUX ? 0x08000000 : 0x0001;
const CUInt SA_RESTART = env::LINUX ? 0x10000000 : 0x0002;
const CUInt SA_RESETHAND = env::LINUX ? 0x80000000 : 0x0004;
const CUInt SA_SIGINFO = env::LINUX ? 0x00000004 : 0x0040;
def Sigset_t = uint @if(!env::LINUX);
def Sigset_t = ulong[16] @if(env::LINUX);
@@ -29,9 +29,16 @@ struct Sigaction
struct Stack_t
{
void* ss_sp;
usz ss_size @if(!env::LINUX);
struct @if(!env::LINUX)
{
usz ss_size;
CInt ss_flags;
usz ss_size @if(env::LINUX);
}
struct @if(env::LINUX)
{
CInt ss_flags;
usz ss_size;
}
}
extern fn CInt sigaltstack(Stack_t* ss, Stack_t* old_ss);

View File

@@ -209,7 +209,30 @@ void create_project(BuildOptions *build_options)
file = fopen("main.c3", "w");
if (!file) goto ERROR;
(void) fprintf(file, MAIN_TEMPLATE, build_options->project_name);
scratch_buffer_clear();
size_t len = strlen(build_options->project_name);
bool has_char = false;
for (size_t i = 0; i < len; i++)
{
char c = build_options->project_name[i];
if (c >= '0' && c <= '9')
{
if (!has_char) scratch_buffer_append("m_");
has_char = true;
scratch_buffer_append_char(c);
continue;
}
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
{
scratch_buffer_append_char(c | 0x20);
has_char = true;
continue;
}
scratch_buffer_append_char('_');
}
if (!has_char) scratch_buffer_append("module");
(void) fprintf(file, MAIN_TEMPLATE, scratch_buffer_to_string());
if (fclose(file)) goto ERROR;
if (!dir_change("..")) goto ERROR;

View File

@@ -3191,6 +3191,10 @@ static bool sema_append_generate_parameterized_name(SemaContext *c, Module *modu
if (type->type_kind == TYPE_OPTIONAL) RETURN_SEMA_ERROR(type_info, "Expected a non-optional type.");
if (type == type_void) RETURN_SEMA_ERROR(type_info, "A 'void' type cannot be used as a parameter type.");
if (type_is_invalid_storage_type(type)) RETURN_SEMA_ERROR(type_info, "Expected a runtime type.");
if (type_is_func_ptr(type))
{
if (!sema_resolve_type_decl(c, type->pointer)) return false;
}
if (mangled)
{
type_mangle_introspect_name_to_buffer(type);

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.655"
#define COMPILER_VERSION "0.4.656"

View File

@@ -0,0 +1,14 @@
module oups;
import std::collections::map;
fn void! main()
{
}
def FooFunc = fn void! (Bar*); // #error: Recursive definition
def Foo = HashMap(<String, FooFunc>);
struct Bar
{
Foo foo;
}