new changes i said

This commit is contained in:
apio 2022-06-09 17:24:50 +02:00
parent ca9da4c330
commit 243894a026
9 changed files with 84 additions and 68 deletions

View File

@ -1,11 +1,7 @@
namespace allocate {
@memalloc (void*) (u64 size) {
}
@memfree (void* ptr) {
}
let @memalloc (u64 size) : void* in {
}
let @memfree (void* ptr) in {
}

View File

@ -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);
}

View File

@ -1,5 +1 @@
import core/linux;
namespace fs {
}
let { os } in @'core/os';

View File

@ -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();
main();
flow.exit(0);
}
flow.exit(0);
}

View File

@ -1,9 +1,17 @@
import core/__internal/io/linux;
namespace io {
@outln (str String) {
out(string.concat(String,'\n'));
}
let { os } in @'core/os';
let { string } in @'core/string';
let { alloc } in @'core/allocate';
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'));
}

View File

@ -1 +1,3 @@
import core/__internal/linux/x64;
let compmacro('ifarch','x86-64') in {
let {} in @'core/__internal/linux/x64';
}

7
core/os.sp Normal file
View File

@ -0,0 +1,7 @@
let compmacro('ifposix') in {
let {} in @'core/__internal/os/posix';
}
let compmacro('ifnt') in {
let {} in @'core/__internal/os/nt';
}

View File

@ -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;
}
}

12
examples/new-syntax.sp Normal file
View File

@ -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;
}