flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
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: 342
Location: ukraina
include once
edit: download is always located here

hi
tomasz, add include's modifier please:

Code:

include once 'please.ok?'




Last edited by idle on 15 Dec 2015, 17:37; edited 2 times in total
Post 11 Apr 2011, 06:38
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: 15171
Location: GW170817
There are already some macros for that here on this board.

See here.
Post 11 Apr 2011, 06:59
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA

revolution wrote:
There are already some macros for that here on this board.

See here.

I think your link is broken. It doesn't take me to and example... Wink
Post 11 Apr 2011, 07:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15171
Location: GW170817

Tyler wrote:
I think your link is broken. It doesn't take me to and example... Wink

Give a person a fish ...
Post 11 Apr 2011, 07:24
View user's profile Send private message Visit poster's website Reply with quote
idle



Joined: 06 Jan 2011
Posts: 342
Location: ukraina

Quote:

tomasz, add include's modifier please


that's what i need
Post 11 Apr 2011, 07:25
View user's profile Send private message Send e-mail Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA

revolution wrote:
Give a person a fish ...

... to make them really happy???

idle: You've been given your pole, line, and hook. It's up to you to learn; revolution's too lazy to teach you.
Post 11 Apr 2011, 07:58
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
What exactly do you want once to do?
Post 11 Apr 2011, 08:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15171
Location: GW170817

Tyler wrote:
... revolution's too lazy to teach you.

Hmm, well if by "lazy" you actually mean "busy" then correct. I tried to help, but I guess I failed this time around.
Post 11 Apr 2011, 08:18
View user's profile Send private message Visit poster's website Reply with quote
idle



Joined: 06 Jan 2011
Posts: 342
Location: ukraina
how that's seen in my mind:
having met include, fasm fetches full path of the file
then fasm inspects list of files it has included
if no such file included, fasm includes it regardless once presence
if a file had been included and once present, fasm does nothing
Post 11 Apr 2011, 08:52
View user's profile Send private message Send e-mail Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Sounds like you're having the multiple declaration problem that C headers solve with condition preprocessor macros. Doesn't Fasm have those?
Post 11 Apr 2011, 09:25
View user's profile Send private message Reply with quote
idle



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


Description:
Filesize: 44.72 KB
Viewed: 4230 Time(s)

1.71.39 include once (fasm patch).jpg


Description:
Download
Filename: 1.71.57 include once (fasm patch).7z
Filesize: 71.71 KB
Downloaded: 144 Time(s)



Last edited by idle on 04 Oct 2016, 06:27; edited 2 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: 15171
Location: GW170817
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: 342
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     byte[includes.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]=length(FullName)
        cmp     byte[includes.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     byte[edi],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: 15171
Location: GW170817
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: 15171
Location: GW170817
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: 15171
Location: GW170817

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: 342
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: 140 Time(s)

Post 15 Dec 2015, 14:11
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.