Skip to content

Commit

Permalink
refactor!: rename Array -> List
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Apr 4, 2024
1 parent 41bf146 commit c6eb78a
Show file tree
Hide file tree
Showing 248 changed files with 1,949 additions and 1,986 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
AttributeError: Array object has no attribute `.push!`
AttributeError: List object has no attribute `.push!`
hint: to update the internal state of an object, make it mutable by using `!` operator
hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information
hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information
```

## Requirements
Expand Down
6 changes: 3 additions & 3 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
AttributeError: Arrayオブジェクトは`.push!`という属性を持っていません
AttributeError: Listオブジェクトは`.push!`という属性を持っていません
ヒント: オブジェクトの内部状態を変更したい場合は、`!`演算子を使って可変化してください
ヒント: `Array``push`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/Array/##push を参照してください
ヒント: `Array!``push!`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/Array!/##push! を参照してください
ヒント: `List``push`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/List/##push を参照してください
ヒント: `List!``push!`メソッドを持っています、詳しくは https://erg-lang.github.io/docs/prelude/List!/##push! を参照してください
```

## Requirements
Expand Down
6 changes: 3 additions & 3 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
AttributeError: Array object has no attribute `.push!`
AttributeError: List object has no attribute `.push!`
hint: to update the internal state of an object, make it mutable by using `!` operator
hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information
hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information
```

## 要求
Expand Down
6 changes: 3 additions & 3 deletions README_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@
2│ l = [1, 2, 3]
3│ l.push!(x)
^^^^^
AttributeError: Array object has no attribute `.push!`
AttributeError: List object has no attribute `.push!`
hint: to update the internal state of an object, make it mutable by using `!` operator
hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information
hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information
```

## 要求
Expand Down
14 changes: 7 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* [ ] Pattern-matching
* [x] Variable Pattern
* [x] Literal Pattern
* [x] Array Pattern
* [x] List Pattern
* [x] Tuple Pattern
* [x] Record Pattern
* [x] Data Type Pattern
Expand All @@ -30,7 +30,7 @@
* [x] Positional arguments
* [x] Keyword arguments
* [x] Variable length arguments
* [x] Array literal
* [x] List literal
* [x] Record literal
* [x] Set literal
* [x] Dict literal
Expand Down Expand Up @@ -58,11 +58,11 @@
* [ ] Patch definition
* [ ] Glue Patch definition
* [x] Range object
* [ ] Decorator
* [x] Decorator
* [ ] Comprehension
* [ ] Array
* [ ] Dict
* [ ] Set
* [x] List
* [x] Dict
* [x] Set
* [ ] Tuple
* [x] Pipeline operator
* [ ] ? operator
Expand Down Expand Up @@ -91,7 +91,7 @@
* [x] `sys` (partially)
* [x] `time` (partially)
* [x] Load User Module
* [ ] Recursive module
* [x] Recursive module
* [x] Visibility check
* [x] Patching
* [ ] Implement a side-effect checker
Expand Down
6 changes: 3 additions & 3 deletions crates/els/call_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use erg_compiler::artifact::BuildRunnable;
use erg_compiler::erg_parser::parse::Parsable;

use erg_compiler::hir::{Accessor, Array, Def, Dict, Expr, KeyValue, Set, Tuple};
use erg_compiler::hir::{Accessor, Def, Dict, Expr, KeyValue, List, Set, Tuple};
use erg_compiler::varinfo::{AbsLocation, VarInfo};
use lsp_types::{
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
Expand Down Expand Up @@ -145,8 +145,8 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
calls
}
Expr::UnaryOp(unop) => self.gen_outgoing_call(&unop.expr),
Expr::Array(Array::Normal(arr)) => {
for arg in arr.elems.pos_args.iter() {
Expr::List(List::Normal(lis)) => {
for arg in lis.elems.pos_args.iter() {
calls.extend(self.gen_outgoing_call(&arg.expr));
}
calls
Expand Down
22 changes: 11 additions & 11 deletions crates/els/hir_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<'a> HIRVisitor<'a> {
| Expr::Accessor(_)
| Expr::BinOp(_)
| Expr::UnaryOp(_)
| Expr::Array(_)
| Expr::List(_)
| Expr::Dict(_)
| Expr::Set(_)
| Expr::Tuple(_)
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<'a> HIRVisitor<'a> {
Expr::Def(def) => self.get_expr_from_def(expr, def, pos),
Expr::PatchDef(patch_def) => self.get_expr_from_patch_def(expr, patch_def, pos),
Expr::Lambda(lambda) => self.get_expr_from_lambda(expr, lambda, pos),
Expr::Array(arr) => self.get_expr_from_array(expr, arr, pos),
Expr::List(lis) => self.get_expr_from_list(expr, lis, pos),
Expr::Dict(dict) => self.get_expr_from_dict(expr, dict, pos),
Expr::Record(record) => self.get_expr_from_record(expr, record, pos),
Expr::Set(set) => self.get_expr_from_set(expr, set, pos),
Expand Down Expand Up @@ -440,18 +440,18 @@ impl<'a> HIRVisitor<'a> {
self.get_expr_from_block(lambda.body.iter(), pos)
}

fn get_expr_from_array<'e>(
fn get_expr_from_list<'e>(
&'e self,
expr: &'e Expr,
arr: &'e Array,
lis: &'e List,
pos: Position,
) -> Option<&Expr> {
if arr.ln_end() == pos.ln_end() && self.search.matches(expr) {
if lis.ln_end() == pos.ln_end() && self.search.matches(expr) {
// arr: `[1, 2]`, pos: `]`
return Some(expr);
}
match arr {
Array::Normal(arr) => self.get_expr_from_args(&arr.elems, pos),
match lis {
List::Normal(lis) => self.get_expr_from_args(&lis.elems, pos),
_ => None, // todo!(),
}
}
Expand Down Expand Up @@ -587,7 +587,7 @@ impl<'a> HIRVisitor<'a> {
Expr::PatchDef(patch_def) => self.get_patch_def_info(patch_def, token),
Expr::Def(def) => self.get_def_info(def, token),
Expr::Lambda(lambda) => self.get_lambda_info(lambda, token),
Expr::Array(arr) => self.get_array_info(arr, token),
Expr::List(lis) => self.get_list_info(lis, token),
Expr::Dict(dict) => self.get_dict_info(dict, token),
Expr::Record(record) => self.get_record_info(record, token),
Expr::Set(set) => self.get_set_info(set, token),
Expand Down Expand Up @@ -764,9 +764,9 @@ impl<'a> HIRVisitor<'a> {
.or_else(|| self.get_block_info(lambda.body.iter(), token))
}

fn get_array_info(&self, arr: &Array, token: &Token) -> Option<VarInfo> {
match arr {
Array::Normal(arr) => self.get_args_info(&arr.elems, token),
fn get_list_info(&self, lis: &List, token: &Token) -> Option<VarInfo> {
match lis {
List::Normal(lis) => self.get_args_info(&lis.elems, token),
_ => None, // todo!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/els/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
lsp_log!("failed to get packages: {}", artifact.ast);
return cfg;
};
let Some(ast::Expr::Array(ast::Array::Normal(arr))) = pkgs.body.block.first() else {
let Some(ast::Expr::List(ast::List::Normal(lis))) = pkgs.body.block.first() else {
lsp_log!("packages must be an array: {pkgs}");
return cfg;
};
let mut packages = vec![];
for rec in arr.iter() {
for rec in lis.iter() {
let ast::Expr::Record(rec) = rec else {
lsp_log!("packages must be records: {rec}");
break;
Expand Down
34 changes: 17 additions & 17 deletions crates/erg_compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ use erg_parser::token::{Token, TokenKind};
use crate::compile::{AccessKind, Name, StoreLoadKind};
use crate::context::ControlKind;
use crate::error::CompileError;
use crate::hir::ArrayWithLength;
use crate::hir::DefaultParamSignature;
use crate::hir::ListWithLength;
use crate::hir::{
Accessor, Args, Array, BinOp, Block, Call, ClassDef, Def, DefBody, Expr, GuardClause,
Identifier, Lambda, Literal, NonDefaultParamSignature, Params, PatchDef, PosArg, ReDef, Record,
Accessor, Args, BinOp, Block, Call, ClassDef, Def, DefBody, Expr, GuardClause, Identifier,
Lambda, List, Literal, NonDefaultParamSignature, Params, PatchDef, PosArg, ReDef, Record,
Signature, SubrSignature, Tuple, UnaryOp, VarSignature, HIR,
};
use crate::ty::codeobj::{CodeObj, CodeObjFlags, MakeFunctionFlags};
Expand Down Expand Up @@ -3031,20 +3031,20 @@ impl PyCodeGenerator {
}

// TODO: list comprehension
fn emit_array(&mut self, array: Array) {
fn emit_list(&mut self, list: List) {
let init_stack_len = self.stack_len();
if !self.cfg.no_std {
self.emit_push_null();
if array.is_unsized() {
self.emit_load_name_instr(Identifier::static_public("UnsizedArray"));
if list.is_unsized() {
self.emit_load_name_instr(Identifier::static_public("UnsizedList"));
} else {
self.emit_load_name_instr(Identifier::static_public("Array"));
self.emit_load_name_instr(Identifier::static_public("List"));
}
}
match array {
Array::Normal(mut arr) => {
let len = arr.elems.len();
while let Some(arg) = arr.elems.try_remove_pos(0) {
match list {
List::Normal(mut lis) => {
let len = lis.elems.len();
while let Some(arg) = lis.elems.try_remove_pos(0) {
self.emit_expr(arg.expr);
}
self.write_instr(BUILD_LIST);
Expand All @@ -3055,7 +3055,7 @@ impl PyCodeGenerator {
self.stack_dec_n(len - 1);
}
}
Array::WithLength(ArrayWithLength {
List::WithLength(ListWithLength {
elem,
len: Some(len),
..
Expand All @@ -3066,10 +3066,10 @@ impl PyCodeGenerator {
self.emit_call_instr(1, Name);
self.stack_dec();
self.emit_expr(*len);
self.emit_binop_instr(Token::dummy(TokenKind::Star, "*"), TypePair::ArrayNat);
self.emit_binop_instr(Token::dummy(TokenKind::Star, "*"), TypePair::ListNat);
return;
}
Array::WithLength(ArrayWithLength {
List::WithLength(ListWithLength {
elem, len: None, ..
}) => {
self.emit_expr(*elem);
Expand Down Expand Up @@ -3331,7 +3331,7 @@ impl PyCodeGenerator {
Expr::UnaryOp(unary) => self.emit_unaryop(unary),
Expr::BinOp(bin) => self.emit_binop(bin),
Expr::Call(call) => self.emit_call(call),
Expr::Array(arr) => self.emit_array(arr),
Expr::List(lis) => self.emit_list(lis),
Expr::Tuple(tup) => self.emit_tuple(tup),
Expr::Set(set) => self.emit_set(set),
Expr::Dict(dict) => self.emit_dict(dict),
Expand All @@ -3355,7 +3355,7 @@ impl PyCodeGenerator {
self.emit_load_name_instr(Identifier::public(&v.qual_name()));
}
other => match &other.qual_name()[..] {
t @ ("Bytes" | "Array" | "Dict" | "Set") => {
t @ ("Bytes" | "List" | "Dict" | "Set") => {
self.emit_push_null();
self.emit_load_name_instr(Identifier::public(t));
}
Expand All @@ -3378,7 +3378,7 @@ impl PyCodeGenerator {
Expr::UnaryOp(unary) => self.emit_unaryop(unary),
Expr::BinOp(bin) => self.emit_binop(bin),
Expr::Call(call) => self.emit_call(call),
Expr::Array(arr) => self.emit_array(arr),
Expr::List(lis) => self.emit_list(lis),
Expr::Tuple(tup) => self.emit_tuple(tup),
Expr::Set(set) => self.emit_set(set),
Expr::Dict(dict) => self.emit_dict(dict),
Expand Down
Loading

0 comments on commit c6eb78a

Please sign in to comment.