Impl Tuple type checking & code generating

This commit is contained in:
Shunsuke Shibayama 2022-08-29 12:41:14 +09:00
parent 11e89576e1
commit 451d94d31b
5 changed files with 94 additions and 6 deletions

View file

@ -27,7 +27,7 @@ use crate::compile::{AccessKind, Name, StoreLoadKind};
use crate::error::{CompileError, CompileErrors, CompileResult};
use crate::eval::eval_lit;
use crate::hir::{
Accessor, Args, Array, Block, DefBody, Expr, Signature, SubrSignature, VarSignature, HIR,
Accessor, Args, Array, Block, DefBody, Expr, Signature, SubrSignature, Tuple, VarSignature, HIR,
};
use AccessKind::*;
@ -1216,6 +1216,23 @@ impl CodeGenerator {
}
other => todo!("{other}"),
},
// TODO: tuple comprehension
// TODO: tuples can be const
Expr::Tuple(tup) => match tup {
Tuple::Normal(mut tup) => {
let len = tup.elems.len();
while let Some(arg) = tup.elems.try_remove_pos(0) {
self.codegen_expr(arg.expr);
}
self.write_instr(BUILD_TUPLE);
self.write_arg(len as u8);
if len == 0 {
self.stack_inc();
} else {
self.stack_dec_n(len - 1);
}
}
},
Expr::Record(rec) => {
let attrs_len = rec.attrs.len();
// importing namedtuple