Skip to content

Commit 85f5b79

Browse files
Bootstrap 2 (#37)
* bootstrap 2 failure. lots to do before
1 parent fa7e425 commit 85f5b79

File tree

6 files changed

+85
-12
lines changed

6 files changed

+85
-12
lines changed

bootstrap/makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
.ty/token.o:
2-
ty obj src/token.ty
1+
SRCS := $(wildcard src/*.ty)
2+
OBJS := $(patsubst src/%.ty,.ty/%.o,$(SRCS))
3+
4+
all: $(OBJS)
5+
echo $(OBJS)
6+
echo $(SRCS)
7+
touch .ty/all
8+
9+
$(OBJS): $(SRCS)
10+
ty obj $<
311

412
.PHONY: clean
513
clean:

bootstrap/src/lexer.ty

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const Token = import "token.Token"
2+
pub const TokenError = import "token.TokenError"
3+
const get_next = import "token.get_next"
4+
5+
pub type Lexeme = struct {
6+
token: Token,
7+
slice: [char],
8+
start: u32,
9+
end: u32
10+
}
11+
12+
pub type Lexer = struct {
13+
current: ?Lexeme,
14+
buffer: &[char],
15+
idx: u32,
16+
}
17+
18+
pub const new = fn(buffer: &[char]) Lexer {
19+
return Lexer {
20+
buffer: buffer,
21+
current : undefined,
22+
idx: 0
23+
}
24+
}
25+
26+
pub const peek = fn(self: *Lexer) TokenError!?Lexeme {
27+
if (self.current) {
28+
return clone self.current
29+
}
30+
let len = 0
31+
let end = self.buf.len()
32+
let result = try get_next(self.buf[self.idx..end], *len)?
33+
self.current = Lexeme {
34+
token: result,
35+
slice: clone self.buf[self.idx..len],
36+
start: self.idx,
37+
end: len
38+
}
39+
self.idx += len
40+
return clone self.current
41+
}
42+
43+
pub const collect = fn(self: *Lexer) Lexeme {
44+
let temp = clone self.current.unwrap()
45+
self.current = undefined
46+
return temp
47+
}

bootstrap/src/token.ty

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,11 @@ const build_string = fn(buf: &[char], len: *u32, end: char) TokenError!Token {
302302
}
303303
return Token.String
304304
}
305-
pub const get_next = fn(buf: &[char], len: *u32) TokenError!Token {
305+
306+
pub const get_next = fn(buf: &[char], len: *u32) TokenError!?Token {
306307
len = 0
307308
const c = buf[0]
308-
return match (c) {
309+
return match (c?) {
309310
c.isAlphabetic() => tokenize_chars(buf, len)
310311
c.isDigit() => tokenize_num(buf, len)
311312
_ => {

linter/src/lib.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
7777
Expr::UnOp(un) => match un.op.token {
7878
Token::Dash => self.check_negate(un),
7979
Token::Exclam => self.check_not(un),
80+
Token::Try => self.check_try(un),
8081
Token::Ampersand => self.check_borrow_ro(un),
8182
Token::Asterisk => self.check_borrow_mut(un),
8283
Token::Copy => self.check_copy(un),
@@ -112,6 +113,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
112113
Expr::ArgDef(arg) => self.check_arg_def(&arg),
113114
Expr::ArrayType(arr) => self.check_array_type(&arr),
114115
Expr::ArrayAccess(arr) => self.check_array_access(&arr),
116+
Expr::UndefBubble(u) => self.check_undefined_bubble(&u),
115117
_ => panic!("type-lang linter issue, expr not implemented {:?}", to_cmp),
116118
}
117119
}
@@ -750,16 +752,22 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
750752
return ok_tree!(Copy, unop, curried);
751753
}
752754

755+
pub fn check_undefined_bubble(&mut self, un: &UndefBubble) -> ResultTreeType {
756+
let result = self.lint_recurse(&un.prev)?;
757+
let unop = UnaryOp {
758+
val: result.0,
759+
curried: result.1,
760+
};
761+
let curried = unop.curried.clone();
762+
return ok_tree!(BubbleUndef, unop, curried);
763+
}
764+
753765
pub fn check_clone(&mut self, un: &UnOp) -> ResultTreeType {
754766
let result = self.lint_recurse(&un.val)?;
755-
let mut unop = UnaryOp {
767+
let unop = UnaryOp {
756768
val: result.0,
757769
curried: result.1,
758770
};
759-
match unop.val.as_ref().as_ref() {
760-
TypeTree::BoolValue(_) => unop.curried = Ty::Bool,
761-
_ => panic!("clone check failed"),
762-
}
763771
let curried = unop.curried.clone();
764772
return ok_tree!(Clone, unop, curried);
765773
}
@@ -896,6 +904,16 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
896904
return ok_tree!(NotEq, binop, curried);
897905
}
898906

907+
pub fn check_try(&mut self, un: &UnOp) -> ResultTreeType {
908+
let result = self.lint_recurse(&un.val)?;
909+
let unop = UnaryOp {
910+
val: result.0,
911+
curried: result.1,
912+
};
913+
let curried = unop.curried.clone();
914+
return ok_tree!(BubbleError, unop, curried);
915+
}
916+
899917
pub fn check_not(&mut self, un: &UnOp) -> ResultTreeType {
900918
let result = self.lint_recurse(&un.val)?;
901919
let mut unop = UnaryOp {

parser/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ impl<'s> Parser<'s> {
745745
]) {
746746
match x.token {
747747
Token::Question => self.resolve_access(expr!(UndefBubble, prev)),
748-
Token::Try => self.resolve_access(expr!(ErrBubble, prev)),
749748
Token::Period => {
750749
let ident = self
751750
.ident()

types/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ pub enum TypeTree {
230230
Range(BinaryOp),
231231
CastAs(BinaryOp),
232232
Gt(BinaryOp),
233-
BubbleUndef(BinaryOp),
234-
BubbleError(BinaryOp),
235233
// unops
234+
BubbleUndef(UnaryOp),
235+
BubbleError(UnaryOp),
236236
ReadBorrow(UnaryOp),
237237
MutBorrow(UnaryOp),
238238
Copy(UnaryOp),

0 commit comments

Comments
 (0)