diff --git a/resources/examples/nolibc/hello_world.c3 b/resources/examples/nolibc/hello_world.c3 index ccf3bc0f5..5e8b0f1e6 100644 --- a/resources/examples/nolibc/hello_world.c3 +++ b/resources/examples/nolibc/hello_world.c3 @@ -1,22 +1,26 @@ +fn void print(String msg) +{ + $$syscall(1, 1, (uptr)msg.ptr, msg.len); // __NR_write, STDOUT +} + +fn void printn(String msg) +{ + print(msg); + print("\n"); +} + +fn void exit(int exit_code) +{ + $$syscall(60, exit_code); // __NR_exit +} + fn int main() { - String msg = "Hello, C3 World!\n"; - $$syscall(1, 1, (uptr)msg.ptr, msg.len); // __NR_write, STDOUT - return 0; + printn("Hello, C3 World!"); + return 0; } fn void _start() @export("_start") { - int ret = main(); - $$syscall(60, ret); // __NR_exit -} - -module std::core::builtin; - -alias PanicFn = fn void(String message, String file, String function, uint line); - -PanicFn panic = &default_panic; - -fn void default_panic(String message, String file, String function, uint line) -{ + exit(main()); } diff --git a/resources/examples/nolibc/project.json b/resources/examples/nolibc/project.json index aeaf3d0ef..acec55a30 100644 --- a/resources/examples/nolibc/project.json +++ b/resources/examples/nolibc/project.json @@ -13,6 +13,8 @@ "version": "0.1.0", // Sources compiled for all targets. "sources": [ "./**" ], + // Test sources compiled for all targets. + "test-sources": [ "test/**" ], // C sources if the project also compiles C sources // relative to the project file. // "c-sources": [ "csource/**" ], @@ -24,31 +26,21 @@ // Targets. "targets": { "hello_world": { + // Executable or library. "type": "executable", - "debug-info": "none", - "link-libc": false, - "opt": "O0", - "safe": false, - "linker": "builtin", - "use-stdlib": false, + // Additional libraries, sources + // and overrides of global settings here. }, }, // Global settings. - // C compiler if the project also compiles C sources - // defaults to 'cc'. - "cc": "cc", // CPU name, used for optimizations in the LLVM backend. "cpu": "generic", - // Debug information, may be "none", "full" and "line-tables". - "debug-info": "full", - // FP math behaviour: "strict", "relaxed", "fast". - "fp-math": "strict", // Link libc other default libraries. - "link-libc": true, + "link-libc": false, // Memory environment: "normal", "small", "tiny", "none". - "memory-env": "normal", + "memory-env": "small", // Optimization: "O0", "O1", "O2", "O3", "O4", "O5", "Os", "Oz". - "opt": "O0", + "opt": "Os", // Code optimization level: "none", "less", "more", "max". "optlevel": "none", // Code size optimization: "none", "small", "tiny". @@ -58,7 +50,7 @@ // Trap on signed and unsigned integer wrapping for testing. "trap-on-wrap": false, // Turn safety (contracts, runtime bounds checking, null pointer checks etc). - "safe": true, + "safe": false, // Compile all modules together, enables more inlining. "single-module": true, // Use / don't use soft float, value is otherwise target default. @@ -69,11 +61,7 @@ // of symbols that can be used. Should usually not be changed. "symtab": 1048576, // Select linker. - "linker": "cc", + "linker": "builtin", // Include the standard library. - "use-stdlib": true, - // Set general level of x64 cpu: "baseline", "ssse3", "sse4", "avx1", "avx2-v1", "avx2-v2", "avx512", "native". - "x86cpu": "native", - // Set max type of vector use: "none", "mmx", "sse", "avx", "avx512", "native". - "x86vec": "sse", + "use-stdlib": false, } \ No newline at end of file