From e6e44774556bf6172c1577268cf9f013a4157ae2 Mon Sep 17 00:00:00 2001 From: A404M Date: Sun, 27 Apr 2025 02:11:41 +0330 Subject: add operator overloading --- code/basic.felan | 91 ++++++++++++++++++++++++++++++++------------------------ code/main.felan | 14 ++++++--- 2 files changed, 62 insertions(+), 43 deletions(-) (limited to 'code') diff --git a/code/basic.felan b/code/basic.felan index 9d93ef8..c9e8b61 100644 --- a/code/basic.felan +++ b/code/basic.felan @@ -1,40 +1,53 @@ -string :: []u8; - -print :: (value:[]u8)->void{ - i :u64= 0; - while i < value.length { - putc value[i]; - i += 1; - } -}; - -print :: (value:u64)->void{ - value := value; - result :[20]u8 = undefined; - i := 0; - while { - result[i] = '0' + @cast(value % 10,u8); - i += 1; - value /= 10; - value != 0; - } {} - - j := 0; - while j < i { - putc result[j]; - j += 1; - } -}; - -to_u64 :: (value:string) -> u64 { - i := value.length; - result :u64= 0; - - while i > 0 { - c := value[i-1]; - result *= 10; - result += @cast(c - '0',u64); - i -= 1; - } - return result; +__plus__ :: (a:u8) -> u8 { + return a; }; + +__plus__ :: (a:i8) -> i8 { + return a; +}; + +__plus__ :: (a:u16) -> u16 { + return a; +}; + +__plus__ :: (a:i16) -> i16 { + return a; +}; + +__plus__ :: (a:u32) -> u32 { + return a; +}; + +__plus__ :: (a:i32) -> i32 { + return a; +}; + +__plus__ :: (a:u64) -> u64 { + return a; +}; + +__plus__ :: (a:i64) -> i64 { + return a; +}; + +__minus__ :: (a:i8) -> i8 { + return a; +}; + +__minus__ :: (a:i16) -> i16 { + return a; +}; + +__minus__ :: (a:i32) -> i32 { + return a; +}; + +__minus__ :: (a:i64) -> i64 { + return a; +}; + +__logical_not__ :: (a:bool) -> bool { + return a; +}; + + diff --git a/code/main.felan b/code/main.felan index aeb4da9..b135110 100644 --- a/code/main.felan +++ b/code/main.felan @@ -1,9 +1,15 @@ -@import("lib/print.felan"); +@import("basic.felan"); main :: () -> void { - print(@isComptime); + a : u8 = 65; + b : u8 = 70; + a + b; }; -comptime { - print(@isComptime); +__sum__ :: (a:u8,b:u8)->void{ + putc 'h'; + putc a; + putc '\n'; + putc b; }; + -- cgit v1.2.3