Re: [cc65] New .IDENT function

From: 42Bastian Schick <bastian421monlynx.de>
Date: 2005-05-10 08:34:49
42Bastian Schick <bastian42@monlynx.de> schrieb am Tue, 10 May 2005 
08:16:14 +0200:

> Ullrich
>
>> I've added a new pseudo function named .ident. Its purpose is to make an
>> identifier from a string. Example:
>>
>>         .macro  makelabel       arg1, arg2
>>                 .ident (.concat (arg1, arg2)):
>>         .endmacro
>>
>>                 makelabel       "foo", "bar"
>>
>>                 .word           foobar          ; Valid label
>>
>> If the argument of .ident starts with the current .localchar, it is 
>> converted
>> into a cheap local identifer.
>
> Nice new feature.
>
> Actually it would be interessing if following works (using .set as 
> variable :-)
>
> nesting .set 0
> elseuse .set 0
> 	.macro IFEQ arg
> nesting .set nesting + 1
> 	cmp	#arg
> 	bne	.ident(.concat("_else",.STRING(nesting)))
> 	.endmacro
>
> 	.macro ELSE
> elseuse .set elseuse + 1
> 	bra	.indent(.concat("_endif",.STRING(nesting)))
> .indent("_else",.STRING(nesting)):
> 	.endmacro
>
>
> 	.macro ENDIF
>    .if elseuse == nesting
> elseuse .set elseuse - 1
>    .else
> .indent("_else",.STRING(nesting))
>    .endif
> .indent("_endif",.STRING(nesting)):
> nesting .set nesting - 1
> 	.endmacro
>
> Now:
> 	IFEQ 10
> 	lda test
> 	ELSE
> 	lda game
> 	ENDIF
>
> would be possible.
>
> But it seems it is not possible to build a string out of a number...

With a small change in FuncString:
     if ( Tok == TOK_EQ ){
      	/* Numeric expression containing identifiers* /
         long Val;
	NextTok ();
	Val = ConstExpression ();
      	sprintf (Buf, "%ld", Val);
     } else  if (Tok == TOK_IDENT || Tok == TOK_LOCAL_IDENT) {

following works:
q = 10
  .ident(.concat("a",.string(=q))):
	.byte .string(=q) ; "10"
	.byte .string(q)  ; "q"
	.byte .string(=q+10) "20"
	jmp	a10

BTW: Sorry for putting hands on the sources, but they are simply inviting 
...

-- 
42Bastian Schick
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue May 10 08:34:58 2005

This archive was generated by hypermail 2.1.8 : 2005-05-10 08:35:01 CEST