mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 07:26:30 +00:00
mod std
This commit is contained in:
parent
9f17396571
commit
d981e60f8f
@ -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";
|
||||
}
|
||||
|
@ -78,8 +78,12 @@ export class SpecialLoopDesugarer implements AstVisitor {
|
||||
param: { ident: "::length", pos: npos },
|
||||
value: Expr({
|
||||
type: "call",
|
||||
subject: Expr({
|
||||
type: "path",
|
||||
subject: Expr({
|
||||
type: "ident",
|
||||
ident: "std",
|
||||
}),
|
||||
ident: "array_length",
|
||||
}),
|
||||
args: [
|
||||
|
@ -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();
|
||||
|
@ -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"
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {}
|
Loading…
Reference in New Issue
Block a user