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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
erode
Commits
54da96ec
Commit
54da96ec
authored
Sep 16, 2020
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
check call
parent
88413cd2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ast.rs
+0
-1
0 additions, 1 deletion
src/ast.rs
src/check.rs
+52
-42
52 additions, 42 deletions
src/check.rs
src/env.rs
+0
-1
0 additions, 1 deletion
src/env.rs
with
52 additions
and
44 deletions
src/ast.rs
+
0
−
1
View file @
54da96ec
...
@@ -47,7 +47,6 @@ pub struct Param {
...
@@ -47,7 +47,6 @@ pub struct Param {
pub
id
:
Id
,
pub
id
:
Id
,
pub
ty
:
Type
,
pub
ty
:
Type
,
}
}
// pub bool, pub Id, pub Type);
#[derive(Debug,
PartialEq)]
#[derive(Debug,
PartialEq)]
pub
enum
TypeDecl
{
pub
enum
TypeDecl
{
...
...
This diff is collapsed.
Click to expand it.
src/check.rs
+
52
−
42
View file @
54da96ec
...
@@ -98,43 +98,44 @@ fn expr_type(
...
@@ -98,43 +98,44 @@ fn expr_type(
// Err(format!("op {} rt {}", opt, rt))
// Err(format!("op {} rt {}", opt, rt))
// }
// }
// }
// }
// Call(s, args) => {
Call
(
s
,
args
)
=>
{
// trace!("call {} with {}", s, args);
trace!
(
"call {} with {}"
,
s
,
args
);
// let argt: Vec<Type> = args
let
arg_t
:
Vec
<
Type
>
=
args
// .clone()
.clone
()
// .0
.0
// .into_iter()
.into_iter
()
// .map(|e| expr_type(&*e, fn_env, type_env, var_env))
.map
(|
e
|
expr_type
(
&*
e
,
fn_env
,
type_env
,
var_env
))
// .collect::<Result<_, _>>()?;
.collect
::
<
Result
<
_
,
_
>>
()
?
;
// trace!("arg types {:?}", argt);
trace!
(
"arg types {:?}"
,
arg_t
);
// let f = match fn_env.get(s.as_str()) {
let
f
=
match
fn_env
.get
(
s
.as_str
())
{
// Some(f) => f,
Some
(
f
)
=>
f
,
// None => Err(format!("{} not found", s))?,
None
=>
Err
(
format!
(
"{} not found"
,
s
))
?
,
// };
};
// let part: Vec<Type> = (f.params.0.clone())
let
par_t
:
Vec
<
Type
>
=
(
f
.params
.0
.clone
())
// .into_iter()
.into_iter
()
// .map(|p| From::from(&p))
.map
(|
p
|
From
::
from
(
&
p
))
// .collect();
.collect
();
// trace!(
trace!
(
// "fn to call {} with params {} and types {:?}",
"fn to call {} with params {} and types {:?}"
,
// f,
f
,
// f.params,
f
.params
,
// part
par_t
// );
);
// if argt == part {
if
arg_t
==
par_t
{
// Ok((false, f.result.clone()))
Ok
(
f
.result
.clone
())
// } else {
}
else
{
// Err(format!(
Err
(
format!
(
// "arguments types {:?} does not match parameter types {:?}",
"arguments types {:?} does not match parameter types {:?}"
,
// argt, part
arg_t
,
par_t
// ))
))
// }
}
// }
}
Id
(
id
)
=>
match
var_env
.get
(
id
.to_string
())
{
Id
(
id
)
=>
match
var_env
.get
(
id
.to_string
())
{
Some
(
t
)
=>
Ok
(
t
.clone
()),
Some
(
t
)
=>
Ok
(
t
.clone
()),
None
=>
Err
(
format!
(
"variable not found {}"
,
id
)),
None
=>
Err
(
format!
(
"variable not found {}"
,
id
)),
...
@@ -341,18 +342,27 @@ pub fn check(p: &Program) -> Result<(), Error> {
...
@@ -341,18 +342,27 @@ pub fn check(p: &Program) -> Result<(), Error> {
// build a scope for the arguments
// build a scope for the arguments
let
mut
arg_ty
=
IdType
::
new
();
let
mut
arg_ty
=
IdType
::
new
();
for
Param
{
is_mut
,
id
,
ty
}
in
fd
.params
.0
.iter
()
{
for
Param
{
is_mut
,
id
,
ty
}
in
fd
.params
.0
.iter
()
{
// TODO move is_mut to Type in parser
let
ty
=
match
*
is_mut
{
arg_ty
.insert
(
id
.to_owned
(),
ty
.clone
());
true
=>
Type
::
Mut
(
Box
::
new
(
ty
.clone
())),
_
=>
ty
.clone
(),
};
arg_ty
.insert
(
id
.to_owned
(),
ty
);
}
}
var_env
.push_param_scope
(
arg_ty
);
var_env
.push_param_scope
(
arg_ty
);
let
stmt_type
=
check_stmts
(
&
fd
.body
,
&
fn_env
,
&
type_env
,
&
mut
var_env
);
let
stmt_type
=
check_stmts
(
&
fd
.body
,
&
fn_env
,
&
type_env
,
&
mut
var_env
);
trace!
(
"function id {}: {:?}"
,
fd
.id
,
stmt_type
);
trace!
(
"function id {}: {:?}"
,
fd
.id
,
&
stmt_type
);
if
stmt_type
?
!=
fd
.result
{
let
stmt_type
=
stmt_type
?
;
Err
(
format!
(
"return value does not match statements"
))
?
;
if
stmt_type
!=
fd
.result
{
Err
(
format!
(
"return type {} does not match statements type {}"
,
fd
.result
,
stmt_type
))
?
;
}
}
}
}
Ok
(())
Ok
(())
...
...
This diff is collapsed.
Click to expand it.
src/env.rs
+
0
−
1
View file @
54da96ec
...
@@ -53,7 +53,6 @@ impl VarEnv {
...
@@ -53,7 +53,6 @@ impl VarEnv {
}
}
pub
fn
update
(
&
mut
self
,
id
:
String
,
ty
:
Type
)
->
Result
<
(),
Error
>
{
pub
fn
update
(
&
mut
self
,
id
:
String
,
ty
:
Type
)
->
Result
<
(),
Error
>
{
use
Type
::
*
;
match
self
.get_mut
(
id
.clone
())
{
match
self
.get_mut
(
id
.clone
())
{
Some
(
ot
)
=>
match
ot
{
Some
(
ot
)
=>
match
ot
{
Type
::
Unknown
=>
{
Type
::
Unknown
=>
{
...
...
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