diff options
| author | Baitinq <[email protected]> | 2025-06-11 00:16:17 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-06-11 00:16:17 +0200 |
| commit | fa92a157746ae17f295d31b7a047dfeb99624a13 (patch) | |
| tree | 71e469e67a70df15542d873ebe223654def6111b /examples/20.pry | |
| parent | stdlib: Remove println (diff) | |
| download | interpreter-fa92a157746ae17f295d31b7a047dfeb99624a13.tar.gz interpreter-fa92a157746ae17f295d31b7a047dfeb99624a13.tar.bz2 interpreter-fa92a157746ae17f295d31b7a047dfeb99624a13.zip | |
Diffstat (limited to 'examples/20.pry')
| -rw-r--r-- | examples/20.pry | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/20.pry b/examples/20.pry new file mode 100644 index 0000000..0cae122 --- /dev/null +++ b/examples/20.pry @@ -0,0 +1,49 @@ + +extern malloc = (i64) => *void; +extern free = (*void) => void; + +import "!stdlib.pry"; + +let init_array = (n: i64, arr: *i64) => i64 { + let i = 0; + while i < n { + (*(arr + cast(*i64, i))) = i; + i = i + 1; + }; + return 0; +}; + +let main = () => i64 { + let n = 10; + let arr = cast(*i64, malloc(n * 8)); + init_array(n, arr); + + let i = 0; + while i < n { + printf("%d\n", *(arr + cast(*i64, i))); + i = i + 1; + }; + + free(cast(*void, arr)); + + return 0; +}; + +/* + +Expected stdout: + +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + +Expected return: 0 + +*/ |