mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 04:24:43 +00:00
Impl Tuple type checking & code generating
This commit is contained in:
parent
11e89576e1
commit
451d94d31b
5 changed files with 94 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue