summaryrefslogtreecommitdiff
path: root/code/lib/print.felan
diff options
context:
space:
mode:
authorAhmad Mahmoudi <59058087+A404M@users.noreply.github.com>2025-04-25 18:50:41 +0000
committerGitHub <noreply@github.com>2025-04-25 18:50:41 +0000
commit0202e4c30d404e84b0ca37daad0a0c77135bf1a5 (patch)
tree83531f405964268e9e15d286347502f8b3e92d0a /code/lib/print.felan
parent0f50a82f0694bcf2902a772de63cc2b9a007c2f7 (diff)
parent32c9b5a9c854996ce7370618c348fcbd842d8d4f (diff)
Merge pull request #1 from Ilygm/master
Added print library
Diffstat (limited to 'code/lib/print.felan')
-rw-r--r--code/lib/print.felan167
1 files changed, 167 insertions, 0 deletions
diff --git a/code/lib/print.felan b/code/lib/print.felan
new file mode 100644
index 0000000..fd6663c
--- /dev/null
+++ b/code/lib/print.felan
@@ -0,0 +1,167 @@
+print :: (value:u8)->void{
+ putc value;
+};
+
+print :: (value:[]u8)->void{
+ i :u64= 0;
+ while i < value.length {
+ putc value[i];
+ i += 1;
+ }
+};
+
+print_reverse :: (value:[]u8, size:u8)->void{
+ size := size;
+ while size != 0 {
+ size -= 1;
+ putc value[size];
+ }
+};
+
+print :: (value:i8)->void {
+ value := value;
+ if (value < 0) {
+ putc '-';
+ if (value == -128) {
+ print("128");
+ return;
+ }
+ value = -value;
+ }
+
+ output :[3]u8= undefined;
+ i :u8= 0;
+ while {
+ output[i] = '0' + @cast(value % 10, u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(output, i - 1);
+};
+
+print :: (value:i16)->void {
+ value := value;
+ if (value < 0) {
+ putc '-';
+ if (value == -32768) {
+ print("32768");
+ return;
+ }
+ value = -value;
+ }
+
+ output :[5]u8= undefined;
+ i :u8= 0;
+ while {
+ output[i] = '0' + @cast(value % 10, u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(output, i);
+};
+
+print :: (value:i32)->void {
+ value := value;
+ if (value < 0) {
+ putc '-';
+ if (value == -2147483648) {
+ print("2147483648");
+ return;
+ }
+ value = -value;
+ }
+
+ output :[10]u8= undefined;
+ i :u8= 0;
+ while {
+ output[i] = '0' + @cast(value % 10, u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(output, i - 1);
+};
+
+print :: (value:i64)->void {
+ value := value;
+ if (value < 0) {
+ putc '-';
+ if (value == -9223372036854775808) {
+ print("9223372036854775808");
+ return;
+ }
+ value = -value;
+ }
+
+ output :[19]u8= undefined;
+ i :u8= 0;
+ while {
+ output[i] = '0' + @cast(value % 10, u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(output, i - 1);
+};
+
+print :: (value:u8)->void{
+ value := value;
+ result :[3]u8 = undefined;
+ i :u8= 0;
+ while {
+ result[i] = '0' + @cast(value % 10,u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(result, i - 1);
+};
+
+print :: (value:u16)->void{
+ value := value;
+ result :[5]u8 = undefined;
+ i :u8= 0;
+ while {
+ result[i] = '0' + @cast(value % 10,u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(result, i - 1);
+};
+
+print :: (value:u32)->void{
+ value := value;
+ result :[10]u8 = undefined;
+ i :u8= 0;
+ while {
+ result[i] = '0' + @cast(value % 10,u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(result, i - 1);
+};
+
+print :: (value:u64)->void{
+ value := value;
+ result :[20]u8 = undefined;
+ i :u8= 0;
+ while {
+ result[i] = '0' + @cast(value % 10,u8);
+ i += 1;
+ value /= 10;
+ value != 0;
+ } {}
+
+ print_reverse(result, i - 1);
+}; \ No newline at end of file