Compare commits

...

2 Commits

Author SHA1 Message Date
c6906a65c4 pub, mod, anno syntax 2024-12-31 00:24:22 +01:00
c45682a77d pub stdlib 2024-12-31 00:24:09 +01:00
2 changed files with 40 additions and 35 deletions

View File

@ -8,7 +8,7 @@ if exists("b:current_syntax")
endif
syn keyword Keyword break return let fn loop if else struct import or and not while for in
syn keyword Keyword break return let fn loop if else struct import or and not while for in mod pub
syn keyword Special null
syn keyword Type int string bool
syn keyword Boolean true false
@ -48,6 +48,7 @@ syn match Comment "//.*$" contains=Todo
syn region Comment start=+/\*+ end=+\*/+ contains=Todo
syn match Identifier '[a-z_]\w*'
syn match Type '[A-Z]\w*'
@ -57,4 +58,8 @@ syn match Function ' \zs[a-zA-Z_]\w*\ze\s\{-}<.\{-}>\s\{-}(.\{-})'
syn region sligeBlock start="{" end="}" transparent fold
syn region sligeAnno start="#!\?\[" end="]" contains=Identifier,Type
hi def link sligeAnno PreProc
let b:current_syntax = "slige"

View File

@ -2,59 +2,59 @@
// stdlib.slg
#[builtin(Exit)]
fn exit(status_code: int) {}
pub fn exit(status_code: int) {}
#[builtin(Print)]
fn print(msg: string) {}
pub fn print(msg: string) {}
msg + "\n"
fn println(msg: string) { print) }
pub fn println(msg: string) { print) }
#[builtin(IntToString)]
fn int_to_string(number: int) -> string {}
pub fn int_to_string(number: int) -> string {}
#[builtin(StringPushChar)]
fn string_push_char(str: string, value: int) -> string {}
pub fn string_push_char(str: string, value: int) -> string {}
#[builtin(StringCharAt)]
fn string_char_at(str: string, index: int) -> int {}
pub fn string_char_at(str: string, index: int) -> int {}
#[builtin(StringLength)]
fn string_length(str: string) -> int {}
pub fn string_length(str: string) -> int {}
#[builtin(StringToInt)]
fn string_to_int(str: string) -> int {}
pub fn string_to_int(str: string) -> int {}
#[builtin(ArrayNew)]
fn array_new<T>() -> [T] {}
pub fn array_new<T>() -> [T] {}
#[builtin(ArrayPush)]
fn array_push<T>(array: [T], value: T) {}
pub fn array_push<T>(array: [T], value: T) {}
#[builtin(ArrayLength)]
fn array_length<T>(array: [T]) -> int {}
pub fn array_length<T>(array: [T]) -> int {}
#[builtin(ArrayAt)]
fn array_at<T>(array: [T], index: int) -> T {}
pub fn array_at<T>(array: [T], index: int) -> T {}
#[builtin(FileOpen)]
fn file_open(filename: string, mode: string) -> int {}
pub fn file_open(filename: string, mode: string) -> int {}
#[builtin(FileClose)]
fn file_close(file: int) {}
pub fn file_close(file: int) {}
#[builtin(FileWriteString)]
fn file_write_string(file: int, content: string) -> int {}
pub fn file_write_string(file: int, content: string) -> int {}
#[builtin(FileReadChar)]
fn file_read_char(file: int) -> int {}
pub fn file_read_char(file: int) -> int {}
#[builtin(FileReadToString)]
fn file_read_to_string(file: int) -> string {}
pub fn file_read_to_string(file: int) -> string {}
#[builtin(FileFlush)]
fn file_flush(file: int) {}
pub fn file_flush(file: int) {}
#[builtin(FileEof)]
fn file_eof(file: int) -> bool {}
pub fn file_eof(file: int) -> bool {}
#[builtin(IntToString)]
fn itos(number: int) -> string {}
pub fn itos(number: int) -> string {}
#[builtin(StringToInt)]
fn stoi(str: string) -> int {}
pub fn stoi(str: string) -> int {}
fn stdin() -> int { 0 }
fn stdout() -> int { 1 }
fn stderr() -> int { 2 }
pub fn stdin() -> int { 0 }
pub fn stdout() -> int { 1 }
pub fn stderr() -> int { 2 }
fn file_read_line(file: int) -> string {
pub fn file_read_line(file: int) -> string {
let line = "";
loop {
if file_eof(file) {
@ -69,20 +69,20 @@ fn file_read_line(file: int) -> string {
line
}
fn read_text_file(filename: string) -> string {
pub fn read_text_file(filename: string) -> string {
let file = file_open(filename, "r");
let text = file_read_to_string(file);
file_close(file);
text
}
fn input(prompt: string) -> string {
pub fn input(prompt: string) -> string {
print("> ");
file_flush(stdout());
file_read_line(stdin())
}
fn string_abs(number: int) -> int {
pub fn string_abs(number: int) -> int {
let result = number;
if number < 0 {
result = number - (number * 2);
@ -90,7 +90,7 @@ fn string_abs(number: int) -> int {
result
}
fn string_split(str: string, seperator: int) -> [string] {
pub fn string_split(str: string, seperator: int) -> [string] {
let result = array_new::<string>();
let i = 0;
@ -112,7 +112,7 @@ fn string_split(str: string, seperator: int) -> [string] {
result
}
fn string_slice(str: string, from: int, to: int) -> string {
pub fn string_slice(str: string, from: int, to: int) -> string {
let result = "";
let i = from;
loop {
@ -128,7 +128,7 @@ fn string_slice(str: string, from: int, to: int) -> string {
result
}
fn string_contains(str: string, ch: int) -> bool {
pub fn string_contains(str: string, ch: int) -> bool {
let len = string_length(str);
for (let i = 0; i < len; i += 1) {
if str[i] == ch {
@ -138,7 +138,7 @@ fn string_contains(str: string, ch: int) -> bool {
false
}
fn array_clone<T>(array: [T]) -> [T] {
pub fn array_clone<T>(array: [T]) -> [T] {
let len = array_length(array);
let result = array_new::<T>();
let i = 0;
@ -150,7 +150,7 @@ fn array_clone<T>(array: [T]) -> [T] {
result
}
fn array_sort_mut(array: [int]) {
pub fn array_sort_mut(array: [int]) {
let len = array_length(array);
for (let i = 0; i < len; i += 1) {
for (let j = i + 1; j < len; j += 1) {
@ -163,7 +163,7 @@ fn array_sort_mut(array: [int]) {
}
}
fn array_to_sorted(array: [int]) -> [int] {
pub fn array_to_sorted(array: [int]) -> [int] {
let cloned = array_clone(array);
array_sort_mut(array);
cloned