Skip to content
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

Fix Indentation for Windows #2726

Closed
wants to merge 1 commit into from
Closed
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
51 changes: 23 additions & 28 deletions src/runtime/lpython_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def pow(x: f64, y: i32) -> f64:
def pow(x: bool, y: bool) -> i32:
if y and not x:
return 0

return 1

@overload
Expand All @@ -146,7 +146,7 @@ def sum(arr: list[i32]) -> i32:
"""
sum: i32
sum = 0

i: i32
for i in range(len(arr)):
sum += arr[i]
Expand All @@ -159,7 +159,7 @@ def sum(arr: list[i64]) -> i64:
"""
sum: i64
sum = i64(0)

i: i32
for i in range(len(arr)):
sum += arr[i]
Expand All @@ -172,7 +172,7 @@ def sum(arr: list[f32]) -> f32:
"""
sum: f32
sum = f32(0.0)

i: i32
for i in range(len(arr)):
sum += arr[i]
Expand All @@ -185,7 +185,7 @@ def sum(arr: list[f64]) -> f64:
"""
sum: f64
sum = 0.0

i: i32
for i in range(len(arr)):
sum += arr[i]
Expand Down Expand Up @@ -618,7 +618,7 @@ def _lpython_str_capitalize(x: str) -> str:
res += chr(ord(i) + 32) # Convert to lowercase using ASCII values
else:
res += i

val: i32
val = ord(res[0])
if val >= ord('a') and val <= ord('z'):
Expand All @@ -634,15 +634,15 @@ def _lpython_str_count(s: str, sub: str) -> i32:
lps: list[i32] = []
s_len = len(s)
sub_len = len(sub)

if sub_len == 0:
return s_len + 1

count = 0

for i in range(sub_len):
lps.append(0)

i = 1
_len = 0
while i < sub_len:
Expand All @@ -656,7 +656,7 @@ def _lpython_str_count(s: str, sub: str) -> i32:
else:
lps[i] = 0
i += 1

j: i32
j = 0
i = 0
Expand All @@ -672,7 +672,7 @@ def _lpython_str_count(s: str, sub: str) -> i32:
j = lps[j - 1]
else:
i = i + 1

return count


Expand Down Expand Up @@ -766,15 +766,15 @@ def _lpython_str_title(s: str) -> str:
else:
result += ch
capitalize_next = True

return result

def _lpython_str_istitle(s: str) -> bool:
length: i32 = len(s)

if length == 0:
return False # Empty string is not in title case

word_start: bool = True # Flag to track the start of a word
ch: str
only_whitespace: bool = True
Expand All @@ -785,15 +785,13 @@ def _lpython_str_istitle(s: str) -> bool:
word_start = False
else:
return False # Found an uppercase character in the middle of a word

elif ch.isalpha() and (ord('a') <= ord(ch) and ord(ch) <= ord('z')):
only_whitespace = False
if word_start:
return False # Found a lowercase character in the middle of a word
word_start = False
else:
word_start = True

return True if not only_whitespace else False

@overload
Expand All @@ -807,10 +805,10 @@ def _lpython_str_find(s: str, sub: str) -> i32:
res = -1
if s_len == 0 or sub_len == 0:
return 0 if sub_len == 0 or (sub_len == s_len) else -1

for i in range(sub_len):
lps.append(0)

i = 1
_len = 0
while i < sub_len:
Expand All @@ -824,7 +822,7 @@ def _lpython_str_find(s: str, sub: str) -> i32:
else:
lps[i] = 0
i += 1

j: i32
j = 0
i = 0
Expand All @@ -841,7 +839,6 @@ def _lpython_str_find(s: str, sub: str) -> i32:
j = lps[j - 1]
else:
i = i + 1

return res

def _lpython_str_rstrip(x: str) -> str:
Expand Down Expand Up @@ -886,7 +883,7 @@ def _lpython_str_split(x: str) -> list[str]:
res.append(x_strip[start:start + ind])
start += ind + len(sep)
return res

@overload
def _lpython_str_split(x: str, sep:str) -> list[str]:
if len(sep) == 0:
Expand All @@ -907,7 +904,7 @@ def _lpython_str_split(x: str, sep:str) -> list[str]:
@overload
def _lpython_str_replace(x: str, old:str, new:str) -> str:
return _lpython_str_replace(x, old, new, len(x))


@overload
def _lpython_str_replace(x: str, old:str, new:str, count: i32) -> str:
Expand All @@ -925,7 +922,7 @@ def _lpython_str_replace(x: str, old:str, new:str, count: i32) -> str:
lx: i32 = len(x)
c: i32 = 0
t: i32 = -1

while(c<count):
t = _lpython_str_find(x[i:lx], old)
if(t==-1):
Expand Down Expand Up @@ -965,17 +962,16 @@ def _lpython_str_startswith(s: str ,sub: str) -> bool:

@overload
def _lpython_str_endswith(s: str, suffix: str) -> bool:

if(len(suffix) > len(s)):
return False

i : i32
i = 0
while(i < len(suffix)):
if(suffix[len(suffix) - i - 1] != s[len(s) - i - 1]):
return False
i += 1

return True

@overload
Expand Down Expand Up @@ -1143,4 +1139,3 @@ def list(s: str) -> list[str]:
for i in range(len(s)):
l.append(s[i])
return l

26 changes: 13 additions & 13 deletions src/runtime/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def modf(x: f64) -> tuple[f64, f64]:
"""
Return fractional and integral parts of `x` as a pair.

Both results carry the sign of x and are floats.
"""
return (x - f64(int(x)), float(int(x)))
Expand All @@ -20,7 +20,7 @@ def factorial(x: i32) -> i32:
"""
Computes the factorial of `x`.
"""

result: i32
result = 0
if x < 0:
Expand Down Expand Up @@ -104,7 +104,7 @@ def fsum(arr: list[i32]) -> f64:
"""
sum: f64
sum = 0.0

i: i32
for i in range(len(arr)):
sum += float(arr[i])
Expand All @@ -117,7 +117,7 @@ def fsum(arr: list[i64]) -> f64:
"""
sum: f64
sum = 0.0

i: i32
for i in range(len(arr)):
sum += float(arr[i])
Expand All @@ -130,7 +130,7 @@ def fsum(arr: list[f32]) -> f64:
"""
sum: f64
sum = 0.0

i: i32
for i in range(len(arr)):
sum += float(arr[i])
Expand All @@ -143,7 +143,7 @@ def fsum(arr: list[f64]) -> f64:
"""
sum: f64
sum = 0.0

i: i32
for i in range(len(arr)):
sum += arr[i]
Expand All @@ -157,7 +157,7 @@ def prod(arr: list[i32]) -> f64:
"""
Return the product of the elements of `arr`.
"""

result: f64
result = 1.0
i: i32
Expand All @@ -170,7 +170,7 @@ def prod(arr: list[i64]) -> f64:
"""
Return the product of the elements of `arr`.
"""

result: f64
result = 1.0
i: i32
Expand All @@ -183,7 +183,7 @@ def prod(arr: list[f32]) -> f64:
"""
Return the product of the elements of `arr`.
"""

result: f64
result = 1.0
i: i32
Expand All @@ -196,7 +196,7 @@ def prod(arr: list[f64]) -> f64:
"""
Return the product of the elements of `arr`.
"""

result: f64
result = 1.0
i: i32
Expand All @@ -213,7 +213,7 @@ def dist(x: list[f64], y: list[f64]) -> f64:
raise ValueError("Length of lists should be same")
res: f64
res = 0.0

i: i32
for i in range(len(x)):
res += (x[i] - y[i]) * (x[i] - y[i])
Expand All @@ -225,7 +225,7 @@ def comb(n: i32, k: i32) -> i32:
Computes the result of `nCk`, i.e, the number of ways to choose `k`
items from `n` items without repetition and without order.
"""

if n < k or n < 0:
return 0
return i32(factorial(n)//(factorial(k)*factorial(n-k)))
Expand All @@ -236,7 +236,7 @@ def perm(n: i32, k: i32) -> i32:
Computes the result of `nPk`, i.e, the number of ways to choose `k` items
from `n` items without repetition and with order.
"""

if n < k or n < 0:
return 0
return i32(factorial(n)//factorial(n-k))
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ def python_implementation() -> str:
return "LPython"

def python_version() -> str:
return __LPYTHON_VERSION__
return __LPYTHON_VERSION__
Loading
Loading