flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > CALM CALL instruction

Author
Thread Post new topic Reply to topic
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 20 Apr 2023, 12:07
Hi Tomasz
Another question reg. CALM : getting kinda puzzled by CALL instruction ... what exact purpose does it serve ?
What would be the difference between CALL and sthg like ARRANGE + ASSEMBLE ?

typ., assuming i have
Code:
calminstruction calm_inx
(...)
end calminstruction
    

how is
Code:
calminstruction another_calm_inx
   call calm_inx
end calminstruction
    

different from
Code:
calminstruction another_calm_inx
   local _cmd
   arrange _cmd, =calm_inx
   assemble _cmd
end calminstruction
    
Post 20 Apr 2023, 12:07
View user's profile Send private message Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 20 Apr 2023, 12:16
. or even different from simply
Code:
calminstruction another_calm_inx
   calm_inx
end calminstruction
    
    
Post 20 Apr 2023, 12:16
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 20 Apr 2023, 13:58
CALL was implemented on a request from one of the early adopters of CALM, purely for performance reasons. However, they way it is implemented, it also allows to do some small tricks that are not possible through a normal ASSEMBLE route.

When a macro is called through a standard assembly, the arguments are always symbolic values - pieces of text cut from the original assembled line. But when giving values to CALL variables, you can pass any kind of value, not necessarily symbolic. This allows for a further performance gain, when you pass a numeric/polynomial value directly, but may also cause some subtle effects in cases where the type of value matters:
Code:
calminstruction demo value*
        local a, b
        match a+b, value
        jyes two
        emit 1, value
        exit
      two:
        emit 1, a
        emit 1, b
        exit
end calminstruction

calminstruction test0 expr
        local cmd
        arrange cmd, =demo expr
        assemble cmd
end calminstruction

calminstruction test1 expr
        compute value, expr
        call demo, value
end calminstruction

test0 2+3
test1 2+3 ; fails, because MATCH cannot be applied to numeric value    


The fact that CALL makes it possible for an argument to come with a non-symbolic value is the reason why in the experimental branch I added a __TEXT operator that allows CHECK command to determine whether a variable has a symbolic value.

And CALL command is also going to fail when the target instruction is not CALM itself.

In short: the use of CALL is optional, when you need your macros to work faster, and then it should be used carefully.

fabbel wrote:
. or even different from simply
Code:
calminstruction another_calm_inx
   calm_inx
end calminstruction
    
    
This is very much different, as this calls a macro defined as "calminstruction?.calm_inx", and it does it at the time of definition (when "another_calm_inx" is compiled). The CALL is done at run-time (just like ASSEMBLE).

This helped me remember another difference: with CALL the reference to target instruction is resolved at definition time. At the run-time ASSEMBLE may see and execute an instruction with the same name from a different namespace, depending on context, but compiled CALL command always refers to the same symbol, fixed at the time of definition/compilation.
Post 20 Apr 2023, 13:58
View user's profile Send private message Visit poster's website Reply with quote
fabbel



Joined: 30 Oct 2012
Posts: 84
fabbel 21 Apr 2023, 14:09
Hi, Tx for detailed explanation.

Another question though... : can CALL command be used to call a labelled calminstruction ?
what is the syntax to use then ?
Post 21 Apr 2023, 14:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 21 Apr 2023, 14:20
No, there is no such variant. It is more natural for the instructions that you call to be written specifically for that purpose.
Post 21 Apr 2023, 14:20
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.