fa/std/std.fa
Ari Archer c30a3de674
Deprecate mutability contexts
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
2022-07-27 13:41:50 +03:00

129 lines
1.8 KiB
Text

include 'std/syscall.fa'
macro STDIN 0 end
macro STDOUT 1 end
macro STDERR 2 end
macro EXIT_SUCCESS 0 end
macro EXIT_FAILURE 1 end
macro CHAR_SZ 1 end
macro INT_SZ 4 end
macro SHORT_SZ 2 end
macro LONG_SZ 8 end
macro FLOAT_SZ 4 end
macro DOUBLE_SZ 8 end
macro LDOUBLE_SZ 10 end
--<
Write a string to a specified file descriptor
Takes:
INT: File descriptor
STR: The string
INT: The size
>--
macro fputs
%SYS_write sys 4 pop
end
--<
Print a string and then a newline
Takes:
STR: The string
>--
macro puts
%STDOUT %fputs -- The string
"\n" %STDOUT %fputs -- Newline
end
--<
Print a string and then a newline (to stderr)
Takes:
STR: The string
>--
macro eputs
%STDERR %fputs -- The string
"\n" %STDOUT %fputs -- Newline
end
--<
Print a character from its charcode to
a specified file descriptor
Takes:
INT: The char code
INT: The file descriptor
>--
macro fputc
swap
as __fputc_charcode
1 @__fputc_charcode swap %fputs
unname __fputc_charcode
end
--<
Wrapper around %fputc for stdout
Takes:
INT: The char code
>--
macro putc
%STDOUT %fputc
10 %STDOUT %fputc
end
--<
Exit with a specified exit code
Takes:
INT: The exit code
>--
macro exit
%SYS_exit sys 2 pop
end
--<
Print a todo message and exit with EXIT_FAILURE
Takes:
STR: The todo
>--
macro todo
"TODO: " %STDERR %fputs
%STDERR %fputs
"\n" %STDERR %fputs
%EXIT_FAILURE %exit
end
--<
Print an error message and exit with EXIT_FAILURE
Takes:
STR: The error message
>--
macro error
"ERROR: " %STDERR %fputs
%STDERR %fputs
"\n" %STDERR %fputs
%EXIT_FAILURE %exit
end