From 243894a026f1faacd337afda2c81e56226ae0ccd Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 9 Jun 2022 17:24:50 +0200 Subject: [PATCH] new changes i said --- core/__internal/allocate/linux.sp | 10 ++---- core/flow.sp | 15 +++++---- core/fs.sp | 6 +--- core/init.sp | 21 +++++------- core/io.sp | 22 +++++++++---- core/linux.sp | 4 ++- core/os.sp | 7 ++++ core/string.sp | 55 +++++++++++++++---------------- examples/new-syntax.sp | 12 +++++++ 9 files changed, 84 insertions(+), 68 deletions(-) create mode 100644 core/os.sp create mode 100644 examples/new-syntax.sp diff --git a/core/__internal/allocate/linux.sp b/core/__internal/allocate/linux.sp index 84388d3..22cdcbb 100644 --- a/core/__internal/allocate/linux.sp +++ b/core/__internal/allocate/linux.sp @@ -1,11 +1,7 @@ -namespace allocate { +let @memalloc (u64 size) : void* in { - @memalloc (void*) (u64 size) { +} - } - - @memfree (void* ptr) { - - } +let @memfree (void* ptr) in { } \ No newline at end of file diff --git a/core/flow.sp b/core/flow.sp index f8e73dc..92aeb9b 100644 --- a/core/flow.sp +++ b/core/flow.sp @@ -1,9 +1,10 @@ -import core/linux; - -namespace flow { - - @exit (i32 code) { - linux.sys_exit(code); - } +let compmacro('ifsystem','linux') in { + let { posix } in @'core/linux'; +} +let compmacro('ifsystem','darwin') in { + let { posix } in @'core/darwin'; +} +let @exit (i32 code) in { + posix.sys_exit(code); } \ No newline at end of file diff --git a/core/fs.sp b/core/fs.sp index bb0e4ba..0a07b33 100644 --- a/core/fs.sp +++ b/core/fs.sp @@ -1,5 +1 @@ -import core/linux; - -namespace fs { - -} \ No newline at end of file +let { os } in @'core/os'; \ No newline at end of file diff --git a/core/init.sp b/core/init.sp index ae802df..4e3114f 100644 --- a/core/init.sp +++ b/core/init.sp @@ -1,16 +1,13 @@ -import core/flow; +let { flow } in @'core/flow'; -namespace init { +let _libcore_Argc : i32; +let _libcore_Argv : i8**; - i32 _libcore_Argc; - i8** _libcore_Argv; +let @__libcore_call_init (i32 _Argc, i8** _Argv) in { + _libcore_Argc = _Argc; + _libcore_Argv = _Argv; - @__libcore_call_init (i32 _Argc, i8** _Argv) { - _libcore_Argc = _Argc; - _libcore_Argv = _Argv; - - main(); - - flow.exit(0); - } + main(); + + flow.exit(0); } \ No newline at end of file diff --git a/core/io.sp b/core/io.sp index 3bd3f7a..53c7459 100644 --- a/core/io.sp +++ b/core/io.sp @@ -1,9 +1,17 @@ -import core/__internal/io/linux; +let { os } in @'core/os'; +let { string } in @'core/string'; +let { alloc } in @'core/allocate'; -namespace io { - - @outln (str String) { - out(string.concat(String,'\n')); - } - +let @out (String str) in { + os.write(1,(i8*)str,string.len(str)); +} + +let @in : String in { + i8* buffer = cast(i8*,alloc.memalloc(256)); + os.read(0,buffer,256); + return (String)buffer; +} + +let @outln (String str) in { + out(string.concat(str,'\n')); } \ No newline at end of file diff --git a/core/linux.sp b/core/linux.sp index 3d6e4fc..625de0b 100644 --- a/core/linux.sp +++ b/core/linux.sp @@ -1 +1,3 @@ -import core/__internal/linux/x64; \ No newline at end of file +let compmacro('ifarch','x86-64') in { + let {} in @'core/__internal/linux/x64'; +} \ No newline at end of file diff --git a/core/os.sp b/core/os.sp new file mode 100644 index 0000000..e40f4ee --- /dev/null +++ b/core/os.sp @@ -0,0 +1,7 @@ +let compmacro('ifposix') in { + let {} in @'core/__internal/os/posix'; +} + +let compmacro('ifnt') in { + let {} in @'core/__internal/os/nt'; +} \ No newline at end of file diff --git a/core/string.sp b/core/string.sp index 66d07e9..9760487 100644 --- a/core/string.sp +++ b/core/string.sp @@ -1,35 +1,32 @@ -import core/allocate; +let { alloc } in @'core/allocate'; -namespace string { - - @len (u64) (str string) { - i8* ptr = (i8*)string; - u64 length = 0; - while(ptr[length] != 0) - { - length += 1; - } - return length; +let @len (String string) : u64 in { + let ptr = cast(i8*,string); + let length : u64 = 0; + while(ptr[length] != 0) + { + length += 1; } + return length; +} - @concat (str) (str a, str b) { - u64 len_a = len(a); - u64 len_b = len(b); - u64 final_size = len_a + len_b; - i8* chars = (i8*)allocate.memalloc(final_size + 1); - clone(a,chars,len_a); - clone(b,chars + len_a,len_b); - chars[final_size] = 0; - return (str)chars; - } +let @concat (String a, String b) : String in { + let len_a = len(a); + let len_b = len(b); + let final_size = len_a + len_b; + let chars = cast(i8*,alloc.memalloc(final_size + 1)); + clone(a,chars,len_a); + clone(b,chars + len_a,len_b); + chars[final_size] = 0; + return (String)chars; +} - @clone (str string, i8* buffer, u64 max_copy_size) { - u64 chars_cloned = 0; - i8* ptr = (i8*)string; - while(chars_cloned <= max_copy_size and ptr[chars_cloned] != 0) - { - buffer[chars_cloned] = ptr[chars_cloned]; - chars_cloned += 1; - } +let @clone (str string, i8* buffer, u64 max_copy_size) in { + let chars_cloned : u64 = 0; + let ptr = cast(i8*,string); + while(chars_cloned <= max_copy_size and ptr[chars_cloned] != 0) + { + buffer[chars_cloned] = ptr[chars_cloned]; + chars_cloned += 1; } } \ No newline at end of file diff --git a/examples/new-syntax.sp b/examples/new-syntax.sp new file mode 100644 index 0000000..77a1e60 --- /dev/null +++ b/examples/new-syntax.sp @@ -0,0 +1,12 @@ +let { io } in @'core/io'; + +let good_food : String = 'watermelon'; + +let @main : i32 in { + + io.outln('Hello world!'); + + io.outf('My favorite food is %s\n',good_food); + + return 0; +} \ No newline at end of file