Skip to content

Commit

Permalink
Merge pull request #148 from shattered/_3be1181f
Browse files Browse the repository at this point in the history
minor QoL improvements and size optimisations
  • Loading branch information
davidgiven authored Jun 17, 2024
2 parents b02a53e + 483d573 commit d5a8639
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions rt/common.coh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions rt/strings.coh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/cowfe/lexer.coh
Original file line number Diff line number Diff line change
Expand Up @@ -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 := '"';
Expand Down

0 comments on commit d5a8639

Please sign in to comment.