flat assembler
Message board for the users of flat assembler.

Index > Main > Redefining the syntax (flat assembler 1.61)

Goto page 1, 2, 3, 4, 5  Next

Do you like the proposed changes (read below)?
Yes
96%
 96%  [ 24 ]
No
4%
 4%  [ 1 ]
Total Votes : 25

Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
My recent additions have finally shown that my design of FIX directive was really a bit unfortunate. The explanations I had to give to define the source of problem FIX causes when combined with new REPT and MATCH directives have shown why people were reporting that usage of FIX is hard to understand - it was not really doing exactly the thing, that was defined to be its purpose: the absolute precedence over any other preprocessing.

So now I have an idea to clean up this mess. First, extend the new MATCH directive so it could be used for all the current applications of FIX where the messy details of FIX processing were exploited. Second, reimplement the FIX directive to behave in a clearly predictable way, always preceding any other preprocessing, on the lines from actual source. Here's an example how the "true" FIX would work:
Code:
V fix {

     macro some
     V          ; begins macro

V fix }         ; Even though we are defining macro now,
                ; the FIX has precedence over all other preprocessing,
                ; so V gets redefined now
                ; and this line doesn't become actually part of macro.

     V          ; ends macro    

So only this one application of FIX would be left and probably the most of the confusion with this directive would be avoided.

And so the question is: if all the current applications of FIX would be still possible to achieve with different methods (EQU combined with proposed MATCH), would you accept such backward-compatibility-breaking change?


Last edited by Tomasz Grysztar on 06 Jul 2005, 20:21; edited 3 times in total
Post 08 Jun 2005, 15:48
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
We're moving from 32bit to 64bit compilation, now is the perfect time to break any nagging backward compatibility issues. If it will enhance the efficiency of using the compiler it should be implemented.
Post 08 Jun 2005, 18:09
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
You could implement a directive, something like new_syntax, and it would imply that the source would be using the proposed 'fix' syntax. Old code would default to using the old syntax, and would be processed properly. Although it might be a bit too complicated to explain in the documentation.

_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*
Post 08 Jun 2005, 22:03
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
I'd prefer to clean up the things completely.
Post 08 Jun 2005, 22:32
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
As the famous saying goes, Cleanliness is next to Godliness.... However, if by 'CLEANING up completely' you wish to imply a formidible alteration to an existing masterpiece, then I wish to submit that "fix" is not actually an elegant term to employ.......
A good beginning to a more thorough revision, assuming one is needed, might include a detailed analysis of the goal of each of the elements of the assembler, together with a frank assessment of the current status of the code for each of the major sections. Instead of "fix", or "patch", one might then be asking, especially for this macro capability, "Is this operation really essential to the central artistic vision of FASM, or has the project outgrown its original scope?"
Just my opinion, probably not worth the space it occupies, but, I believe simpler is more elegant....
Smile
Post 08 Jun 2005, 22:52
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
I don't use fix often, but I see nothing wrong with breaking backwards-compatibility if the end result is cleaner than the original.
Post 08 Jun 2005, 23:22
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
crc wrote:
I don't use fix often, but I see nothing wrong with breaking backwards-compatibility if the end result is cleaner than the original.

My thoughts exactly.
Post 09 Jun 2005, 00:35
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
With such positive income I have implemented those changes today and thus came the 1.61.11 release - check it out, the Win32 version already contains the corrected macros where it was necessary (and not only - the old "proc" macro would still work, but is now cleaned up a bit thanks to "match", perhaps also other macros can be improved with use of the new features).

The improved "match" directive expands the symbolic constants inside the values to match, and one of my first samples of how it can be used now looks like:
Code:
macro freeform [arg]
 { common
     DONE equ NO
     match src->dst, arg
     \{
        mov dst,src
        DONE equ YES
     \}
     match =NO dst<-src, DONE arg
     \{
        mov dst,src
        DONE equ YES
     \}
     match =NO, DONE
     \{
        unrecognized syntax
     \}
 }

freeform eax -> ebx     ; mov ebx,eax

freeform al <- [esi+1]  ; mov al,[esi+1]    

And revolution's macros can be rewritten for example this way:
Code:
end_ifdef fix }
macro ifdef name { match =defined, name { }
macro ifndef name { match =name, name { }    


The application of "match" in the "proc"/"endp" macros is especially nice, in "proc" there's now line:
Code:
all@args equ arg    

which defines the symbolic constant with value containing list of all arguments to procedure; and the "endp" macro contains:
Code:
match all,all@args \{ restore all \}    

There are two features of "match" used here: first is that it replaces the "all@args" with its value before matching and therefore passes the whole list of arguments to "restore" directive, second is that it doesn't match empty values, so if there were not arguments at all, the "restore" won't be processed.
Post 09 Jun 2005, 01:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
Fabulous, I don't mind doing a little editing of my sources if it means that you can improve the syntax.
Post 09 Jun 2005, 02:39
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Please, explain why this doesn't work with new release and how it must be implemented now:

Code:
macro try _name
{
 @name fix _name
}

macro close
{
 @name#_lab:
}

try Asd

close

try Zxc

close             


Thanks.

_________________
Flat Assembler is the best!
Post 09 Jun 2005, 06:04
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
As I can explained in the first post above, the corrected FIX is now so prioritized, that it even doesn't become part of macro definition (I have given the example there, I though it's a good one). However for this application the good old EQU regains favor, with help of one of the MATCH directive's features:
Code:
macro try _name
{
 @name equ _name
}

macro close
{
 match name,@name \{ name\#_lab: \}
 restore @name
}    

BTW, that RESTORE gives the feature that was not present in the old-FIX-based solution - it allows nesting.


Last edited by Tomasz Grysztar on 09 Jun 2005, 08:34; edited 2 times in total
Post 09 Jun 2005, 08:16
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Thanks a lot for your explanation, Privalov!
I think it is very powerful feature.
Regards.
Post 09 Jun 2005, 08:21
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
Yeah, Flat Assembler is the best Very Happy
...but I wouldn't call this:
Code:
     \}
     match =NO, DONE
     \{
        unrecognized syntax
     \}
    
"clean" at least not visually - it's hard to read it out loud & pronounce... I hope you get what I mean.
I wish there would be a possibility to elegantly remove ""s from syntax as much as possible. Though, they are logical in the linechange - don't change that, please!
Post 09 Jun 2005, 08:22
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
The backslash was chosen for escaping since it was the best choice from the internals design point of view, and also seemed to be accepted so far. Hope you can get used to it.

The new version of HLL macros I've made today:
Code:
macro .if [arg]
{
  common
  __IF equ
  local ..endif
  __ENDIF equ ..endif
  local ..else
  __ELSE equ ..else
  JCOND __ELSE,arg
}

macro .else
{
  jmp __ENDIF
  __ELSE:
  restore __IF
  __IF equ ,
}

macro .elseif [arg]
{
  common
  jmp __ENDIF
  __ELSE:
  restore __ELSE
  local ..else
  __ELSE equ ..else
  JCOND __ELSE,arg
}

macro .endif
{
  if __IF eq
   __ELSE:
  end if
  __ENDIF:
  restore __ELSE
  restore __ENDIF
  restore __IF
}

macro .while [arg]
{
  common
  local ..while
  __WHILE equ ..while
  local ..endw
  __ENDW equ ..endw
  __WHILE:
  JCOND __ENDW,arg
}

macro .endw
{
  jmp __WHILE
  __ENDW:
  restore __ENDW
  restore __WHILE
}

macro .repeat
{
  local ..repeat
  __REPEAT equ ..repeat
  __REPEAT:
}

macro .until [arg]
{
  common
  JCOND __REPEAT,arg
  restore __REPEAT
}

macro JCOND label,[cond]
{
 common
 match =COND v1>==v2, COND cond
 \{
   cmp v1,v2
   jb label
   COND equ
 \}
 match =COND v1<==v2, COND cond
 \{
   cmp v1,v2
   ja label
   COND equ
 \}
 match =COND v1==v2, COND cond
 \{
   cmp v1,v2
   jne label
   COND equ
 \}
 match =COND v1<>v2, COND cond
 \{
   cmp v1,v2
   je label
   COND equ
 \}
 match =COND v1>v2, COND cond
 \{
   cmp v1,v2
   jbe label
   COND equ
 \}
 match =COND v1<v2, COND cond
 \{
   cmp v1,v2
   jae label
   COND equ
 \}
 match =COND v1=,c=,v2, COND cond
 \{
   cmp v1,v2
   jn\#c label
   COND equ
 \}
 match =COND v, COND cond
 \{
   cmp v,0
   je label
   COND equ
 \}
 restore COND
}

jnne equ je
jnna equ ja
jnnb equ jb
jnng equ jg
jnnl equ jl
jnnae equ jae
jnnbe equ jbe
jnnge equ jge
jnnle equ jle    

The new syntaxes can be used aswell as the old ones:
Code:
.if eax = 4

.elseif ebx > ecx

.elseif ecx, le, 2

.elseif edx

.else

.endif    

and it can be quite easy for anyone to add even more syntaxes there.
Post 09 Jun 2005, 09:31
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Please, help me again. How must I rewrite this code for new release:

Code:
macro declare 
{ 
 @data fix
}

macro _data Name,Type,Value
{
 @data fix @data,Name,Type,Value
}

macro insert_data space,[Name,Type,Value]
{
 forward
  Name Type Value
}

macro close
{
 insert_data @data
}

declare

 _data  a , dd , 100
 _data  b , db , 200

close    


Thanks.

_________________
Flat Assembler is the best!
Post 09 Jun 2005, 10:44
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
This exactly the same kind of problem, you were using FIX to create a list of arguments for macro, what is no longer possible - now you should use the standard EQU to create list and then MATCH directive to pass the value of list to macro:
Code:
macro declare
{
 @data equ
}

macro _data Name,Type,Value
{
 @data equ @data,Name,Type,Value
}

macro insert_data space,[Name,Type,Value]
{
 forward
  Name Type Value
}

macro close
{
 match data,@data \{ insert_data data \}
}    

Do you need some more explanation to be able to write such macros yourself? This is important, seeing what troubles you might got with understanding it will help me write better manual.

Hmm, or maybe even design something like multiple-matching, similar to the multiple macro arguments? The "forward" and family are currently unemployed in "match" block, and this would allow to do all the processing inside the "match" in sample above instead of calling another macro. But - again - I have to be careful with new ideas, I don't know yet how it could be done cleanly.
Post 09 Jun 2005, 10:49
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
Some cryptic macro sample just for the fun of it: Wink
Code:
include 'win32ax.inc'

macro AddAPI param { match (name),param \{ macro name [params] \\{ \\common match (args),params \\\{ invoke name,args \\\} match =dd any,params \\\{ name dd any \\\} \\} \} }

.code

  start:

        AddAPI(MessageBox);
        AddAPI(ExitProcess);

        MessageBox(HWND_DESKTOP,"Hi! I'm the example program!","Win32 Assembly",MB_OK);

        ExitProcess(0);

.end start    
Post 09 Jun 2005, 11:22
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Thanks again, Privalov!
I have seen these new features only few years ago that's why I have't enough time to study it somehow. I am interesting in replacing fix with new features because such tecniques (I mean fixes) are used in my OOP macros. With new release it doesn't work. I am very lucky because I thought about OOP macros improvement and haven't done it earlier. In this case I would get a lot of convertions to do. Moreover, this new features will be very helpful in my work. I think I will be able to write such macros myself, but if I have any question I will ask, of course.
Thanks and regards.
Post 09 Jun 2005, 11:38
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
I have a problem with Fresh macros for data definition (obviously they don't work). Currently they are:
Code:
macro iglobal {
  IncludeIGlobals fix IncludeIGlobals,
  macro __IGlobalBlock {
}

macro uglobal {
  IncludeUGlobals fix IncludeUGlobals,
  macro __UGlobalBlock {
}

endg fix }      

macro __IncludeIGlobals dummy,[n]
{
  forward
   __IGlobalBlock
   purge __IGlobalBlock
}

macro __IncludeUGlobals dummy,[n]
{
  common
    local begin, size
    begin = $
    virtual at $
  forward
      __UGlobalBlock
      purge __UGlobalBlock
  common
      size = $ - begin
    end virtual
    rb size
}

macro IncludeAllGlobals {
  IncludeIGlobals
  IncludeUGlobals
}

IncludeIGlobals fix __IncludeIGlobals
IncludeUGlobals fix __IncludeUGlobals    


I can't correct them Sad
Post 09 Jun 2005, 15:24
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7795
Location: Kraków, Poland
Tomasz Grysztar
Actually it's the same kind of solution as with IronFelix's macros:
Code:
macro iglobal {
  IncludeIGlobals equ IncludeIGlobals,
  macro __IGlobalBlock {
}

macro uglobal {
  IncludeUGlobals equ IncludeUGlobals,
  macro __UGlobalBlock {
}

endg fix }

macro __IncludeIGlobals dummy,[n]
{
  forward
   __IGlobalBlock
   purge __IGlobalBlock
}

macro __IncludeUGlobals dummy,[n]
{
  common
    local begin, size
    begin = $
    virtual at $
  forward
      __UGlobalBlock
      purge __UGlobalBlock
  common
      size = $ - begin
    end virtual
    rb size
}

macro IncludeAllGlobals {
 match I:U, IncludeIGlobals:IncludeUGlobals
 \{
    I
    U
 \}
}

IncludeIGlobals equ __IncludeIGlobals
IncludeUGlobals equ __IncludeUGlobals    
Post 09 Jun 2005, 15:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4, 5  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.