Module Qcert.NNRS.Lang.NNRSVars
Require
Import
String
.
Require
Import
List
.
Require
Import
Arith
.
Require
Import
EquivDec
.
Require
Import
Morphisms
.
Require
Import
Arith
.
Require
Import
Max
.
Require
Import
Bool
.
Require
Import
Peano_dec
.
Require
Import
EquivDec
.
Require
Import
Decidable
.
Require
Import
Utils
.
Require
Import
DataRuntime
.
Require
Import
NNRS
.
Section
NNRSVars
.
Context
{
fruntime
:
foreign_runtime
}.
Context
(
h
:
brand_relation_t
).
Fixpoint
nnrs_expr_free_vars
(
e
:
nnrs_expr
) :
list
var
:=
match
e
with
|
NNRSGetConstant
_
=>
nil
|
NNRSVar
v
=>
v
::
nil
|
NNRSConst
_
=>
nil
|
NNRSBinop
_
e
₁
e
₂ =>
nnrs_expr_free_vars
e
₁ ++
nnrs_expr_free_vars
e
₂
|
NNRSUnop
_
e
₁ =>
nnrs_expr_free_vars
e
₁
|
NNRSGroupBy
_
_
e
₁ =>
nnrs_expr_free_vars
e
₁
end
.
Fixpoint
nnrs_stmt_free_env_vars
(
s
:
nnrs_stmt
) :
list
var
:=
match
s
with
|
NNRSSeq
s
₁
s
₂ =>
nnrs_stmt_free_env_vars
s
₁ ++
nnrs_stmt_free_env_vars
s
₂
|
NNRSLet
v
e
s
₀ =>
nnrs_expr_free_vars
e
++
remove
equiv_dec
v
(
nnrs_stmt_free_env_vars
s
₀)
|
NNRSLetMut
v
s
₁
s
₂ =>
nnrs_stmt_free_env_vars
s
₁ ++
remove
equiv_dec
v
(
nnrs_stmt_free_env_vars
s
₂)
|
NNRSLetMutColl
v
s
₁
s
₂ =>
nnrs_stmt_free_env_vars
s
₁ ++
remove
equiv_dec
v
(
nnrs_stmt_free_env_vars
s
₂)
|
NNRSAssign
v
e
=>
nnrs_expr_free_vars
e
|
NNRSPush
v
e
=>
nnrs_expr_free_vars
e
|
NNRSFor
v
e
s
₀ =>
nnrs_expr_free_vars
e
++
remove
equiv_dec
v
(
nnrs_stmt_free_env_vars
s
₀)
|
NNRSIf
e
s
₁
s
₂ =>
nnrs_expr_free_vars
e
++
nnrs_stmt_free_env_vars
s
₁ ++
nnrs_stmt_free_env_vars
s
₂
|
NNRSEither
e
x
₁
s
₁
x
₂
s
₂ =>
nnrs_expr_free_vars
e
++
remove
equiv_dec
x
₁ (
nnrs_stmt_free_env_vars
s
₁) ++
remove
equiv_dec
x
₂ (
nnrs_stmt_free_env_vars
s
₂)
end
.
Fixpoint
nnrs_stmt_free_mcenv_vars
(
s
:
nnrs_stmt
) :
list
var
:=
match
s
with
|
NNRSSeq
s
₁
s
₂ =>
nnrs_stmt_free_mcenv_vars
s
₁ ++
nnrs_stmt_free_mcenv_vars
s
₂
|
NNRSLet
v
e
s
₀ =>
nnrs_stmt_free_mcenv_vars
s
₀
|
NNRSLetMut
v
s
₁
s
₂ =>
nnrs_stmt_free_mcenv_vars
s
₁ ++
nnrs_stmt_free_mcenv_vars
s
₂
|
NNRSLetMutColl
v
s
₁
s
₂ =>
remove
equiv_dec
v
(
nnrs_stmt_free_mcenv_vars
s
₁) ++
nnrs_stmt_free_mcenv_vars
s
₂
|
NNRSAssign
v
e
=>
nil
|
NNRSPush
v
e
=>
v
::
nil
|
NNRSFor
v
e
s
₀ =>
nnrs_stmt_free_mcenv_vars
s
₀
|
NNRSIf
e
s
₁
s
₂ =>
nnrs_stmt_free_mcenv_vars
s
₁ ++
nnrs_stmt_free_mcenv_vars
s
₂
|
NNRSEither
e
x
₁
s
₁
x
₂
s
₂ =>
nnrs_stmt_free_mcenv_vars
s
₁ ++
nnrs_stmt_free_mcenv_vars
s
₂
end
.
Fixpoint
nnrs_stmt_free_mdenv_vars
(
s
:
nnrs_stmt
) :
list
var
:=
match
s
with
|
NNRSSeq
s
₁
s
₂ =>
nnrs_stmt_free_mdenv_vars
s
₁ ++
nnrs_stmt_free_mdenv_vars
s
₂
|
NNRSLet
v
e
s
₀ =>
nnrs_stmt_free_mdenv_vars
s
₀
|
NNRSLetMut
v
s
₁
s
₂ =>
remove
equiv_dec
v
(
nnrs_stmt_free_mdenv_vars
s
₁) ++
nnrs_stmt_free_mdenv_vars
s
₂
|
NNRSLetMutColl
v
s
₁
s
₂ =>
nnrs_stmt_free_mdenv_vars
s
₁ ++
nnrs_stmt_free_mdenv_vars
s
₂
|
NNRSAssign
v
e
=>
v
::
nil
|
NNRSPush
v
e
=>
nil
|
NNRSFor
v
e
s
₀ =>
nnrs_stmt_free_mdenv_vars
s
₀
|
NNRSIf
e
s
₁
s
₂ =>
nnrs_stmt_free_mdenv_vars
s
₁ ++
nnrs_stmt_free_mdenv_vars
s
₂
|
NNRSEither
e
x
₁
s
₁
x
₂
s
₂ =>
nnrs_stmt_free_mdenv_vars
s
₁ ++
nnrs_stmt_free_mdenv_vars
s
₂
end
.
Fixpoint
nnrs_stmt_bound_env_vars
(
s
:
nnrs_stmt
) :
list
var
:=
match
s
with
|
NNRSSeq
s
₁
s
₂ =>
nnrs_stmt_bound_env_vars
s
₁ ++
nnrs_stmt_bound_env_vars
s
₂
|
NNRSLet
v
e
s
₀ =>
v
::
nnrs_stmt_bound_env_vars
s
₀
|
NNRSLetMut
v
s
₁
s
₂ =>
v
::
nnrs_stmt_bound_env_vars
s
₁ ++
nnrs_stmt_bound_env_vars
s
₂
|
NNRSLetMutColl
v
s
₁
s
₂ =>
v
::
nnrs_stmt_bound_env_vars
s
₁ ++
nnrs_stmt_bound_env_vars
s
₂
|
NNRSAssign
v
e
=>
nil
|
NNRSPush
v
e
=>
nil
|
NNRSFor
v
e
s
₀ =>
v
::
nnrs_stmt_bound_env_vars
s
₀
|
NNRSIf
e
s
₁
s
₂ =>
nnrs_stmt_bound_env_vars
s
₁ ++
nnrs_stmt_bound_env_vars
s
₂
|
NNRSEither
e
x
₁
s
₁
x
₂
s
₂ =>
x
₁ ::
x
₂ ::
nnrs_stmt_bound_env_vars
s
₁ ++
nnrs_stmt_bound_env_vars
s
₂
end
.
Fixpoint
nnrs_stmt_bound_mcenv_vars
(
s
:
nnrs_stmt
) :
list
var
:=
match
s
with
|
NNRSSeq
s
₁
s
₂ =>
nnrs_stmt_bound_mcenv_vars
s
₁ ++
nnrs_stmt_bound_mcenv_vars
s
₂
|
NNRSLet
v
e
s
₀ =>
nnrs_stmt_bound_mcenv_vars
s
₀
|
NNRSLetMut
v
s
₁
s
₂ =>
nnrs_stmt_bound_mcenv_vars
s
₁ ++
nnrs_stmt_bound_mcenv_vars
s
₂
|
NNRSLetMutColl
v
s
₁
s
₂ =>
v
::
nnrs_stmt_bound_mcenv_vars
s
₁ ++
nnrs_stmt_bound_mcenv_vars
s
₂
|
NNRSAssign
v
e
=>
nil
|
NNRSPush
v
e
=>
nil
|
NNRSFor
v
e
s
₀ =>
nnrs_stmt_bound_mcenv_vars
s
₀
|
NNRSIf
e
s
₁
s
₂ =>
nnrs_stmt_bound_mcenv_vars
s
₁ ++
nnrs_stmt_bound_mcenv_vars
s
₂
|
NNRSEither
e
x
₁
s
₁
x
₂
s
₂ =>
nnrs_stmt_bound_mcenv_vars
s
₁ ++
nnrs_stmt_bound_mcenv_vars
s
₂
end
.
Fixpoint
nnrs_stmt_bound_mdenv_vars
(
s
:
nnrs_stmt
) :
list
var
:=
match
s
with
|
NNRSSeq
s
₁
s
₂ =>
nnrs_stmt_bound_mdenv_vars
s
₁ ++
nnrs_stmt_bound_mdenv_vars
s
₂
|
NNRSLet
v
e
s
₀ =>
nnrs_stmt_bound_mdenv_vars
s
₀
|
NNRSLetMut
v
s
₁
s
₂ =>
v
::
nnrs_stmt_bound_mdenv_vars
s
₁ ++
nnrs_stmt_bound_mdenv_vars
s
₂
|
NNRSLetMutColl
v
s
₁
s
₂ =>
nnrs_stmt_bound_mdenv_vars
s
₁ ++
nnrs_stmt_bound_mdenv_vars
s
₂
|
NNRSAssign
v
e
=>
nil
|
NNRSPush
v
e
=>
nil
|
NNRSFor
v
e
s
₀ =>
nnrs_stmt_bound_mdenv_vars
s
₀
|
NNRSIf
e
s
₁
s
₂ =>
nnrs_stmt_bound_mdenv_vars
s
₁ ++
nnrs_stmt_bound_mdenv_vars
s
₂
|
NNRSEither
e
x
₁
s
₁
x
₂
s
₂ =>
nnrs_stmt_bound_mdenv_vars
s
₁ ++
nnrs_stmt_bound_mdenv_vars
s
₂
end
.
End
NNRSVars
.