diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-03 03:42:41 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-03 03:42:41 -0500 |
| commit | 3a7588e5c5b7718012917b608e2346dc066cecc2 (patch) | |
| tree | aa88655cf4210d5256377ab44ec1915a0bcebcfc /std/common.cup | |
| parent | Move builtins to a separate file (diff) | |
| download | cup-3a7588e5c5b7718012917b608e2346dc066cecc2.tar.xz cup-3a7588e5c5b7718012917b608e2346dc066cecc2.zip | |
Remove `putc` intrinsic and replace with `write(fd, buf, size)`
`putc`, `puts`, and `putnum` in `std/common.cup` are now implemented
in terms of the `write()` syscall.
Diffstat (limited to 'std/common.cup')
| -rw-r--r-- | std/common.cup | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/std/common.cup b/std/common.cup index b5e0e9f..865e8c3 100644 --- a/std/common.cup +++ b/std/common.cup @@ -62,12 +62,24 @@ fn streq(s1: char *, s2: char *): int { return *s1 == *s2; } -// TODO: This should call fwrite() directly at some point. fn puts(c: char *) { let len: int = strlen(c); - let i: int = 0; + write(0, c, len); +} - for (i = 0; i < len; i = i + 1) { - putc(c[i]); +fn strrev(s: char *) { + let len: int = strlen(s); + let i: int = 0; + let j: int = len - 1; + while (i < j) { + let tmp: char = s[i]; + s[i] = s[j]; + s[j] = tmp; + i = i + 1; + j = j - 1; } -}
\ No newline at end of file +} + +fn putc(c: char) { + write(0, &c, 1); +} |