Skip to content

Ubaid/test/pr #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
create-args: >-
python=${{ matrix.python-version }}
cmake=3.30.0
nodejs=18.20.5

- name: Install Windows Conda Packages
if: contains(matrix.os, 'windows')
Expand All @@ -50,7 +51,7 @@ jobs:
- name: Install Linux / macOS Conda Packages
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
shell: bash -e -l {0}
run: micromamba install --freeze-installed bison=3.4 nodejs=18
run: micromamba install --freeze-installed bison=3.4

- name: Conda info
shell: bash -e -l {0}
Expand Down Expand Up @@ -153,8 +154,8 @@ jobs:

./emsdk install 3.1.35
./emsdk activate 3.1.35
./emsdk install node-14.18.2-64bit
./emsdk activate node-14.18.2-64bit
./emsdk install node-18.20.3-64bit
./emsdk activate node-18.20.3-64bit

- name: Show Emscripten and Node Info
shell: bash -l {0}
Expand All @@ -181,7 +182,7 @@ jobs:
source $HOME/ext/emsdk/emsdk_env.sh # Activate Emscripten
which node
node -v
node --experimental-wasm-bigint src/lpython/tests/test_lpython.js
node src/lpython/tests/test_lpython.js

test_pip_pkgs:
name: Test PIP Installable Packages
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LPython

LPython is an ahead-of-time compiler for Python written in C++. It is currently in alpha
stage and under heavy development. LPython works on Windows, macOS and Linux.
stage and under heavy development. LPython works on Windows, macOS and Linux.

Some of the goals of LPython include:

Expand All @@ -13,7 +13,7 @@ Some of the goals of LPython include:
- Exploring design patterns so that LPython can eventually compile all Python code.
- Providing excellent user-friendly diagnostic messages: error, warnings, hints, notes, etc.

among many more.
among many more. No change here.

# Sponsors

Expand Down
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ RUN(NAME test_set_len LABELS cpython llvm llvm_jit)
RUN(NAME test_set_add LABELS cpython llvm llvm_jit)
RUN(NAME test_set_remove LABELS cpython llvm llvm_jit)
RUN(NAME test_set_discard LABELS cpython llvm llvm_jit)
RUN(NAME test_set_from_list LABELS cpython llvm llvm_jit)
RUN(NAME test_set_clear LABELS cpython llvm)
RUN(NAME test_set_pop LABELS cpython llvm)
RUN(NAME test_global_set LABELS cpython llvm llvm_jit)
Expand All @@ -605,6 +606,7 @@ RUN(NAME test_import_04 LABELS cpython llvm llvm_jit c)
RUN(NAME test_import_05 LABELS cpython llvm llvm_jit c wasm wasm_x86 wasm_x64)
RUN(NAME test_import_06 LABELS cpython llvm llvm_jit)
RUN(NAME test_import_07 LABELS cpython llvm llvm_jit c)
RUN(NAME test_import_08 LABELS cpython llvm)
RUN(NAME test_math LABELS cpython llvm llvm_jit NOFAST)
RUN(NAME test_membership_01 LABELS cpython llvm)
RUN(NAME test_numpy_01 LABELS cpython llvm llvm_jit c)
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/test_import_08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import string

import test_import_08_module
6 changes: 6 additions & 0 deletions integration_tests/test_import_08_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from lpython import i32

a: i32 = 10
b: i32 = a + 10

print("Inside import")
14 changes: 14 additions & 0 deletions integration_tests/test_set_from_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from lpython import i32


def test_set():
s: set[i32]
s = set([1, 2, 2, 2, -1, 1, 1, 3])
assert len(s) == 4

s2: set[str]
s2 = set(["a", "b", "b", "abc", "a"])
assert len(s2) == 3


test_set()
3 changes: 2 additions & 1 deletion src/libasr/diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct Span {
// Lines of source code from first_line to last_line
std::vector<std::string> source_code;

Span(const Location &loc) : loc{loc} {}
Span(const Location &loc)
: loc{loc}, first_line{0}, first_column{0}, last_line{0}, last_column{0} {}
};

/*
Expand Down
14 changes: 10 additions & 4 deletions src/libasr/runtime/lfortran_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2135,12 +2135,18 @@ LFORTRAN_API int32_t _lpython_bit_length8(int64_t num)
//repeat str for n time
LFORTRAN_API void _lfortran_strrepeat(char** s, int32_t n, char** dest)
{
// Return empty string for non-positive n
if (n <= 0) {
char* dest_char = (char*)malloc(1);
dest_char[0] = '\0';
*dest = dest_char;
return;
}

char trmn = '\0';
int s_len = strlen(*s);
int trmn_size = sizeof(trmn);
int f_len = s_len*n;
if (f_len < 0)
f_len = 0;
char* dest_char = (char*)malloc(f_len+trmn_size);

if (s_len == 1) {
Expand Down Expand Up @@ -2304,7 +2310,7 @@ LFORTRAN_API char* _lfortran_str_slice_assign(char* s, char *r, int32_t idx1, in
return s;
}

char* dest_char = (char*)malloc(s_len);
char* dest_char = (char*)malloc(s_len + 1);
strcpy(dest_char, s);
int s_i = idx1, d_i = 0;
while((step > 0 && s_i >= idx1 && s_i < idx2) ||
Expand Down Expand Up @@ -3367,7 +3373,7 @@ uint32_t get_file_size(int64_t fp) {
void get_local_info_dwarfdump(struct Stacktrace *d) {
// TODO: Read the contents of lines.dat from here itself.
char *base_name = get_base_name(source_filename);
char *filename = malloc(strlen(base_name) + 14);
char *filename = malloc(strlen(base_name) + 15);
strcpy(filename, base_name);
strcat(filename, "_lines.dat.txt");
int64_t fd = _lpython_open(filename, "r");
Expand Down
39 changes: 37 additions & 2 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4910,6 +4910,16 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
throw SemanticError("The module '" + mod_sym + "' cannot be loaded",
x.base.base.loc);
}
if( mod_sym == "__init__" ) {
for( auto item: ASRUtils::symbol_symtab(t)->get_scope() ) {
if( ASR::is_a<ASR::ExternalSymbol_t>(*item.second) ) {
current_module_dependencies.push_back(al,
ASR::down_cast<ASR::ExternalSymbol_t>(item.second)->m_module_name);
}
}
} else {
current_module_dependencies.push_back(al, s2c(al, mod_sym));
}
}
}

Expand Down Expand Up @@ -5114,6 +5124,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
tmp = nullptr;
tmp_vec.clear();
visit_stmt(*x.m_body[i]);

for (auto t: global_init) {
if (t) {
items.push_back(al, t);
Expand Down Expand Up @@ -8789,9 +8800,33 @@ we will have to use something else.
tmp = nullptr;
}
return ;
} else if (args.size() > 1) {
throw SemanticError("set accepts only 1 argument for now, got " +
std::to_string(args.size()) + " arguments instead.",
x.base.base.loc);
}

throw SemanticError("set is only used for an empty set for now.", x.base.base.loc);
if ( assign_asr_target == nullptr ) {
throw SemanticError("set from list cannot be called without target type for now", x.base.base.loc);
}
ASR::expr_t *arg = args[0].m_value;
ASR::ttype_t *type = ASRUtils::expr_type(arg);
if(!ASR::is_a<ASR::ListConstant_t>(*arg)) {
throw SemanticError("set accepts only list constant for now, got " +
ASRUtils::type_to_str(type) + " type.", x.base.base.loc);
}
ASR::ListConstant_t* list = ASR::down_cast<ASR::ListConstant_t>(arg);
ASR::expr_t **m_args = list->m_args;
size_t n_args = list->n_args;
ASR::ttype_t* value_type = ASRUtils::get_contained_type(type);
ASR::ttype_t* target_type = ASRUtils::get_contained_type(ASRUtils::expr_type(assign_asr_target));
if (!ASRUtils::check_equal_type(target_type, value_type)){
std::string ltype = ASRUtils::type_to_str_python(target_type);
std::string rtype = ASRUtils::type_to_str_python(value_type);
throw SemanticError("type mismatch ('" + ltype + "' and '" + rtype + "')", x.base.base.loc);
}
tmp = ASR::make_SetConstant_t(al, x.base.base.loc, m_args, n_args,
ASRUtils::expr_type(assign_asr_target));
return ;
} else if( call_name == "deepcopy" ) {
parse_args(x, args);
if( args.size() != 1 ) {
Expand Down
Loading
Loading