Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
DEntisT committed Aug 17, 2023
1 parent 9094b87 commit 1aaa2b0
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 57 deletions.
55 changes: 54 additions & 1 deletion src/modules/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,67 @@ the Initial Developer. All Rights Reserved.
// creds Y_Less



stock levenstein(const a[], const b[]) { //southclaws
new
aLength = strlen(a),
bLength = strlen(b),
cache[256],
index = 0,
bIndex = 0,
distance,
bDistance,
result,
code;

if (!strcmp(a, b)) {
return 0;
}

if (aLength == 0) {
return bLength;
}

if (bLength == 0) {
return aLength;
}

while (index < aLength) {
cache[index] = index + 1;
index++;
}

while (bIndex < bLength) {
code = b[bIndex];
result = distance = bIndex++;
index = -1;

while (++index < aLength) {
bDistance = code == a[index] ? distance : distance + 1;
distance = cache[index];

cache[index] = result = distance > result
? bDistance > result
? result + 1
: bDistance
: bDistance > distance
? distance + 1
: bDistance;
}
}

return result;
}


enum string_edges {
edge_left = 1,
edge_right = 2,
edge_both = edge_left | edge_right
};

// Big thanks to Slice (oscar broman), without him
// D++ would not exist the way it does now
// PawnScript would not exist the way it does now
stock dpp_codetrim(string[], const chars[] = !"", string_edges:edge = edge_both)
{
new bool:packed = ispacked(string);
Expand Down
88 changes: 35 additions & 53 deletions src/pawnscript.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -213,59 +213,6 @@ public OnGameModeExit()

//-----------------------------------------------------------



stock levenstein(const a[], const b[]) {
new
aLength = strlen(a),
bLength = strlen(b),
cache[256],
index = 0,
bIndex = 0,
distance,
bDistance,
result,
code;

if (!strcmp(a, b)) {
return 0;
}

if (aLength == 0) {
return bLength;
}

if (bLength == 0) {
return aLength;
}

while (index < aLength) {
cache[index] = index + 1;
index++;
}

while (bIndex < bLength) {
code = b[bIndex];
result = distance = bIndex++;
index = -1;

while (++index < aLength) {
bDistance = code == a[index] ? distance : distance + 1;
distance = cache[index];

cache[index] = result = distance > result
? bDistance > result
? result + 1
: bDistance
: bDistance > distance
? distance + 1
: bDistance;
}
}

return result;
}

main()
{
//CallLocalFunction("dpp_asmtest", "");
Expand All @@ -282,6 +229,25 @@ public pawnscript_testpawnfunc()
}

//-----------------------------------------------------------
myprintf(const formattedstr[], {Float,_}:...)
{
if(numargs() == 1)
{
@emit__ tempaddr ,.str=formattedstr
#emit push.c dpp_tempaddr__
#emit push.c 4
#emit sysreq.c print
#emit stack 8
#emit retn
return 0;
}

#emit nop // Just no.

#emit retn
return 0;
}

forward dpp_asmtest();
public dpp_asmtest()
{
Expand Down Expand Up @@ -359,6 +325,22 @@ public dpp_asmtest()
#emit zero.alt
#emit nop
printf("%i", dpp_pri__);

#emit nop
new test=5;
@emit__ tempfloat ,.float=23.34
#emit push.c dpp_tempfloat__
#emit push.adr test
@emit__ tempreg ,.int=__cellbytes
#emit push.c dpp_tempreg__
@emit__ tempaddr ,.str="Testaddr2 %i %i %f"
#emit push.c dpp_tempaddr__
#emit push.c 16
#emit sysreq.c printf
#emit stack 20

myprintf("hi");

#emit retn
return 1; // Make compiler happy.
}
Expand Down
21 changes: 19 additions & 2 deletions src/ps_asm.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@ the Initial Developer. All Rights Reserved.
*/

#define tempaddr 0
#define tempreg 1
#define tempfloat 2

#define @emit__%0\32;%1\10;%3 dpp_asm__(%1);

stock dpp_asm__(operand, int = 0, bool:bool = false, const str[] = "null")
stock dpp_asm__(operand, int = 0, bool:bool = false, Float:float = 0.0, const str[] = "null")
{
#pragma unused int
#pragma unused bool
if(operand == tempaddr)
{
strmid(dpp_tempaddr__, str, 0, sizeof dpp_tempaddr__);
return 1;
}
if(operand == tempreg)
{
#emit zero.pri
#emit load.s.pri int
#emit stor.pri dpp_tempreg__
return 1;
}

if(operand == tempfloat)
{
#emit zero.pri
#emit load.s.pri float
#emit stor.pri dpp_tempfloat__
return 1;
}
#emit retn
return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ps_mem.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,6 @@ new dpp_inputdest;
new dpp_pri__, dpp_alt__;
new dpp_bytes__;
#pragma unused dpp_bytes__
new dpp_tempaddr__[dpp_maxstrsize];
new dpp_tempaddr__[dpp_maxstrsize];
new dpp_tempreg__;
new Float:dpp_tempfloat__;

0 comments on commit 1aaa2b0

Please sign in to comment.