-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aw-query: Add preprocessing and refcounting
- Loading branch information
1 parent
2fc85f3
commit 072753b
Showing
5 changed files
with
214 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use aw_datastore::Datastore; | ||
|
||
use crate::ast::*; | ||
use crate::DataType; | ||
use crate::QueryError; | ||
use crate::VarEnv; | ||
|
||
pub fn preprocess_prog( | ||
p: &Program, | ||
env: &mut VarEnv, | ||
ds: &Datastore, | ||
) -> Result<(), QueryError> { | ||
for expr in &p.stmts { | ||
preprocess_expr(env, ds, expr)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn preprocess_expr( | ||
env: &mut VarEnv, | ||
ds: &Datastore, | ||
expr: &Expr, | ||
) -> Result<(), QueryError> { | ||
use crate::ast::Expr_::*; | ||
match &expr.node { | ||
Var(ref var) => env.add_ref(var)?, | ||
Add(ref a, ref b) => { | ||
preprocess_expr(env, ds, a)?; | ||
preprocess_expr(env, ds, b)?; | ||
} | ||
Sub(ref a, ref b) => { | ||
preprocess_expr(env, ds, a)?; | ||
preprocess_expr(env, ds, b)?; | ||
} | ||
Mul(ref a, ref b) => { | ||
preprocess_expr(env, ds, a)?; | ||
preprocess_expr(env, ds, b)?; | ||
} | ||
Div(ref a, ref b) => { | ||
preprocess_expr(env, ds, a)?; | ||
preprocess_expr(env, ds, b)?; | ||
} | ||
Mod(ref a, ref b) => { | ||
preprocess_expr(env, ds, a)?; | ||
preprocess_expr(env, ds, b)?; | ||
} | ||
Equal(ref a, ref b) => { | ||
preprocess_expr(env, ds, a)?; | ||
preprocess_expr(env, ds, b)?; | ||
} | ||
Assign(ref var, ref b) => { | ||
preprocess_expr(env, ds, b)?; | ||
env.declare(var.to_string()); | ||
}, | ||
Function(ref fname, ref args) => { | ||
env.add_ref(fname)?; | ||
preprocess_expr(env, ds, args)?; | ||
} | ||
If(ref ifs) => { | ||
for (cond, block) in ifs { | ||
// TODO: could be optimized? | ||
preprocess_expr(env, ds, cond)?; | ||
for expr in block { | ||
preprocess_expr(env, ds, expr)?; | ||
} | ||
} | ||
} | ||
List(list) => { | ||
for entry in list { | ||
preprocess_expr(env, ds, entry)?; | ||
} | ||
} | ||
Dict(d) => { | ||
for (key, val_uninterpreted) in d { | ||
preprocess_expr(env, ds, val_uninterpreted)?; | ||
} | ||
} | ||
Return(e) => { | ||
println!("return!"); | ||
preprocess_expr(env, ds, e)?; | ||
}, | ||
Bool(_lit) => (), | ||
Number(_lit) => (), | ||
String(_lit) => (), | ||
}; | ||
Ok(()) | ||
} |
Oops, something went wrong.