flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] New method of preprocessing included file

Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7925
Location: Kraków, Poland
Tomasz Grysztar
I've found a very simple implementation of a small feature that allows to enable a preprocessor for an included file without the usual trickery.

Based on version j6ia, the patch looks like this:
Code:
==================================================================
--- source/directives.inc
+++ source/directives.inc
@@ -1282,11 +1282,17 @@
        mov     [edx+SymbolTree_Root.chain],eax
       new_parameter_namespace_ok:
        and     [eax+SymbolTree_Root.parameters],0
        mov     [ebx+SourceEntry.local_namespace],eax
        pop     esi
-       jmp     instruction_assembled
+       call    get_constituent_value
+       jc      instruction_assembled
+       cmp     al,','
+       jne     instruction_assembled
+       cmp     [number_of_line_embeddings],0
+       jne     invalid_argument
+       jmp     assemble_after_label
     include_stack_limit_exceeded:
        pop     esi
        mov     edx,_stack_limit_exceeded
        call    register_error
        jmp     instruction_assembled    
and it enables an additional argument of INCLUDE directive, which is a command that is going to be executed just before processing the first line of the included file:
Code:
include 'hello.asm', display 'The file has been read, time to process it...'    
It may not look like much, but it does in fact allow to enable a line interceptor just in time to start catching all the lines of the included file:
Code:
macro preprocess! line&
        display `line,10
end macro

include 'hello.asm', mvmacro ?,preprocess    
The command after comma may also itself be an invocation of a macro, if more complex preparation is necessary. It sees __FILE__ variable as already reflecting the included file, and __LINE__ is 0.

If you find it useful, please let me know. The implementation is so cheap, that I may consider adding it as an official feature, although it's one that may look a bit confusing unless you understand the specific problem that it solves.
Post 22 Apr 2021, 17:17
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3290
Location: vpcmipstrm
bitRAKE
This also allow a much cleaner solution to my file name trick to self-include a file in a different state. Probably eliminates half my passing code on the command-line, too.

_________________
¯\(°_o)/¯ unlicense.org
Post 26 Apr 2021, 22:55
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:  


< 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.