From 483d573f3f4641068576457e950aac2d1ba37618 Mon Sep 17 00:00:00 2001 From: Sergey Svishchev Date: Tue, 28 May 2024 13:43:25 +0300 Subject: [PATCH] minor QoL improvements and size optimisations --- rt/common.coh | 4 ++-- rt/strings.coh | 29 +++++++++++++++++++++-------- src/cowfe/lexer.coh | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/rt/common.coh b/rt/common.coh index a13a313e..5d4a6fc3 100644 --- a/rt/common.coh +++ b/rt/common.coh @@ -16,14 +16,14 @@ end sub; sub UIToA(value: uint32, base: uint8, buffer: [uint8]): (ptr: [uint8]) is ptr := buffer; loop - var rem := value % (base as uint32); + var rem := (value % (base as uint32)) as uint8; value := value / (base as uint32); if rem < 10 then rem := rem + '0'; else rem := rem + ('a' - 10); end if; - [ptr] := rem as uint8; + [ptr] := rem; ptr := @next ptr; if value == 0 then diff --git a/rt/strings.coh b/rt/strings.coh index 046e07ec..c6fbd22e 100644 --- a/rt/strings.coh +++ b/rt/strings.coh @@ -4,8 +4,21 @@ sub StrCmp(s1: [uint8], s2: [uint8]): (res: int8) is if (res != 0) or ([s1] == 0) then break; end if; - s1 := s1 + 1; - s2 := s2 + 1; + s1 := @next s1; + s2 := @next s2; + end loop; +end sub; + +sub MemCmp(s1: [uint8], s2: [uint8], len: uint16): (res: int8) is + var i: uint16 := 1; + loop + res := ([s1] - [s2]) as int8; + if (res != 0) or i == len then + break; + end if; + s1 := @next s1; + s2 := @next s2; + i := i + 1; end loop; end sub; @@ -23,8 +36,8 @@ sub StrICmp(s1: [uint8], s2: [uint8]): (res: int8) is if (res != 0) or ([s1] == 0) then break; end if; - s1 := s1 + 1; - s2 := s2 + 1; + s1 := @next s1; + s2 := @next s2; end loop; end sub; @@ -43,9 +56,9 @@ end sub; sub CopyString(src: [uint8], dest: [uint8]) is loop var c := [src]; + src := @next src; [dest] := c; - src := src + 1; - dest := dest + 1; + dest := @next dest; if c == 0 then break; end if; @@ -55,8 +68,8 @@ end sub; sub MemCopy(src: [uint8], size: intptr, dest: [uint8]) is while size != 0 loop [dest] := [src]; - dest := dest + 1; - src := src + 1; + dest := @next dest; + src := @next src; size := size - 1; end loop; end sub; diff --git a/src/cowfe/lexer.coh b/src/cowfe/lexer.coh index ea258736..d4a7a3a3 100644 --- a/src/cowfe/lexer.coh +++ b/src/cowfe/lexer.coh @@ -487,6 +487,7 @@ sub LexerReadToken(): (token: uint8) is when 'n': c := 10; when 'r': c := 13; when 't': c := 9; + when 'e': c := 27; when '\\': c := '\\'; when '\'': c := '\''; when '"': c := '"';