Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

detecting '\'

A community discussion post from the original code:zIRON forum.

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

it is not possible, since i developed the macro system this way specifically for performance reasons.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

btw i updated RTL macro strJoin to cover for eax

inline function strJoin(;) {
	$maxbuf = $argc - 1;
	
	$if deftype($arg[$maxbuf]) <> 'int':	
		$raise 'strJoin final argument must be maximum buffer length';
	$end
	
	$i = 1;	
	$to = $argc - 2;	
	
	$repeat $to: 
		$if $arg[$i] = 'eax':
			push eax;
		$end;
	$end;

	$repeat $to:  
		$if $arg[$i] = 'eax':
			pop eax
		$end;

		eax = strAppend($arg[0], $arg[$i], $arg[$maxbuf]);
		$i++;
	$end;
	
	$return eax;
}

but of course it would be better to use another free register, since its 1 less push/pop

Colin admin
Posts
928
Threads
49
Location
Bulgaria

sorry fixed a bug and made a little better:

inline function strJoin(;) {
	$maxbuf = $argc - 1;
	
	$if deftype($arg[$maxbuf]) <> 'int':	
		$raise 'strJoin final argument must be maximum buffer length';
	$end
	
	$i = 1;	
	$to = $argc - 2;	
	
	$repeat $to: 
		$if $i > 1:
			$if $arg[$i] = 'eax':
				push eax;
			$end;
		$end;
		$i++;
	$end;

	$i = 1;
	$repeat $to:  
		$if $i > 1:
			$if $arg[$i] = 'eax':
				pop eax
			$end;
		$end;

		eax = strAppend($arg[0], $arg[$i], $arg[$maxbuf]);
		$i++;
	$end;
	
	$return eax;
}
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok does ziron support string array, or not.

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

sorry , i have to go now , if i have time i will post again tonight .

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

firs you will need to make a fix to strlcpy in strings.zir, replace the whole strlcpy macro with:

//
// Copyright (c) 2012. OverHertz Ltd
//
inline procedure m_strcpy_std(dst, ssrc, ln) {
	push edi
	push esi
	push ecx
	
	edi = $dst;
	esi = $ssrc;
	ecx = $ln;
	shr ecx, 2
	rep movsd

	ecx = $ln;
	and ecx, 3
	rep movsb

	pop ecx
	pop esi
	pop edi
}
	
inline procedure m_strcpy_mmx(dst, ssrc, ln) {
	push edi
	push esi
	push ecx
	push edx

	edi = $dst;
	esi = $ssrc;  
	ecx = $ln;
	edx = ecx;
		  
	shr ecx, 6
	if (ecx <> 0) {
		repeat {
			//$if defined(assembler_SSE_ON) == true:
			//$end
				
			movq mm0, qword[esi+0]
			movq mm1, qword[esi+8]
			movq mm2, qword[esi+16]
			movq mm3, qword[esi+24]
			movq mm4, qword[esi+32]
			movq mm5, qword[esi+40]
			movq mm6, qword[esi+48]
			movq mm7, qword[esi+56]
				
			movq qword[edi+0], mm0
			movq qword[edi+8], mm1
			movq qword[edi+16], mm2
			movq qword[edi+24], mm3
			movq qword[edi+32], mm4
			movq qword[edi+40], mm5
			movq qword[edi+48], mm6
			movq qword[edi+56], mm7
				
			esi += 64;
			edi += 64;
				
			edx -= 64;
		
			ecx -= 1;
		} until (ecx == 0);
	}
		  
	ecx = edx;  
	shr edx, 3
		  
	if (edx <> 0) {
		repeat {
			movq mm0, qword[esi]
			movq qword[edi], mm0
			
			esi += 8;
			edi += 8;
			
			ecx -= 8;		
			edx -= 1;
		} until (edx == 0);
	}
			
	rep movsb

	pop edx
	pop ecx
	pop esi
	pop edi
		  
	emms	
}
	
inline procedure strlcpy(dest, source, len) {	
	$if defined(assembler_MMX_ON) == true:
		$if $len of 0:
			$if $len < 64:
				m_strcpy_std($dest, $source, $len);
			$else
				m_strcpy_mmx($dest, $source, $len);
			$end
		$else
			if ($len < 64) {
				m_strcpy_std($dest, $source, $len);
			} else {
				m_strcpy_mmx($dest, $source, $len);
			}
		$end;
	$else
		m_strcpy_std(dest, source, len);
	$end
}

ok now the fix is done, here is small string sample:

program WIN32CUI 'test';

#include 'ch.zir';

char* myArr[2];

//constant mem
myArr[0] = 'String 1';
myArr[1] = 'String 2';

print(myArr[0], '	', myArr[1], '\r\n');

//dynamic
myArr[0] = malloc(16);
myArr[1] = malloc(16);

strlcpy(myArr[0], 'Test 1', sizeof 'Test 1');
strlcpy(myArr[1], 'Test 2', sizeof 'Test 2');

print(myArr[0], '	', myArr[1], '\r\n');

delete myArr[0];
delete myArr[1];

wait_key();
ExitProcess(0);
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , but this not allowed

for(ecx = 0 to 1)
{
  print(myArr[ecx], '\r\n');
}

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i plan to add this but for now:

edi = @myArr;

for(ecx = 0 to 1) {
  print([edi+ecx*4], '\r\n');
}