Skip to content

Commit 8badcba

Browse files
committed
Merge main
2 parents dd2f4cc + 22ea159 commit 8badcba

File tree

7 files changed

+175
-136
lines changed

7 files changed

+175
-136
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
create-args: >-
4242
python=${{ matrix.python-version }}
4343
cmake=3.30.0
44+
nodejs=18.20.5
4445
4546
- name: Install Windows Conda Packages
4647
if: contains(matrix.os, 'windows')
@@ -50,7 +51,7 @@ jobs:
5051
- name: Install Linux / macOS Conda Packages
5152
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
5253
shell: bash -e -l {0}
53-
run: micromamba install --freeze-installed bison=3.4 nodejs=18
54+
run: micromamba install --freeze-installed bison=3.4
5455

5556
- name: Conda info
5657
shell: bash -e -l {0}
@@ -153,8 +154,8 @@ jobs:
153154
154155
./emsdk install 3.1.35
155156
./emsdk activate 3.1.35
156-
./emsdk install node-14.18.2-64bit
157-
./emsdk activate node-14.18.2-64bit
157+
./emsdk install node-18.20.3-64bit
158+
./emsdk activate node-18.20.3-64bit
158159
159160
- name: Show Emscripten and Node Info
160161
shell: bash -l {0}
@@ -181,7 +182,7 @@ jobs:
181182
source $HOME/ext/emsdk/emsdk_env.sh # Activate Emscripten
182183
which node
183184
node -v
184-
node --experimental-wasm-bigint src/lpython/tests/test_lpython.js
185+
node src/lpython/tests/test_lpython.js
185186
186187
test_pip_pkgs:
187188
name: Test PIP Installable Packages

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ RUN(NAME test_set_len LABELS cpython llvm llvm_jit)
592592
RUN(NAME test_set_add LABELS cpython llvm llvm_jit)
593593
RUN(NAME test_set_remove LABELS cpython llvm llvm_jit)
594594
# RUN(NAME test_set_discard LABELS cpython llvm llvm_jit)
595+
# RUN(NAME test_set_from_list LABELS cpython llvm llvm_jit)
595596
# RUN(NAME test_set_clear LABELS cpython llvm)
596597
# RUN(NAME test_set_pop LABELS cpython llvm)
597598
RUN(NAME test_global_set LABELS cpython llvm llvm_jit)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from lpython import i32
2+
3+
4+
def test_set():
5+
s: set[i32]
6+
s = set([1, 2, 2, 2, -1, 1, 1, 3])
7+
assert len(s) == 4
8+
9+
s2: set[str]
10+
s2 = set(["a", "b", "b", "abc", "a"])
11+
assert len(s2) == 3
12+
13+
14+
test_set()

src/libasr/diagnostics.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ struct Span {
2323
// Lines of source code from first_line to last_line
2424
std::vector<std::string> source_code;
2525

26-
Span(const Location &loc) : loc{loc} {}
26+
Span(const Location &loc)
27+
: loc{loc}, first_line{0}, first_column{0}, last_line{0}, last_column{0} {}
2728
};
2829

2930
/*

src/libasr/runtime/lfortran_intrinsics.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
833833
state->current_arr_element_int64 = state->arr_ptr_int64[state->current_arr_index++];
834834
} else {
835835
state->array_size = va_arg(*args,int64_t);
836-
state->current_arr_index = 0;
836+
state->current_arr_index = 0;
837837
state->arr_ptr_int64 = va_arg(*args,int64_t*);
838838
state->current_arr_element_int64 = state->arr_ptr_int64[state->current_arr_index++];
839839
*count+= state->array_size - 2;
@@ -858,7 +858,7 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
858858
state->current_arr_element_int64 = (int64_t)temp_val;
859859
} else {
860860
state->array_size = va_arg(*args,int64_t);
861-
state->current_arr_index = 0;
861+
state->current_arr_index = 0;
862862
state->arr_ptr_int16 = va_arg(*args,int16_t*);
863863
int16_t temp_val = state->arr_ptr_int16[state->current_arr_index++];
864864
state->current_arr_element_int64 = (int64_t)temp_val;
@@ -871,7 +871,7 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
871871
state->current_arr_element_int64 = (int64_t)temp_val;
872872
} else {
873873
state->array_size = va_arg(*args,int64_t);
874-
state->current_arr_index = 0;
874+
state->current_arr_index = 0;
875875
state->arr_ptr_int8 = va_arg(*args,int8_t*);
876876
int8_t temp_val = state->arr_ptr_int8[state->current_arr_index++];
877877
state->current_arr_element_int64 = (int64_t)temp_val;
@@ -883,7 +883,7 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
883883
state->current_arr_element_double = state->arr_ptr_double[state->current_arr_index++];
884884
} else {
885885
state->array_size = va_arg(*args,int64_t);
886-
state->current_arr_index = 0;
886+
state->current_arr_index = 0;
887887
state->arr_ptr_double = va_arg(*args,double*);
888888
state->current_arr_element_double = state->arr_ptr_double[state->current_arr_index++];
889889
*count+= state->array_size - 2;
@@ -895,7 +895,7 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
895895
state->current_arr_element_double = (double)temp_val;
896896
} else {
897897
state->array_size = va_arg(*args,int64_t);
898-
state->current_arr_index = 0;
898+
state->current_arr_index = 0;
899899
state->arr_ptr_float = va_arg(*args,float*);
900900
float temp_val = state->arr_ptr_float[state->current_arr_index++];
901901
state->current_arr_element_double = (double)temp_val;
@@ -907,7 +907,7 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
907907
state->current_arr_element_char_ptr = state->arr_ptr_charPtr[state->current_arr_index++];
908908
} else {
909909
state->array_size = va_arg(*args,int64_t);
910-
state->current_arr_index = 0;
910+
state->current_arr_index = 0;
911911
state->arr_ptr_charPtr = va_arg(*args,char**);
912912
state->current_arr_element_char_ptr = state->arr_ptr_charPtr[state->current_arr_index++];
913913
*count+= state->array_size - 2;
@@ -918,19 +918,19 @@ bool check_array_iteration(int* count, int* current_arg_type_int, va_list* args,
918918
state->current_arr_element_bool = state->arr_ptr_bool[state->current_arr_index++];
919919
} else {
920920
state->array_size = va_arg(*args,int64_t);
921-
state->current_arr_index = 0;
921+
state->current_arr_index = 0;
922922
state->arr_ptr_bool = va_arg(*args,bool*);
923923
state->current_arr_element_bool = state->arr_ptr_bool[state->current_arr_index++];
924924
*count+= state->array_size - 2;
925925
}
926926
break;
927-
//To DO : handle --> arr[cptr], arr[enumType]
927+
//To DO : handle --> arr[cptr], arr[enumType]
928928
default:
929929
is_array = false;
930930
break;
931931
}
932932
return is_array;
933-
933+
934934
}
935935
char* int_to_format_specifier(int32_t type_as_int){
936936
switch(type_as_int){
@@ -1147,7 +1147,7 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(int count, const char* form
11471147
result = (char*)malloc(150 * sizeof(char));
11481148
sprintf(result, " Runtime Error : Got argument of type (%s), while the format specifier is (%c)\n",type ,value[0]);
11491149
// Special indication for error --> "\b" to be handled by `lfortran_print` or `lfortran_file_write`
1150-
result[0] = '\b';
1150+
result[0] = '\b';
11511151
count = 0; // Break while loop.
11521152
break;
11531153
}
@@ -1158,7 +1158,7 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(int count, const char* form
11581158
count--;
11591159
char* arg = NULL;
11601160
if(is_array){
1161-
arg = array_state.current_arr_element_char_ptr;
1161+
arg = array_state.current_arr_element_char_ptr;
11621162
} else {
11631163
arg = va_arg(args, char*);
11641164
}
@@ -2032,7 +2032,7 @@ LFORTRAN_API void _lfortran_strcat(char** s1, char** s2, char** dest)
20322032
dest_char[cntr] = trmn;
20332033
*dest = &(dest_char[0]);
20342034
}
2035-
// Allocate_allocatable-strings + Extend String -----------------------------------------------------------
2035+
// Allocate_allocatable-strings + Extend String -----------------------------------------------------------
20362036

20372037
void extend_string(char** ptr, int32_t new_size /*Null-Character Counted*/, int64_t* string_capacity){
20382038
ASSERT_MSG(string_capacity != NULL, "%s", "string capacity is NULL");
@@ -2057,7 +2057,7 @@ LFORTRAN_API void _lfortran_alloc(char** ptr, int32_t desired_size /*Null-Charac
20572057
if(100 < desired_size){
20582058
inital_capacity = desired_size;
20592059
} else {
2060-
inital_capacity = 100;
2060+
inital_capacity = 100;
20612061
}
20622062
*ptr = (char*)malloc(inital_capacity);
20632063
*string_capacity = inital_capacity;
@@ -2082,14 +2082,14 @@ LFORTRAN_API void _lfortran_strcpy_descriptor_string(char** x, char *y, int64_t*
20822082
ASSERT_MSG(((*x != NULL) && (*x_string_size <= (*x_string_capacity - 1))) ||
20832083
(*x == NULL && *x_string_size == 0 && *x_string_capacity == 0) , "%s",
20842084
"compiler-behavior error : string x_string_capacity < string size");
2085-
2085+
20862086
if(y == NULL){
20872087
fprintf(stderr,
20882088
"Runtime Error : RHS allocatable-character variable must be allocated before assignment.\n");
20892089
exit(1);
20902090
}
2091-
size_t y_len, x_len;
2092-
y_len = strlen(y);
2091+
size_t y_len, x_len;
2092+
y_len = strlen(y);
20932093
x_len = y_len;
20942094

20952095
if (*x == NULL) {
@@ -2101,7 +2101,7 @@ LFORTRAN_API void _lfortran_strcpy_descriptor_string(char** x, char *y, int64_t*
21012101
}
21022102
}
21032103
int64_t null_character_index = x_len;
2104-
(*x)[null_character_index] = '\0';
2104+
(*x)[null_character_index] = '\0';
21052105
for (size_t i = 0; i < x_len; i++) {
21062106
(*x)[i] = y[i];
21072107
}
@@ -2116,7 +2116,7 @@ LFORTRAN_API void _lfortran_strcpy_pointer_string(char** x, char *y)
21162116
exit(1);
21172117
}
21182118
size_t y_len;
2119-
y_len = strlen(y);
2119+
y_len = strlen(y);
21202120
// A workaround :
21212121
// every LHS string that's not allocatable should have been
21222122
// allocated a fixed-size-memory space that stays there for the whole life time of the program.
@@ -2282,8 +2282,6 @@ LFORTRAN_API void _lfortran_strrepeat(char** s, int32_t n, char** dest)
22822282
int s_len = strlen(*s);
22832283
int trmn_size = sizeof(trmn);
22842284
int f_len = s_len*n;
2285-
if (f_len < 0)
2286-
f_len = 0;
22872285
char* dest_char = (char*)malloc(f_len+trmn_size);
22882286
for (int i = 0; i < n; i++) {
22892287
for (int j = 0; j < s_len; j++) {
@@ -2673,10 +2671,10 @@ LFORTRAN_API char* _lfortran_zone() {
26732671
// Windows doesn't provide timezone offset directly, so we calculate it
26742672
TIME_ZONE_INFORMATION tzinfo;
26752673
DWORD retval = GetTimeZoneInformation(&tzinfo);
2676-
2674+
26772675
// Calculate the total offset in minutes
26782676
int offset_minutes = -tzinfo.Bias; // Bias is in minutes; negative for UTC+
2679-
2677+
26802678
if (retval == TIME_ZONE_ID_DAYLIGHT) {
26812679
offset_minutes -= tzinfo.DaylightBias; // Apply daylight saving if applicable
26822680
} else if (retval == TIME_ZONE_ID_STANDARD) {
@@ -3651,7 +3649,7 @@ LFORTRAN_API void _lfortran_string_write(char **str_holder, int64_t* size, int64
36513649
char *s = (char *) malloc(strlen(str)*sizeof(char) + strlen(end)*sizeof(char) + 1);
36523650
sprintf(s, format, str, end);
36533651

3654-
if(((*size) == -1) && ((*capacity) == -1)){
3652+
if(((*size) == -1) && ((*capacity) == -1)){
36553653
_lfortran_strcpy_pointer_string(str_holder, s);
36563654
} else {
36573655
_lfortran_strcpy_descriptor_string(str_holder, s, size, capacity);

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8836,9 +8836,33 @@ we will have to use something else.
88368836
tmp = nullptr;
88378837
}
88388838
return ;
8839+
} else if (args.size() > 1) {
8840+
throw SemanticError("set accepts only 1 argument for now, got " +
8841+
std::to_string(args.size()) + " arguments instead.",
8842+
x.base.base.loc);
88398843
}
8840-
8841-
throw SemanticError("set is only used for an empty set for now.", x.base.base.loc);
8844+
if ( assign_asr_target == nullptr ) {
8845+
throw SemanticError("set from list cannot be called without target type for now", x.base.base.loc);
8846+
}
8847+
ASR::expr_t *arg = args[0].m_value;
8848+
ASR::ttype_t *type = ASRUtils::expr_type(arg);
8849+
if(!ASR::is_a<ASR::ListConstant_t>(*arg)) {
8850+
throw SemanticError("set accepts only list constant for now, got " +
8851+
ASRUtils::type_to_str(type) + " type.", x.base.base.loc);
8852+
}
8853+
ASR::ListConstant_t* list = ASR::down_cast<ASR::ListConstant_t>(arg);
8854+
ASR::expr_t **m_args = list->m_args;
8855+
size_t n_args = list->n_args;
8856+
ASR::ttype_t* value_type = ASRUtils::get_contained_type(type);
8857+
ASR::ttype_t* target_type = ASRUtils::get_contained_type(ASRUtils::expr_type(assign_asr_target));
8858+
if (!ASRUtils::check_equal_type(target_type, value_type)){
8859+
std::string ltype = ASRUtils::type_to_str_python(target_type);
8860+
std::string rtype = ASRUtils::type_to_str_python(value_type);
8861+
throw SemanticError("type mismatch ('" + ltype + "' and '" + rtype + "')", x.base.base.loc);
8862+
}
8863+
tmp = ASR::make_SetConstant_t(al, x.base.base.loc, m_args, n_args,
8864+
ASRUtils::expr_type(assign_asr_target));
8865+
return ;
88428866
} else if( call_name == "deepcopy" ) {
88438867
parse_args(x, args);
88448868
if( args.size() != 1 ) {

0 commit comments

Comments
 (0)