Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
erode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
erode
Commits
11982323
Commit
11982323
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
move to new syntax, wip5
parent
3f81d391
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/wip.rs
+9
-2
9 additions, 2 deletions
examples/wip.rs
src/check.rs
+12
-12
12 additions, 12 deletions
src/check.rs
src/grammar.lalrpop
+17
-31
17 additions, 31 deletions
src/grammar.lalrpop
tests/test_check.rs
+1
-1
1 addition, 1 deletion
tests/test_check.rs
with
39 additions
and
46 deletions
examples/wip.rs
+
9
−
2
View file @
11982323
fn
main
()
{
{}
a
;
// {}
let
mut
a
=
5
;
a
=
5
;
// a = { 7 }
}
fn
b
(
x
:
i32
)
->
i32
{
x
;
}
This diff is collapsed.
Click to expand it.
src/check.rs
+
12
−
12
View file @
11982323
...
...
@@ -41,7 +41,7 @@ fn expr_type(
e
:
&
Expr
,
fn_env
:
&
FnEnv
,
type_env
:
&
TypeEnv
,
var_env
:
&
VarEnv
,
var_env
:
&
mut
VarEnv
,
)
->
Result
<
Type
,
Error
>
{
use
Expr
::
*
;
trace!
(
"expr_type {}"
,
e
);
...
...
@@ -188,7 +188,7 @@ fn expr_type(
}
}
Block
(
b
)
=>
panic!
(
),
Block
(
b
)
=>
check_stmts
(
b
,
fn_env
,
type_env
,
var_env
),
Stmt
(
s
)
=>
panic!
(),
}
...
...
@@ -478,24 +478,24 @@ fn test_expr_type() {
// type of number
assert_eq!
(
expr_type
(
&
Expr
::
Num
(
1
),
&
fn_env
,
&
type_env
,
&
var_env
),
expr_type
(
&
Expr
::
Num
(
1
),
&
fn_env
,
&
type_env
,
&
mut
var_env
),
Ok
(
I32
)
);
// type of variables
// not found
assert!
(
expr_type
(
&
Expr
::
Id
(
"a"
.to_string
()),
&
fn_env
,
&
type_env
,
&
var_env
)
.is_err
());
assert!
(
expr_type
(
&
Expr
::
Id
(
"a"
.to_string
()),
&
fn_env
,
&
type_env
,
&
mut
var_env
)
.is_err
());
// let i: i32 ...
assert_eq!
(
expr_type
(
&
Expr
::
Id
(
"i"
.to_string
()),
&
fn_env
,
&
type_env
,
&
var_env
),
expr_type
(
&
Expr
::
Id
(
"i"
.to_string
()),
&
fn_env
,
&
type_env
,
&
mut
var_env
),
Ok
(
I32
)
);
// let j ... (has no type yet)
assert_eq!
(
expr_type
(
&
Expr
::
Id
(
"j"
.to_string
()),
&
fn_env
,
&
type_env
,
&
var_env
),
expr_type
(
&
Expr
::
Id
(
"j"
.to_string
()),
&
fn_env
,
&
type_env
,
&
mut
var_env
),
Ok
(
Unknown
)
);
...
...
@@ -511,7 +511,7 @@ fn test_expr_type() {
&*
ExprParser
::
new
()
.parse
(
"1 + 2 - 5"
)
.unwrap
(),
&
fn_env
,
&
type_env
,
&
var_env
&
mut
var_env
),
Ok
(
I32
)
);
...
...
@@ -522,7 +522,7 @@ fn test_expr_type() {
&*
ExprParser
::
new
()
.parse
(
"- 5"
)
.unwrap
(),
&
fn_env
,
&
type_env
,
&
var_env
&
mut
var_env
),
Ok
(
I32
)
);
...
...
@@ -533,7 +533,7 @@ fn test_expr_type() {
&*
ExprParser
::
new
()
.parse
(
"b(1)"
)
.unwrap
(),
&
fn_env
,
&
type_env
,
&
var_env
&
mut
var_env
),
Ok
(
I32
)
);
...
...
@@ -544,7 +544,7 @@ fn test_expr_type() {
&*
ExprParser
::
new
()
.parse
(
"b(i)"
)
.unwrap
(),
&
fn_env
,
&
type_env
,
&
var_env
&
mut
var_env
),
Ok
(
I32
)
);
...
...
@@ -554,7 +554,7 @@ fn test_expr_type() {
&*
ExprParser
::
new
()
.parse
(
"b(1, 2)"
)
.unwrap
(),
&
fn_env
,
&
type_env
,
&
var_env
&
mut
var_env
)
.is_err
());
...
...
@@ -563,7 +563,7 @@ fn test_expr_type() {
&*
ExprParser
::
new
()
.parse
(
"b(true)"
)
.unwrap
(),
&
fn_env
,
&
type_env
,
&
var_env
&
mut
var_env
)
.is_err
());
...
...
This diff is collapsed.
Click to expand it.
src/grammar.lalrpop
+
17
−
31
View file @
11982323
...
...
@@ -27,11 +27,7 @@ Comma<T>: Vec<T> = {
// A comma separated sequence without trailing comma
CommaNoTrail<T>: Vec<T> = {
<v:(<T> ",")*> <e:T> => {
let mut v = v;
v.push(e);
v
}
<mut v:(<T> ",")*> <e:T> => { v.push(e); v }
}
// Parenthesized, comma delimeted
...
...
@@ -135,22 +131,20 @@ Type : Type = {
"&" "mut" <Type> => Type::Ref(Box::new(Type::Mut(Box::new(<>)))),
}
// pub Stmts: Stmts = {
// <s: (<Stmt> ";")*> <e: Stmt?> => match e {
// // stmts return ()
// None => Stmts { stmts: s, ret: true },
// // last statement is the return value
// Some(e) => {
// let mut s = s;
// s.push(e);
// Stmts { stmts: s, ret: false }
// },
// }
// }
pub Block: Stmts = {
"{" <sts: StmtSeq*> <st: Stmt?> "}"
=> Stmts { stmts: sts, ret: false },
"{" <mut stmts: StmtSeq*> <st: Stmt?> "}" => {
match &st {
Some(st) => stmts.push(st.clone()),
_ =>(),
};
Stmts {
stmts,
ret: match st {
Some(Stmt::Semi) => true,
_ => false
}
}
}
}
StmtSeq: Stmt = {
...
...
@@ -166,18 +160,11 @@ StmtBlock: Stmts = {
Stmt: Stmt = {
";" => Stmt::Semi,
//"let" <m: "mut"?> <id: Id> <t: (":" <Type>)?> <e: ("=" <Expr>)?> => Stmt::Let(id, m.is_some(), t, e),
// <Expr> "=" <Expr> => Stmt::Assign(<>),
// "while" <Expr> "{" <Block> "}" => Stmt::While(<>),
// "if" <Expr> <Block> < ("else" <Block>)?> => Stmt::If(<>),
"let" <m: "mut"?> <id: Id> <t: (":" <Type>)?> <e: ("=" <Expr>)?> => Stmt::Let(id, m.is_some(), t, e),
<Expr> "=" <Expr> => Stmt::Assign(<>),
<ExprNoBlock> => Stmt::Expr(<>),
// <Block> => Stmt::Block(<>),
}
pub Exprs : Exprs = {
ParCNT<ExprNoBlock> => Exprs( <> ),
}
...
...
@@ -195,8 +182,7 @@ pub ExprBlock: Box<Expr> = {
Block => Box::new(Expr::Block(<>)),
}
pub ExprNoBlock: Box<Expr> = {
// ExprNoBlock Cmp Expr1 => (),
ExprNoBlock = {
Expr1,
}
...
...
This diff is collapsed.
Click to expand it.
tests/test_check.rs
+
1
−
1
View file @
11982323
...
...
@@ -177,5 +177,5 @@ fn check_let_if() {
#[test]
fn
wip
()
{
assert!
(
check
(
&
read_file
::
parse
(
"examples/wip.rs"
))
.is_
err
()
);
let
_
=
check
(
&
read_file
::
parse
(
"examples/wip.rs"
))
.is_
ok
(
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment