Author Topic: Backward compatibility  (Read 15477 times)

Klod

  • Guest
Backward compatibility
« on: August 31, 2010, 03:07:21 AM »
This macro works fine with version 8 but not with nasm-2.09rc4

%imacro uses 1-*.nolist
   %ifctx proc
      %push uses
      %assign %$j 0
      %rep %0
            %assign %$j %$j+1
            %xdefine %$reg_%$j %1
            push dword %1
            %rotate 1         
      %endrep
   %elifctx uses
      %rep %0
         %assign %$j %$j+1
         %xdefine %$reg_%$j %1
         push dword %1
         %rotate 1
      %endrep
   %else
      %error "'USES' must be used inside 'PROC/ENDPROC'"
   %endif
%endmacro

It produces error:`%xdefine' expects a macro identifier

Isn't %define and %xdefine the ways to define single line macros?

regards

Klod



Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Backward compatibility
« Reply #1 on: August 31, 2010, 04:20:45 AM »
Try 2.09, Klod - seems to work for me. Temporary glitch in 2.09rc4?

Best,
Frank


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Backward compatibility
« Reply #2 on: August 31, 2010, 04:42:51 AM »
Whoops, I spoke too soon. If I actually "%push proc", I do get that message. Doing:

Code: [Select]
            %xdefine %$reg_%+%$j %1

seems to work...

O'course, Keith is, how's the manual put it? "improve it out of all recognition" to the preprocessor, so glitches could crop up, as it develops. I think "backward compatibility" is intended - except for that ill-advised "look in outer contexts for context-specific variables" misfeature. 2.09 is supposed to warn, if that change is about to bite ya. :)

Best,
Frank


Offline Cyrill Gorcunov

  • NASM Developer
  • Full Member
  • *****
  • Posts: 179
  • Country: 00
Re: Backward compatibility
« Reply #3 on: September 01, 2010, 04:02:17 PM »
yeah, please try 2.09 and if it fail -- please post the caller code not only macro itself, thanks.

Klod

  • Guest
Re: Backward compatibility
« Reply #4 on: September 02, 2010, 02:41:27 AM »
I did compile with 2.09 and I do get the same error. I had compiled with both 2.09rc4 and 2.09rc7 with the same error.

I'm including here a copy of the program with the uses macro commented out and substituted with push/pop registers, it compiles and runs fine. This macro by the way I have adopted from one of Bryant Keller's post from a few years ago as are some of the other macros used in this example

See attached project
I compile with \nasm\bin\gorc,,,  \nasm\bin\NASM -f win32,,,   \nasm\bin\golink  @\nasm\bin\GFL.txt /entry Start

The errors I get:
\nasm\bin\NASM -f win32  "C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm"
C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm:82: error: `%xdefine' expects a macro identifier
C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm:106: error: comma, colon or end of line expected
C:\NasmEd\Project\WorkInProgress\LatestExamples\BasicWindow2\BasicWindow.asm:106: error: comma, colon or end of line expected

This is Line 82:  uses ebx,edi
This is line 106:  ENDP
And this is the offending statement: %xdefine %$reg_%$j %1

I wonder if this topic is not related??
http://forum.nasm.us/index.php?topic=863.0

Possibly not the correct context?

Regards
Klod

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Backward compatibility
« Reply #5 on: September 02, 2010, 03:41:20 AM »
See attached project

The first thing I see is...

Code: [Select]
%include '\nasm\inc\nasmmacros.asm'
%include '\nasm\inc\windows.inc'

... in which please provide those exact files as you have them, as a reply to this thread.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Backward compatibility
« Reply #6 on: September 02, 2010, 05:58:19 AM »
I don't think this is a "context" issue. I think it's a "token pasting"(?) issue. Both "$reg_ " and "%$j" are okay (I think) - both defined in this context. At one time (under some circumstances, at least) you could just jam 'em together:

Code: [Select]
%xdefine %$reg_%$j %1

"%+" has existed for some time as the "prefered"(?) way to do this...

Code: [Select]
%xdefine %$reg_%+%$j %1

Apparently, now you "have" to do it that way. I don't know if this is a "bug" or not. Since "%+" exists, I just figure "that's the way you're supposed to do it"... but it *is* a change...

At least, that works in my "test" code. Can you confirm whether that works or not in its "native habitat", Klod?

How "should" 2.10 do it, is the question...

Best,
Frank


Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Backward compatibility
« Reply #7 on: September 02, 2010, 06:50:17 AM »
I tend to use Macro Indirection for complex cases.

Klod

  • Guest
Re: Backward compatibility
« Reply #8 on: September 03, 2010, 04:03:09 AM »
Thank you all for your replies.

Frank, I think you are correct. I had tried  %+ before and I still got compile errors and had therefore discounted this possibility. I have played around a bit and this is what I have come up.

Your suggestion %xdefine %$reg_%+%$j %1  solves the define issue.

BasicWindow.asm:82: warning: 1 ebx1
BasicWindow.asm:82: warning: 2 edi2
BasicWindow.asm:82: warning: 3 esi3

However there is one more issue:
This is in the ENDP macro, when restoring the registers
BasicWindow.asm:107: error: comma, colon or end of line expected
This line: pop  dword %$reg_ %+ %$j

BasicWindow.asm:107: warning: 3 esi3 3
BasicWindow.asm:107: warning: 3 esi2 2
BasicWindow.asm:107: warning: 3 esi1 1

I don't quite understand the leading number but assume this to be an internal counter??

Keith, sorry for uploading an incomplete project, I was tired and rushed through the "packaging". Here is a complete copy that should allow you to compile.

Regards
Klod



Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Backward compatibility
« Reply #9 on: September 03, 2010, 07:25:40 AM »
Leaning towards a bug in 2.09+.

%xdefine %%reg_%$j %1 works, as expected. Using the context-local counterpart should as well, but it doesn't.

%xdefine %{${reg_%$j} %1 works, and it shouldn't... notice the missing bracket.

Something is amiss.

Klod

  • Guest
Re: Backward compatibility
« Reply #10 on: October 02, 2010, 04:48:49 AM »
I have been using a helper macro to circumvent this issue:
Code: [Select]
%macro def 2
        %xdefine %1 %2
%endmacro

def %$reg_%+%$j,%1

This seems to work with all versions of Nasm I have tested.

Regards,
Klod