flat assembler
Message board for the users of flat assembler.

Index > Main > include directive behavior

Author
Thread Post new topic Reply to topic
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 17 Nov 2003, 17:22
I tried to organize one of my projects in multiple files in multiple directories when i discovered that if i for example have structure like this:
Code:
Project folder:
test.asm
sub folder:
   test2.asm
   test2.inc
;in test.asm:
include 'sub folder\test2.asm'
;in sub folder\test2.asm:
include 'test2.inc'
    

It won't include 'test2.inc' because it tries to find 'test2.inc' in same folder that has the main source file. I think it would be better to make include work so it would include files relative to current file instead of main source file. Comments, please. Or mayby someone knows how to implement this with macros?
Post 17 Nov 2003, 17:22
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Nov 2003, 18:13
Wouldnt it be better to refer to current idea with '.'. SO to do what you want you could just use
Code:
include '.\test2.inc'    

Maybe not '.', it could be problem with OS, but some special symbol, or pseudo-environment variable (like %CurrentFile%).
Post 17 Nov 2003, 18:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 19 Nov 2003, 13:04
In my opinion it should be includes default behavior but something like %CurrentDir% would also do so i could have macro that works like i want.
Post 19 Nov 2003, 13:04
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 19 Nov 2003, 16:26
It is useful indeed, and not only for includes but for all directory references in fasm (file and load directives).
It could be a fasm directive to indicate reference at current preprocessed file path.
AFAIK it cannot be done with only macros (until Privalov proves me wrong Twisted Evil )

The result could be similar to the time directive (%T) that Privalov is including in new release:

%T - compile time
%D - current parsed file directory
%F - current parsed file name
Post 19 Nov 2003, 16:26
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 20 Nov 2003, 19:12
didnt you mean current preprocessed? (not current parsed)
Post 20 Nov 2003, 19:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 22 Nov 2003, 16:36
If you Privalov see this, would it be difficult to add something like %D to fasm? I would really appreciate it, i'm trying to create macros for somekind of module system and i have structured my projects like this:
Code:
ProjectDir:
   main.asm
   main.inc
   foobar.asm
   Module1:
      main.asm
      main.inc
      foo.asm
      bar.asm
      SubModule:
         main.asm
         main.inc
   Module2:
      main.asm
      main.inc
    
Post 22 Nov 2003, 16:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Nov 2003, 14:21
aaro: why .inc files? You compile to OBJ files and link then? If you just include everything into one file and assemble then i dont see reason for separate .inc files. And if not, why do you need %D then?

do not take this as offense, i was just wondering why you use them
Post 23 Nov 2003, 14:21
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 23 Nov 2003, 14:54
vid,

The main feature of Fasm is that it can produce executables without the usage of object files,in another way,you don't have to use an external linker. Naturally,depending on the project, one can select the classical method based on creating obj files.

_________________
Code it... That's all...
Post 23 Nov 2003, 14:54
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 23 Nov 2003, 18:47
I have designed very interesting macro solution (fasm 1.49.9.2 or higher is needed, as it uses the concatenations of quoted strings, which was not enabled in earlier versions):
Code:
macro incdir dirpath,filename
{
 macro rstincdir .% inc_dir fix cur_dir %.
 cur_dir fix cur_dir # '\' # dirpath
}

macro endinc
{
 rstincdir
 purge rstincdir
}

macro defincl
{
 macro incl filename
 .%
   defincl
   INCLUDE inc_dir .. '\' .. filename
   purge incl
 %.
}

include fix incl
inc_dir fix cur_dir
cur_dir fix '.'
.% fix {
%. fix }
.. fix __
__ fix #
defincl    

Here's an example of usage:
Code:
include 'foobar.inc'    ; includes .\foobar.inc

incdir 'module1'
  include 'foo.inc'     ; includes module1\foo.inc
  include 'bar.inc'     ; includes module1\bar.inc
endinc    

and file "module1\foo.inc" may contain something like:
Code:
include 'subfoo.inc'    ; includes module1\subfoo.inc

incdir 'submod1'
  include 'x.inc'       ; includes module1\submod1\x.inc
endinc    
Post 23 Nov 2003, 18:47
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 23 Nov 2003, 21:23
Privalov: Thank you VERY mutch! Just what i needed.

vid: I like the ability in fasm to assemble without linking and i use separate .inc/.asm files just to organise my code. With these macros i can now have my modules in sub dirs under my project dir and if i need that module in some other project i just copy the sub dir in the new project folder. Then if i need to change something in my module it won't break my old code.
Post 23 Nov 2003, 21:23
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Nov 2003, 05:48
vortex: i know, i was just asking him which method he uses

aaro: i use modules too (for reusuability, but i never reused anything, i rather rewrite it better). But in assermbly there's not separate declaration and definition like in C, and i only break my module file when they are is too big to maintain.
But, of course, code as you like.
Post 24 Nov 2003, 05:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 27 Nov 2003, 02:27
Privalov, is it possible to get these macros work with paths outside the project dir? Now i have to use old include with paths like: '%include%\win32a.inc' and incl with others(commented line 'include fix incl'). Not very importan(i can live with it) but it would be nice if it worked with those too. I can't think way to accomplish this, but it wouldn't be first time you show me how to go around these obstacles.
And in macro 'incdir' there is paramater called 'filename' witch is never used, probably some leftover from previous version, just to inform you.
Post 27 Nov 2003, 02:27
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 27 Nov 2003, 15:33
You can try such little modified version:
Code:
macro incdir dirpath
{
macro rstincdir .% inc_dir fix cur_dir %.
cur_dir fix cur_dir # dirpath
}

macro endinc
{
rstincdir
purge rstincdir
}

macro defincl
{
macro incl filename
.%
   defincl
   INCLUDE inc_dir .. filename
   purge incl
%.
}

include fix incl
inc_dir fix cur_dir
cur_dir fix ''
.% fix {
%. fix }
.. fix __
__ fix #
defincl    

It should allow normal include use, and the only difference is that you should include path separator at the end of path for "incdir" macro, like:
Code:
incdir 'module1\' 
  include 'foo.inc'     
  include 'bar.inc'    
endinc    
Post 27 Nov 2003, 15:33
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 27 Nov 2003, 17:36
Won't work in modules(incdir has been called). I can't think any other solution to this but to somehow compare start of file name with '%include%' and '\' but i don't think that's possible.. I hope i'm mistaken.
Post 27 Nov 2003, 17:36
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 27 Nov 2003, 17:59
Do you mean that you need to do use %include%-like includes in the submodules? Indeed, that would be harder. But you can always use the uppercase INCLUDE for such purpose (or: Include) - it will invoke the original one, not macro.
Post 27 Nov 2003, 17:59
View user's profile Send private message Visit poster's website Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro 27 Nov 2003, 19:53
Yes that's what i meant. Harder, but not impossible? Twisted Evil
But it's good enought allready, i'll use INCLUDE when i want normal behavior. Thank you.
Post 27 Nov 2003, 19:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.