This commit is contained in:
sfja 2024-12-31 00:54:58 +01:00
parent c6906a65c4
commit 1bbb759981
6 changed files with 31 additions and 30 deletions

View File

@ -104,13 +104,14 @@ export class ModTree implements AstVisitor<[string]> {
}
const { ident, filePath: modFilePath } = stmt.kind;
const ast = this.parseFile(
path.join(path.dirname(filePath), modFilePath),
ident === "std"
? path.join(
path.dirname(path.fromFileUrl(Deno.mainModule)),
"../std/lib.slg",
)
: path.join(path.dirname(filePath), modFilePath),
);
stmt.kind = {
type: "mod",
ident,
mod: { filePath, ast },
};
stmt.kind = { type: "mod", ident, mod: { filePath, ast } };
visitStmts(ast, this, filePath);
return "stop";
}

View File

@ -79,7 +79,11 @@ export class SpecialLoopDesugarer implements AstVisitor {
value: Expr({
type: "call",
subject: Expr({
type: "ident",
type: "path",
subject: Expr({
type: "ident",
ident: "std",
}),
ident: "array_length",
}),
args: [

View File

@ -1,5 +1,4 @@
import {
Anno,
AssignType,
AstCreator,
BinaryType,
@ -245,6 +244,10 @@ export class Parser {
}
const ident = this.current().identValue!;
this.step();
if (this.test(";")) {
this.eatSemicolon();
return this.stmt({ type: "mod_file", ident, filePath: ident }, pos);
}
if (this.test("string")) {
const filePath = this.current().stringValue!;
this.step();

View File

@ -52,8 +52,12 @@ syn region Comment start=+/\*+ end=+\*/+ contains=Todo
syn match Identifier '[a-z_]\w*'
syn match Type '[A-Z]\w*'
syn match Function '[a-zA-Z_]\w*\ze\s\{-}(.\{-})'
syn match sligePath '[a-zA-Z_]\w*\ze\s\{-}::'
syn match Function '[a-zA-Z_]\w*\ze\s\{-}::<.\{-}>'
syn match Function ' \zs[a-zA-Z_]\w*\ze\s\{-}<.\{-}>\s\{-}(.\{-})'
syn region sligeBlock start="{" end="}" transparent fold
@ -61,5 +65,6 @@ syn region sligeBlock start="{" end="}" transparent fold
syn region sligeAnno start="#!\?\[" end="]" contains=Identifier,Type
hi def link sligeAnno PreProc
hi def link sligePath Include
let b:current_syntax = "slige"

View File

@ -1,31 +1,20 @@
//
//fn print(msg: string) #[builtin(Print)] {}
//fn println(msg: string) { print(msg + "\n") }
//
//fn itos(number: int) -> string #[builtin(IntToString)] {}
//
//fn array_new<T>() -> [T] #[builtin(ArrayNew)] {}
//fn array_push<T>(array: [T], value: T) #[builtin(ArrayPush)] {}
//fn array_length<T>(array: [T]) -> int #[builtin(ArrayLength)] {}
//fn array_at<T>(array: [T], index: int) -> T #[builtin(ArrayAt)] {}
mod std;
fn main() {
let strings = array_new::<string>();
array_push(strings, "hello");
array_push(strings, "world");
let strings = std::array_new::<string>();
std::array_push(strings, "hello");
std::array_push(strings, "world");
let ints = array_new::<int>();
array_push(ints, 1);
array_push(ints, 2);
let ints = std::array_new::<int>();
std::array_push(ints, 1);
std::array_push(ints, 2);
for v in strings {
println(v)
std::println(v)
}
for v in ints {
println(itos(v))
std::println(std::itos(v))
}
}

View File

@ -6,8 +6,7 @@ pub fn exit(status_code: int) {}
#[builtin(Print)]
pub fn print(msg: string) {}
msg + "\n"
pub fn println(msg: string) { print) }
pub fn println(msg: string) { print(msg + "\n") }
#[builtin(IntToString)]
pub fn int_to_string(number: int) -> string {}