forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lcompilers#277 from Thirumalai-Shaktivel/os
Initial implementation of file accessing using OS Module
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from ltypes import i64 | ||
from os import (open, read, close) | ||
|
||
def test(): | ||
path: str | ||
path = "integration_tests/test_os.py" | ||
fd: i64 | ||
n: i64 | ||
fd = open(path, "r") | ||
n = 100 | ||
print(read(fd, n)) | ||
close(fd) | ||
|
||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from ltypes import i32, i64, ccall | ||
|
||
def open(path: str, flag: str) -> i64: | ||
""" | ||
Returns the file descriptor for the newly opened file | ||
""" | ||
return _lpython_open(path, flag) | ||
|
||
@ccall | ||
def _lpython_open(path: str, flag: str) -> i64: | ||
pass | ||
|
||
def read(fd: i64, n: i64) -> str: | ||
""" | ||
Reads at most `n` bytes from file descriptor | ||
""" | ||
return _lpython_read(fd, n) | ||
|
||
@ccall | ||
def _lpython_read(fd: i64, n: i64) -> str: | ||
pass | ||
|
||
def close(fd: i64): | ||
""" | ||
Closes the file descriptor | ||
""" | ||
_lpython_close(fd) | ||
return | ||
|
||
@ccall | ||
def _lpython_close(fd: i64): | ||
pass |