diff --git a/example/hello_world/hello.zig b/example/hello_world/hello.zig index 6b3495e85f..93fa9ba8ae 100644 --- a/example/hello_world/hello.zig +++ b/example/hello_world/hello.zig @@ -2,7 +2,7 @@ export executable "hello"; use "std.zig"; -export fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 { +pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 { // TODO implicit coercion from array to string print_str("Hello, world!\n" as string); return 0; diff --git a/src/analyze.cpp b/src/analyze.cpp index 740e735bb7..5ba0ae16a7 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -315,7 +315,7 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import, auto entry = import->fn_table.maybe_get(proto_name); bool skip = false; bool is_internal = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModExport); - bool is_pub = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModPub); + bool is_pub = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate); if (entry) { add_node_error(g, node, buf_sprintf("redefinition of '%s'", buf_ptr(proto_name))); diff --git a/src/codegen.cpp b/src/codegen.cpp index f60f116a2c..2863335747 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1611,7 +1611,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src assert(proto_node->type == NodeTypeFnProto); Buf *proto_name = &proto_node->data.fn_proto.name; - bool is_exported = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModExport); + bool is_exported = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate); if (buf_eql_str(proto_name, "main") && is_exported) { g->insert_bootstrap_code = true; diff --git a/std/bootstrap.zig b/std/bootstrap.zig index 348b74a27e..3fc4616df3 100644 --- a/std/bootstrap.zig +++ b/std/bootstrap.zig @@ -1,16 +1,9 @@ +use "std.zig"; -// TODO conditionally compile this differently for non-ELF #attribute("naked") export fn _start() -> unreachable { - // TODO conditionally compile this differently for other architectures and other OSes - asm volatile (" - mov (%%rsp), %%rdi // first parameter is argc - lea 0x8(%%rsp), %%rsi // second parameter is argv - lea 0x10(%%rsp,%%rdi,8), %%rdx // third paremeter is env - callq main - mov %%rax, %%rdi // return value is the parameter to exit syscall - mov $60, %%rax // 60 is exit syscall number - syscall - "); - unreachable + const argc = asm("mov (%%rsp), %[argc]" : [argc] "=r" (return isize)); + const argv = asm("lea 0x8(%%rsp), %[argv]" : [argv] "=r" (return &&u8)); + const env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]" : [env] "=r" (return &&u8)); + exit(main(argc, argv, env)) }