From 1aaa2b06f6690edac8a9c17560ae6c82e00484ca Mon Sep 17 00:00:00 2001 From: DEntisT Date: Thu, 17 Aug 2023 18:43:25 +0200 Subject: [PATCH] More tests. --- src/modules/utils.inc | 55 ++++++++++++++++++++++++++- src/pawnscript.pwn | 88 +++++++++++++++++-------------------------- src/ps_asm.pwn | 21 ++++++++++- src/ps_mem.pwn | 4 +- 4 files changed, 111 insertions(+), 57 deletions(-) diff --git a/src/modules/utils.inc b/src/modules/utils.inc index 11ad7ff..ec2f61f 100644 --- a/src/modules/utils.inc +++ b/src/modules/utils.inc @@ -24,6 +24,59 @@ 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, @@ -31,7 +84,7 @@ enum string_edges { }; // 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); diff --git a/src/pawnscript.pwn b/src/pawnscript.pwn index bcaef28..b91fb1b 100644 --- a/src/pawnscript.pwn +++ b/src/pawnscript.pwn @@ -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", ""); @@ -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() { @@ -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. } diff --git a/src/ps_asm.pwn b/src/ps_asm.pwn index aa08dac..c0f027d 100644 --- a/src/ps_asm.pwn +++ b/src/ps_asm.pwn @@ -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; } diff --git a/src/ps_mem.pwn b/src/ps_mem.pwn index 97f4bb4..0d0dacc 100644 --- a/src/ps_mem.pwn +++ b/src/ps_mem.pwn @@ -381,4 +381,6 @@ new dpp_inputdest; new dpp_pri__, dpp_alt__; new dpp_bytes__; #pragma unused dpp_bytes__ -new dpp_tempaddr__[dpp_maxstrsize]; \ No newline at end of file +new dpp_tempaddr__[dpp_maxstrsize]; +new dpp_tempreg__; +new Float:dpp_tempfloat__; \ No newline at end of file