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 { ident, filePath: modFilePath } = stmt.kind;
|
||||||
const ast = this.parseFile(
|
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 = {
|
stmt.kind = { type: "mod", ident, mod: { filePath, ast } };
|
||||||
type: "mod",
|
|
||||||
ident,
|
|
||||||
mod: { filePath, ast },
|
|
||||||
};
|
|
||||||
visitStmts(ast, this, filePath);
|
visitStmts(ast, this, filePath);
|
||||||
return "stop";
|
return "stop";
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,11 @@ export class SpecialLoopDesugarer implements AstVisitor {
|
|||||||
value: Expr({
|
value: Expr({
|
||||||
type: "call",
|
type: "call",
|
||||||
subject: Expr({
|
subject: Expr({
|
||||||
type: "ident",
|
type: "path",
|
||||||
|
subject: Expr({
|
||||||
|
type: "ident",
|
||||||
|
ident: "std",
|
||||||
|
}),
|
||||||
ident: "array_length",
|
ident: "array_length",
|
||||||
}),
|
}),
|
||||||
args: [
|
args: [
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
Anno,
|
|
||||||
AssignType,
|
AssignType,
|
||||||
AstCreator,
|
AstCreator,
|
||||||
BinaryType,
|
BinaryType,
|
||||||
@ -245,6 +244,10 @@ export class Parser {
|
|||||||
}
|
}
|
||||||
const ident = this.current().identValue!;
|
const ident = this.current().identValue!;
|
||||||
this.step();
|
this.step();
|
||||||
|
if (this.test(";")) {
|
||||||
|
this.eatSemicolon();
|
||||||
|
return this.stmt({ type: "mod_file", ident, filePath: ident }, pos);
|
||||||
|
}
|
||||||
if (this.test("string")) {
|
if (this.test("string")) {
|
||||||
const filePath = this.current().stringValue!;
|
const filePath = this.current().stringValue!;
|
||||||
this.step();
|
this.step();
|
||||||
|
@ -52,8 +52,12 @@ syn region Comment start=+/\*+ end=+\*/+ contains=Todo
|
|||||||
syn match Identifier '[a-z_]\w*'
|
syn match Identifier '[a-z_]\w*'
|
||||||
syn match Type '[A-Z]\w*'
|
syn match Type '[A-Z]\w*'
|
||||||
|
|
||||||
|
|
||||||
syn match Function '[a-zA-Z_]\w*\ze\s\{-}(.\{-})'
|
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 '[a-zA-Z_]\w*\ze\s\{-}::<.\{-}>'
|
||||||
|
|
||||||
syn match Function ' \zs[a-zA-Z_]\w*\ze\s\{-}<.\{-}>\s\{-}(.\{-})'
|
syn match Function ' \zs[a-zA-Z_]\w*\ze\s\{-}<.\{-}>\s\{-}(.\{-})'
|
||||||
|
|
||||||
syn region sligeBlock start="{" end="}" transparent fold
|
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
|
syn region sligeAnno start="#!\?\[" end="]" contains=Identifier,Type
|
||||||
|
|
||||||
hi def link sligeAnno PreProc
|
hi def link sligeAnno PreProc
|
||||||
|
hi def link sligePath Include
|
||||||
|
|
||||||
let b:current_syntax = "slige"
|
let b:current_syntax = "slige"
|
||||||
|
@ -1,31 +1,20 @@
|
|||||||
//
|
mod std;
|
||||||
|
|
||||||
//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)] {}
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let strings = array_new::<string>();
|
let strings = std::array_new::<string>();
|
||||||
array_push(strings, "hello");
|
std::array_push(strings, "hello");
|
||||||
array_push(strings, "world");
|
std::array_push(strings, "world");
|
||||||
|
|
||||||
let ints = array_new::<int>();
|
let ints = std::array_new::<int>();
|
||||||
array_push(ints, 1);
|
std::array_push(ints, 1);
|
||||||
array_push(ints, 2);
|
std::array_push(ints, 2);
|
||||||
|
|
||||||
for v in strings {
|
for v in strings {
|
||||||
println(v)
|
std::println(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
for v in ints {
|
for v in ints {
|
||||||
println(itos(v))
|
std::println(std::itos(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ pub fn exit(status_code: int) {}
|
|||||||
|
|
||||||
#[builtin(Print)]
|
#[builtin(Print)]
|
||||||
pub fn print(msg: string) {}
|
pub fn print(msg: string) {}
|
||||||
msg + "\n"
|
pub fn println(msg: string) { print(msg + "\n") }
|
||||||
pub fn println(msg: string) { print) }
|
|
||||||
|
|
||||||
#[builtin(IntToString)]
|
#[builtin(IntToString)]
|
||||||
pub fn int_to_string(number: int) -> string {}
|
pub fn int_to_string(number: int) -> string {}
|
Loading…
Reference in New Issue
Block a user