Skip to content

Commit 110f33b

Browse files
committed
wip
1 parent 2861a26 commit 110f33b

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ RUN(NAME test_list_02 LABELS cpython llvm)
152152
RUN(NAME test_list_03 LABELS cpython llvm)
153153
RUN(NAME test_list_04 LABELS cpython llvm)
154154
RUN(NAME test_list_05 LABELS cpython llvm)
155-
RUN(NAME test_list_06 LABELS llvm)
155+
RUN(NAME test_list_06 LABELS cpython llvm)
156+
RUN(NAME test_list_07 LABELS cpython llvm)
156157
RUN(NAME test_tuple_01 LABELS cpython llvm)
157158
RUN(NAME test_tuple_02 LABELS cpython llvm)
158159
RUN(NAME modules_01 LABELS cpython llvm)

integration_tests/test_list_06.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ltypes import i32, f64
2+
from copy import deepcopy
23

34
def check_mat_and_vec(mat: list[list[f64]], vec: list[f64]):
45
rows: i32 = len(mat)
@@ -28,7 +29,7 @@ def test_list_of_lists():
2829
for i in range(rows):
2930
for j in range(cols):
3031
vec.append(float(i + j))
31-
mat.append(vec)
32+
mat.append(deepcopy(vec))
3233
vec.clear()
3334

3435
for i in range(cols):
@@ -37,7 +38,7 @@ def test_list_of_lists():
3738
check_mat_and_vec(mat, vec)
3839

3940
for k in range(rows):
40-
tensor.append(mat)
41+
tensor.append(deepcopy(mat))
4142
for i in range(rows):
4243
for j in range(cols):
4344
mat[i][j] += float(1)
@@ -48,7 +49,7 @@ def test_list_of_lists():
4849
assert mat[i][j] - tensor[k][i][j] == rows - k
4950

5051
for l in range(2 * rows):
51-
tensors.append(tensor)
52+
tensors.append(deepcopy(tensor))
5253
for i in range(rows):
5354
for j in range(rows):
5455
for k in range(cols):

integration_tests/test_list_07.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from ltypes import c64, i32
2+
from copy import deepcopy
23

34
def test_tuple_with_lists():
45
mat: list[list[c64]] = []
56
vec: list[c64] = []
67
tensor: tuple[list[list[c64]], list[c64]]
7-
tensors: list[tuple[list[list[c64]], list[c64]]]
8+
tensors: list[tuple[list[list[c64]], list[c64]]] = []
89
i: i32
910
j: i32
1011
k: i32
@@ -15,7 +16,7 @@ def test_tuple_with_lists():
1516
for i in range(rows):
1617
for j in range(cols):
1718
vec.append(complex(i + j, 0))
18-
mat.append(vec)
19+
mat.append(deepcopy(vec))
1920
vec.clear()
2021

2122
for i in range(cols):
@@ -25,7 +26,7 @@ def test_tuple_with_lists():
2526
for j in range(cols):
2627
assert mat[i][j] - vec[j] == i - j
2728

28-
tensor = (mat, vec)
29+
tensor = (deepcopy(mat), deepcopy(vec))
2930

3031
for i in range(rows):
3132
for j in range(cols):
@@ -41,18 +42,18 @@ def test_tuple_with_lists():
4142
for i in range(cols):
4243
assert tensor[1][i] - vec[i] == -complex(0, 2.0)
4344

44-
tensor = (mat, vec)
45+
tensor = (deepcopy(mat), deepcopy(vec))
4546

4647
for k in range(2 * rows):
47-
tensors.append(tensor)
48+
tensors.append(deepcopy(tensor))
4849
for i in range(rows):
4950
for j in range(cols):
5051
mat[i][j] += complex(1.0, 2.0)
5152

5253
for i in range(cols):
5354
vec[i] += complex(1.0, 2.0)
5455

55-
tensor = (mat, vec)
56+
tensor = (deepcopy(mat), deepcopy(vec))
5657

5758
for k in range(2 * rows):
5859
for i in range(rows):

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
197197
std::vector<std::string> &rl_path,
198198
bool &ltypes,
199199
const std::function<void (const std::string &, const Location &)> err) {
200+
if( module_name == "copy" ) {
201+
return nullptr;
202+
}
200203
ltypes = false;
201204
LFORTRAN_ASSERT(symtab);
202205
if (symtab->get_scope().find(module_name) != symtab->get_scope().end()) {
@@ -4422,6 +4425,14 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
44224425
ASRUtils::type_to_str(type) + " type.", x.base.base.loc);
44234426
}
44244427
return;
4428+
} else if( call_name == "deepcopy" ) {
4429+
if( args.size() != 1 ) {
4430+
throw SemanticError("deepcopy only accepts one argument, found " +
4431+
std::to_string(args.size()) + " instead.",
4432+
x.base.base.loc);
4433+
}
4434+
tmp = (ASR::asr_t*) args[0].m_value;
4435+
return ;
44254436
} else {
44264437
// The function was not found and it is not intrinsic
44274438
throw SemanticError("Function '" + call_name + "' is not declared and not intrinsic",

src/lpython/semantics/python_attribute_eval.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,17 @@ struct AttributeHandler {
189189
}
190190

191191
static ASR::asr_t* eval_list_clear(ASR::expr_t *s, Allocator &al,
192-
const Location &loc, Vec<ASR::expr_t*> &args, diag::Diagnostics &diag) {
192+
const Location &loc, Vec<ASR::expr_t*> &args, diag::Diagnostics & diag) {
193193
if (args.size() != 0) {
194-
throw SemanticError("clear() takes no argument", loc);
194+
diag.add(diag::Diagnostic(
195+
"Incorrect number of arguments in 'clear', it accepts no argument",
196+
diag::Level::Error, diag::Stage::Semantic, {
197+
diag::Label("incorrect number of arguments in clear (found: " +
198+
std::to_string(args.size()) + ", expected: 0)",
199+
{loc})
200+
})
201+
);
202+
throw SemanticAbort();
195203
}
196204

197205
return make_ListClear_t(al, loc, s);

0 commit comments

Comments
 (0)