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 { let @memalloc (u64 size) : void* in {
@memalloc (void*) (u64 size) { }
} let @memfree (void* ptr) in {
@memfree (void* ptr) {
}
} }

View File

@ -1,9 +1,10 @@
import core/linux; let compmacro('ifsystem','linux') in {
let { posix } in @'core/linux';
namespace flow { }
let compmacro('ifsystem','darwin') in {
@exit (i32 code) { let { posix } in @'core/darwin';
linux.sys_exit(code); }
}
let @exit (i32 code) in {
posix.sys_exit(code);
} }

View File

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

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; let @__libcore_call_init (i32 _Argc, i8** _Argv) in {
i8** _libcore_Argv; _libcore_Argc = _Argc;
_libcore_Argv = _Argv;
@__libcore_call_init (i32 _Argc, i8** _Argv) { main();
_libcore_Argc = _Argc;
_libcore_Argv = _Argv;
main(); flow.exit(0);
flow.exit(0);
}
} }

View File

@ -1,9 +1,17 @@
import core/__internal/io/linux; let { os } in @'core/os';
let { string } in @'core/string';
namespace io { let { alloc } in @'core/allocate';
@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'));
} }

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 { let @len (String string) : u64 in {
let ptr = cast(i8*,string);
@len (u64) (str string) { let length : u64 = 0;
i8* ptr = (i8*)string; while(ptr[length] != 0)
u64 length = 0; {
while(ptr[length] != 0) length += 1;
{
length += 1;
}
return length;
} }
return length;
}
@concat (str) (str a, str b) { let @concat (String a, String b) : String in {
u64 len_a = len(a); let len_a = len(a);
u64 len_b = len(b); let len_b = len(b);
u64 final_size = len_a + len_b; let final_size = len_a + len_b;
i8* chars = (i8*)allocate.memalloc(final_size + 1); let chars = cast(i8*,alloc.memalloc(final_size + 1));
clone(a,chars,len_a); clone(a,chars,len_a);
clone(b,chars + len_a,len_b); clone(b,chars + len_a,len_b);
chars[final_size] = 0; chars[final_size] = 0;
return (str)chars; return (String)chars;
} }
@clone (str string, i8* buffer, u64 max_copy_size) { let @clone (str string, i8* buffer, u64 max_copy_size) in {
u64 chars_cloned = 0; let chars_cloned : u64 = 0;
i8* ptr = (i8*)string; let ptr = cast(i8*,string);
while(chars_cloned <= max_copy_size and ptr[chars_cloned] != 0) while(chars_cloned <= max_copy_size and ptr[chars_cloned] != 0)
{ {
buffer[chars_cloned] = ptr[chars_cloned]; buffer[chars_cloned] = ptr[chars_cloned];
chars_cloned += 1; 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;
}