143 lines
2.3 KiB
Plaintext
143 lines
2.3 KiB
Plaintext
#!role(ops)
|
|
|
|
// 语言运算符协议。运算符解析只认本模块的 shape;
|
|
|
|
// 用户模块里的同名 shape 不参与语言分派。
|
|
|
|
type Ordering = enum {
|
|
Less,
|
|
Equal,
|
|
Greater,
|
|
};
|
|
|
|
#lang(add)
|
|
type Add = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn add(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(sub)
|
|
type Sub = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn sub(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(mul)
|
|
type Mul = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn mul(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(div)
|
|
type Div = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn div(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(mod)
|
|
type Mod = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn rem(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(neg)
|
|
type Neg = shape {
|
|
type Output;
|
|
fn neg(@Self value: @self): Output;
|
|
};
|
|
|
|
#lang(bit_and)
|
|
type BitAnd = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn bit_and(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(bit_or)
|
|
type BitOr = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn bit_or(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(bit_xor)
|
|
type BitXor = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn bit_xor(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(shl)
|
|
type Shl = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn shl(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(shr)
|
|
type Shr = shape {
|
|
type Rhs;
|
|
type Output;
|
|
fn shr(@Self lhs: @self, rhs: Rhs): Output;
|
|
};
|
|
|
|
#lang(bit_not)
|
|
type BitNot = shape {
|
|
type Output;
|
|
fn bit_not(@Self value: @self): Output;
|
|
};
|
|
|
|
#lang(eq)
|
|
type Eq = shape {
|
|
type Rhs;
|
|
fn eq(@Self lhs: @self, rhs: Rhs): bool;
|
|
};
|
|
|
|
#lang(ord)
|
|
type Ord = shape {
|
|
type Rhs;
|
|
fn cmp(@Self lhs: @self, rhs: Rhs): Ordering;
|
|
};
|
|
|
|
#lang(index)
|
|
type Index = shape {
|
|
type Output;
|
|
fn index(@Self self: *@self, idx: usize): *Output;
|
|
};
|
|
|
|
type Len = shape {
|
|
fn len(@Self self: @self): usize;
|
|
};
|
|
|
|
comptime fn Step(T: type): type {
|
|
ret enum {
|
|
Item: T,
|
|
Done,
|
|
};
|
|
}
|
|
|
|
#lang(call)
|
|
type Call = shape {
|
|
type Args;
|
|
type Output;
|
|
fn call(self: @self, args: Args): Output;
|
|
};
|
|
|
|
#lang(iter)
|
|
type Iter = shape {
|
|
type Item;
|
|
fn next(@Self self: *@self): @Step(Item);
|
|
};
|
|
|
|
#lang(into_iter)
|
|
type IntoIter = shape {
|
|
type Item;
|
|
type Iter;
|
|
fn iter(@Self self: *@self): Iter;
|
|
};
|