flat assembler
Message board for the users of flat assembler.

flat assembler > Compiler Internals > include once

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
idle



Joined: 06 Jan 2011
Posts: 359
Location: ukraina
Done.
version.inc controls if the facility should be included.


Description:
Download
Filename: 1.73.09 include once (fasm patch).7z
Filesize: 72.69 KB
Downloaded: 363 Time(s)



Last edited by idle on 17 Feb 2019, 21:30; edited 5 times in total
Post 15 Dec 2015, 10:16
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
Good job. I like to see small modifications like this.

Can you post just the differences (a patch type file) only?

Also, I didn't try it, but can the first instance of a file also use the "once" syntax? That is: do users need to worry about which include statement is the first, or can they just make everything "include once"?
Post 15 Dec 2015, 11:18
View user's profile Send private message Visit poster's website Reply with quote
idle



Joined: 06 Jan 2011
Posts: 359
Location: ukraina
>>Good job. I like to see small modifications like this.
:)

>>Can they just make everything "include once"?
They can.

>>Can you post just the differences (a patch type file) only?




version.inc
Code:
...
;;
INCLUDEONCE=1
display 13,10,'INCLUDEONCE=',INCLUDEONCE+'0'
;;
...
    





variable.inc
Code:
...
if INCLUDEONCE=1
;; change with care
align 4
includes
  .flags rd 1
  .count rd 1
  .files rd $ff
  .limit rd 1
;;
end if
...
    






preproce.inc
Code:
...
if INCLUDEONCE=1
        ;;
        mov     includes.count,eax
        mov     includes.files,eax    ;last include is none yet
        ;;
end if
...




if INCLUDEONCE=1
        ;;
        mov     byteincludes.flags,al ;remember include form
        cmp     al,1Ah
        jne     common_include          ;no once key
        lodsb
        cmp     al,4
        jne     invalid_argument        ;length'once' must be 4 
        lodsd
        or      eax,'    '              ;case ignorant
        cmp     eax,'once'
        jne     invalid_argument        ;no once key
        lodsb                           ;resume common include 
      common_include
        ;;
end if
...




if INCLUDEONCE=1
        ;;
        movzx   eax,al
        mov     al,upper_case_table+eax
        ;;
end if
...




if INCLUDEONCE=1
        ;;
        mov     esp-8,edi
        ;esp-4     =FullName
        ;esp-8     =beyond FullName0
        ;FullName-4=lengthFullName
        cmp     byteincludes.flags,1Ah
        jne     .include_file
        mov     edx,includes.files-4
      .match_next_include
        add     edx,4
        mov     edi,edx
        test    edi,edi
        jz      .include_file
        mov     esi,esp-4
;sub esp,8
;push edx
;invoke MessageBox,0,edi,esi,0
;pop edx
;add esp,8
        mov     ecx,esi-4
        cmp     ecx,edi-4
        jne     .match_next_include
        repe    cmpsb
        jne     .match_next_include
      .!include_file
        call    close
        mov     edi,current_line
        mov     byteedi,0
        jmp     line_preprocessed
      .include_file
        mov     edi,includes.count
        lea     edi,includes.files+edi*4
        cmp     edi,includes.limit
        je      out_of_memory
        inc     includes.count
        mov     esi,esp-4
        mov     edi,esi
        mov     edi+4,dword 0
        mov     edi,esp-8
        ;;
end if
...




    
Post 15 Dec 2015, 12:06
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
Just some things I think people should be aware of before they decide to use it:

There is a limit of 254 files plus one pointer that must be kept as zero to terminate the search.

Also the path and case must be specified exactly the same else it won't match.
Code:
include once 'abc.inc'
;...
include once 'ABC.INC' ;<--- on Windows this is the same file.
;...
include once '.\abc.inc' ;<--- the same file again but not matched.    
Post 15 Dec 2015, 12:53
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
revolution wrote:
Also the path and case must be specified exactly the same else it won't match.

Well, then the patch is no-go. It's quite controversial by itself, whether it is a responsibility of the includer or the includee to ensure unique inclusion, or how "include once" should behave in relation to the normal include. And if it doesn't even make use of smth. like GetFileInformationByHandle, it's no better than the existing macros doing the same. In the current implementation it's actually worse.

_________________
Faith is a superposition of knowledge and fallacy
Post 15 Dec 2015, 13:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
I don't see why it is worse. But anyhow, knowing the limitations should be enough. Users can then decide if it is fit for their purpose(s). Having some sort of coding standard documentation for specifying file paths could help to avoid problems in one's code.
Post 15 Dec 2015, 13:21
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
revolution
Quote:
I don't see why it is worse.

There's at least one technical reason (you mentioned) for that: the limit of 254 files. And the conceptual reason is that macros give more flexibility. E.g., if you have a (say "legacy") project using only include, then you can use my includecheck (it can be improved using irpv) to avoid include duplication without having to refactor the project.

Quote:
Having some sort of coding standard documentation for specifying file paths could help to avoid problems in one's code.

And why should one introduce such a limitation for a native solution, if it is (contrary to macros) possible to avoid it?

_________________
Faith is a superposition of knowledge and fallacy
Post 15 Dec 2015, 13:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
l_inc wrote:
And why should one introduce such a limitation for a native solution, if it is (contrary to macros) possible to avoid it?
Because Linux, Unix and Windows would break the code in different ways due to case and path differences. So keeping a standard naming scheme is already a desirable asset regardless of the availability of includeonce.
Post 15 Dec 2015, 13:59
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
revolution
Quote:
Because Linux, Unix and Windows would break the code in different ways due to case and path differences.

Provide an example. Without it it seems you are just ignoring what I say.

_________________
Faith is a superposition of knowledge and fallacy
Post 15 Dec 2015, 14:04
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 359
Location: ukraina
Files limit can migrate from $ff=255 -> $ffff=65535 :)
Code:
include OnCe 'abc.inc'
include oNcE 'ABC.INC' ;<--- on Windows this is the same file.
                       ;     and once knows that

;to see how full paths are operated on, open 1.71.39 preproce.inc and uncomment as follows
; sub esp,8
; push edx
; invoke MessageBox,0,edi,esi,0
; pop edx
; add esp,8
;recompile fasm and run your sources again
include once '.\abc.inc' ;<--- the same file again but not matched.            
    


Description:
Download
Filename: 1.71.39 revo test.7z
Filesize: 56.49 KB
Downloaded: 330 Time(s)

Post 15 Dec 2015, 14:11
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
l_inc wrote:
revolution
Quote:
Because Linux, Unix and Windows would break the code in different ways due to case and path differences.

Provide an example. Without it it seems you are just ignoring what I say.
Code:
include 'c\code\uberstuff.inc' ;<--- Linux can open this?    
Post 15 Dec 2015, 14:19
View user's profile Send private message Visit poster's website Reply with quote
idle



Joined: 06 Jan 2011
Posts: 359
Location: ukraina
Post 15 Dec 2015, 14:24
View user's profile Send private message Send e-mail Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
revolution
I didn't say, one should use full paths, but your suggestion is to introduce many more limitations. Say there's a library that includes its files using relative paths (similar to win32a.inc). Some files can be included as a part of the library or individually. The relative paths would be different. How restrictive should be your rules to avoid this?

That's not mentioning that soft and hard links are possible in both Windows and Linux. Taking that into account shows that C-style inclusion duplication prevention is the only correct way. Just consider what you'd do to compile a project making use of soft links on a system that has no support for them.

_________________
Faith is a superposition of knowledge and fallacy
Post 15 Dec 2015, 14:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
l_inc wrote:
That's not mentioning that soft and hard links are possible in both Windows and Linux. Taking that into account shows that C-style inclusion duplication prevention is the only correct way. Just consider what you'd do to compile a project making use of soft links on a system that has no support for them.
I agree. I never said this was a proper or complete solution. It is not. But if one wants to make to most of it then such self restrictions can help to make it less error prone to use.
Post 15 Dec 2015, 16:41
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
revolution
I have nothing against some rules of project organization. I'm just saying that the only reason to implement "include once" natively is the ability to unambiguously identify files, and if even this advantage is ignored, then it's just useless.

_________________
Faith is a superposition of knowledge and fallacy
Post 15 Dec 2015, 19:16
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 359
Location: ukraina
Again, once is a user-typed hint to overcome standard behaviour of fasm.
It does nothing to fasm structures, keeping inclusion order as described in official manual.
What it really does: when fasm is just about including a file, once checks for its presence and does its job.
Post 16 Dec 2015, 06:25
View user's profile Send private message Send e-mail Reply with quote
idle



Joined: 06 Jan 2011
Posts: 359
Location: ukraina
hi, just updated to 1.72
esp tnx to TG for keeping include logics same
Post 21 Nov 2017, 16:55
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  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-2019, Tomasz Grysztar.

Powered by rwasa.