Updated codegen
This commit is contained in:
@@ -4,10 +4,6 @@ pub mod top_level;
|
|||||||
|
|
||||||
use mist_parser::ast::*;
|
use mist_parser::ast::*;
|
||||||
|
|
||||||
pub fn get_mutable(mutable: bool) -> String {
|
|
||||||
if mutable { "mut " } else { "" }.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub expr_ensure_semicolon: bool,
|
pub expr_ensure_semicolon: bool,
|
||||||
}
|
}
|
||||||
@@ -239,7 +235,13 @@ impl GenRust for Pattern {
|
|||||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
match self {
|
match self {
|
||||||
Self::Id(id) => cg.add(&id.get_rust()),
|
Self::Id(id) => cg.add(&id.get_rust()),
|
||||||
Self::Path(path) => cg.add(&path.get_rust()),
|
Self::Path(mutable, path) => {
|
||||||
|
if *mutable {
|
||||||
|
cg.add("mut ");
|
||||||
|
};
|
||||||
|
|
||||||
|
cg.add(&path.get_rust())
|
||||||
|
}
|
||||||
Self::Literal(lit) => lit.gen_rust(ctx, cg),
|
Self::Literal(lit) => lit.gen_rust(ctx, cg),
|
||||||
|
|
||||||
Self::Struct(path, ids) => {
|
Self::Struct(path, ids) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use mist_parser::ast::*;
|
use mist_parser::ast::*;
|
||||||
|
|
||||||
use crate::{Context, get_mutable};
|
use crate::Context;
|
||||||
|
|
||||||
use crate::{GenRust, GetRust, RustCodegen};
|
use crate::{GenRust, GetRust, RustCodegen};
|
||||||
|
|
||||||
@@ -164,7 +164,6 @@ impl GenRust for Statement {
|
|||||||
body,
|
body,
|
||||||
} => {
|
} => {
|
||||||
cg.add("for ");
|
cg.add("for ");
|
||||||
cg.add(&get_mutable(*mutable));
|
|
||||||
pattern.gen_rust(ctx, cg);
|
pattern.gen_rust(ctx, cg);
|
||||||
cg.add(" in ");
|
cg.add(" in ");
|
||||||
iterator.gen_rust(ctx, cg);
|
iterator.gen_rust(ctx, cg);
|
||||||
@@ -186,8 +185,6 @@ impl GenRust for Statement {
|
|||||||
|
|
||||||
impl GenRust for VarDecl {
|
impl GenRust for VarDecl {
|
||||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
cg.add(&get_mutable(self.mutable));
|
|
||||||
|
|
||||||
self.name.gen_rust(ctx, cg);
|
self.name.gen_rust(ctx, cg);
|
||||||
|
|
||||||
cg.add(
|
cg.add(
|
||||||
|
|||||||
Reference in New Issue
Block a user