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
46686c3d
Commit
46686c3d
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
bc added
parent
5f6af115
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/borrow.rs
+23
-9
23 additions, 9 deletions
src/borrow.rs
with
23 additions
and
9 deletions
src/borrow.rs
+
23
−
9
View file @
46686c3d
...
@@ -17,7 +17,15 @@ enum Val {
...
@@ -17,7 +17,15 @@ enum Val {
RefMut
(
Id
),
RefMut
(
Id
),
}
}
type
IdVal
=
HashMap
<
Id
,
(
bool
,
Val
)
>
;
#[derive(Debug,
Clone)]
pub
enum
Bc
{
Fresh
,
// Not yet accessed
Owned
,
// accessed as owned, eg let mut a = 4; _ = a + 1;
SharedRef
(
Vec
<
Id
>
),
// accessed through shared ref, e.g. let b = &a, _ = *b;
UniqueRef
(
Id
),
// accessed through unique ref, e.g. let c = &mut a, _ = *c;
}
type
IdVal
=
HashMap
<
Id
,
(
bool
,
Val
,
Bc
)
>
;
#[derive(Debug)]
#[derive(Debug)]
struct
Mem
(
VecDeque
<
IdVal
>
);
struct
Mem
(
VecDeque
<
IdVal
>
);
...
@@ -29,7 +37,7 @@ impl Mem {
...
@@ -29,7 +37,7 @@ impl Mem {
fn
get
(
&
self
,
id
:
String
)
->
Option
<&
Val
>
{
fn
get
(
&
self
,
id
:
String
)
->
Option
<&
Val
>
{
self
.0
.iter
()
.find_map
(|
hm
|
match
hm
.get
(
id
.as_str
())
{
self
.0
.iter
()
.find_map
(|
hm
|
match
hm
.get
(
id
.as_str
())
{
Some
((
_
,
v
))
=>
Some
(
v
),
// always ok to go from mut to non mut
Some
((
_
,
v
,
_
))
=>
Some
(
v
),
// always ok to go from mut to non mut
_
=>
None
,
_
=>
None
,
})
})
}
}
...
@@ -38,8 +46,8 @@ impl Mem {
...
@@ -38,8 +46,8 @@ impl Mem {
self
.0
self
.0
.iter_mut
()
.iter_mut
()
.find_map
(|
hm
|
match
hm
.get_mut
(
id
.as_str
())
{
.find_map
(|
hm
|
match
hm
.get_mut
(
id
.as_str
())
{
Some
((
true
,
v
))
=>
Some
(
v
),
// a mut reference
Some
((
true
,
v
,
_
))
=>
Some
(
v
),
// a mut reference
Some
((
_
,
v
))
=>
{
Some
((
_
,
v
,
_
))
=>
{
match
v
{
match
v
{
Val
::
Uninitialized
=>
Some
(
v
),
// an uninitialized
Val
::
Uninitialized
=>
Some
(
v
),
// an uninitialized
Val
::
RefMut
(
_
)
=>
{
Val
::
RefMut
(
_
)
=>
{
...
@@ -58,7 +66,7 @@ impl Mem {
...
@@ -58,7 +66,7 @@ impl Mem {
let
hm
=
self
.0
.front_mut
()
.unwrap
();
let
hm
=
self
.0
.front_mut
()
.unwrap
();
println!
(
"insert id {:?}, in scope {:?}"
,
id
,
hm
);
println!
(
"insert id {:?}, in scope {:?}"
,
id
,
hm
);
hm
.insert
(
id
,
(
is_mut
,
Val
::
Uninitialized
));
hm
.insert
(
id
,
(
is_mut
,
Val
::
Uninitialized
,
Bc
::
Owned
));
}
}
fn
update
(
&
mut
self
,
id
:
String
,
val
:
Val
)
{
fn
update
(
&
mut
self
,
id
:
String
,
val
:
Val
)
{
...
@@ -315,7 +323,7 @@ fn eval_fn(id: &str, args: &Vec<Val>, m: &mut Mem, fn_env: &FnEnv) -> Val {
...
@@ -315,7 +323,7 @@ fn eval_fn(id: &str, args: &Vec<Val>, m: &mut Mem, fn_env: &FnEnv) -> Val {
let
p_id_arg
:
Vec
<
(
&
(
bool
,
String
),
&
Val
)
>
=
p_id
.iter
()
.zip
(
args
)
.collect
();
let
p_id_arg
:
Vec
<
(
&
(
bool
,
String
),
&
Val
)
>
=
p_id
.iter
()
.zip
(
args
)
.collect
();
let
p_id_arg
:
IdVal
=
p_id_arg
let
p_id_arg
:
IdVal
=
p_id_arg
.into_iter
()
.into_iter
()
.map
(|(
s
,
v
)|
(
s
.1
.clone
(),
(
s
.0
,
v
.clone
())))
.map
(|(
s
,
v
)|
(
s
.1
.clone
(),
(
s
.0
,
v
.clone
()
,
Bc
::
Fresh
)))
.collect
();
.collect
();
println!
(
"args {:?}"
,
args
);
println!
(
"args {:?}"
,
args
);
...
@@ -347,9 +355,15 @@ fn test_deref() {
...
@@ -347,9 +355,15 @@ fn test_deref() {
let
mut
m
:
Mem
=
Mem
::
new
();
let
mut
m
:
Mem
=
Mem
::
new
();
let
mut
hm
=
IdVal
::
new
();
let
mut
hm
=
IdVal
::
new
();
hm
.insert
(
"a"
.to_string
(),
(
false
,
Val
::
Num
(
7
)));
hm
.insert
(
"a"
.to_string
(),
(
false
,
Val
::
Num
(
7
),
Bc
::
Fresh
));
hm
.insert
(
"b"
.to_string
(),
(
false
,
Val
::
Ref
(
"a"
.to_string
())));
hm
.insert
(
hm
.insert
(
"c"
.to_string
(),
(
false
,
Val
::
Ref
(
"b"
.to_string
())));
"b"
.to_string
(),
(
false
,
Val
::
Ref
(
"a"
.to_string
()),
Bc
::
Fresh
),
);
hm
.insert
(
"c"
.to_string
(),
(
false
,
Val
::
Ref
(
"b"
.to_string
()),
Bc
::
Fresh
),
);
m
.push_param_scope
(
hm
);
m
.push_param_scope
(
hm
);
println!
(
"mem {:?}"
,
m
);
println!
(
"mem {:?}"
,
m
);
let
e
:
Expr
=
Expr
::
Id
(
"a"
.to_string
());
let
e
:
Expr
=
Expr
::
Id
(
"a"
.to_string
());
...
...
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