flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg]CALM concatenate content without space

Author
Thread Post new topic Reply to topic
m_stery



Joined: 08 Nov 2024
Posts: 3
m_stery 07 Mar 2025, 21:53
Is this correct?
Code:
        
        arrange substitution.0?,output
        arrange substitution.1?,tmp
        arrange output,?=0??=1?         ;Is this a way to concatenate the contents of two variables without a space?
        transform output,substitution   ;Feature or bug?
    


Example - transform "<link>" before assemble:
Code:
calminstruction calminstruction?.pt? line&
        local   shared,internal,substitution,output,tmp
        initsym substitution,substitution
        initsym internal,internal
        initsym internal.lt,<
        initsym internal.gt,>
        match   ,line
        jyes    reset_shared
        take    shared,shared
        jno     set_shared
        arrange output,
        jump    space_lookup
    space_substitute:
        arrange line,tmp<!>line
    space_lookup:
        match   tmp?= line?,line
        jyes    space_substitute
        jump    parse_input
    parse_input:
        match   <=?>line?,line
        jyes    shared_out
        match   <!>line?,line
        jyes    copy_space_out
        match   <line?,line
        jyes    open_sub
        match   >line?,line
        jyes    close_sub
        match   tmp line?,line
        jno     finalize
    append_tmp_to_out:
        arrange substitution.0?,output
        arrange substitution.1?,tmp
        arrange output,?=0??=1?         ;Is this a way to concatenate the contents of two variables without a space?
        transform output,substitution   ;Feature or bug?
        jump    parse_input
    shared_out:
        arrange tmp,shared
        jump    append_tmp_to_out
    copy_space_out:
        arrange tmp,<!>
        jump    append_tmp_to_out
    close_sub:
        transform output
        arrange substitution.1?,output
        take    ,output
        take    output,output
        jno     error_unpaired
        arrange substitution.0?,output
        arrange output,?=0??=1?
        transform output,substitution
        jump    parse_input
    open_sub:
        arrange tmp,
        take    output,tmp
        jump    parse_input
    retain_space:
        arrange output,tmp output
    finalize:
        match   tmp<!>output?,output
        jyes    retain_space
        transform output,internal
        assemble output
        exit
    reset_shared:
        take    ,shared
        jyes    reset_shared
        exit
    set_shared:
        take    shared,line
        exit
    error_unpaired:
        stringify output
        stringify line
        err     'output:' bappend output bappend 10 bappend \
                'line:' bappend line bappend 10 bappend \
                '''<>'' not corectly paired'
end calminstruction
    
Post 07 Mar 2025, 21:53
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4162
Location: vpcmpistri
bitRAKE 08 Mar 2025, 00:13
I'd like a complete example to understand better.

If you have a problem with recognition of the whole (i.e. the assembler 'seeing' the tokens as separate) then switch to using #, imho.
Code:
calminstruction dis_play A*,B*
        local var,val
        arrange var,A#B

        arrange val,var 10,'dis_play',10
        assemble val

        stringify var
        display var
end calminstruction

dis_play dis,play    
... my tests show your method failing this small test, but it might not apply to your use case.
Post 08 Mar 2025, 00:13
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 08 Mar 2025, 08:56
fasmg, like fasm, operates on tokenized text, but while fasm is dropping all the whitespace, fasmg includes whitespace as special tokens in the stream. This allows it to recognize presence of the whitespace when needed, while fasm was unable to do so.

Normally it is not possible to have consecutive name tokens in the stream without a whitespace token in between, because these names needed to be separated somehow in the text before tokenization. But it is possible to artificially produce such sequence of tokens, a fasm1-like sequence, one might say. I believe it was first made possible when I introduced the feature of identifiers starting with "?".

It is a trick, though, and may have various side effects, like making debugging harder, because converting such token sequence back to text is going to blend the two name tokens together, as there was no whitespace token between them, but they were two separate tokens nonetheless.
Post 08 Mar 2025, 08:56
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 08 Mar 2025, 16:43
PS. I prepared a simple demonstration of the trick:
Code:
define a alpha
define b beta

tightly_packed equ ?a.?b

match tokens, tightly_packed
  display `tokens, 13,10        ; "alphabeta" (misleading, as there are still two separate tokens)
end match

match =alphabeta, tightly_packed
  display "one token?", 13,10
end match

match =alpha =beta, tightly_packed
  display "two tokens!", 13,10
end match

match =alpha= =beta, tightly_packed
  display "two tokens and whitespace", 13,10
end match    
I do not recommend it for any practical purposes. Although every time I find a trick that seems peculiar but useless, sooner or later someone builds entire framework around it. Very Happy
Post 08 Mar 2025, 16:43
View user's profile Send private message Visit poster's website Reply with quote
m_stery



Joined: 08 Nov 2024
Posts: 3
m_stery 08 Mar 2025, 20:21
Sorry, I'm using a machine translator to English ...

In calminstructions, local symbols are not visible, but I can have references and still access them. But working with them just as references is quite limiting, so I wanted a command that would replace the references with symbols directly. And that's what this command does.
Actually, it greatly simplifies the processing of a line that should only differ by replacing references with its symbol.

I know there are other ways, like having the symbols used in a different namespace, I like to play with the language CALM.

Very simple example (nested block like directive, this only computing a depth):
Code:
calminstruction example?!
        local   shared,depth
        init    depth
        initsym shared,shared
        initsym shared.level,depth              ;make a link to variable
        pt
        pt      shared
        compute depth,depth+1
end calminstruction

calminstruction end?.example?!
        pt      check   <<?>.level> gt 0        ;=> check depth > 0 (gt as comparator '>')
        jno     unexpected
        pt      compute <<?>.level>,<<?>.level>-1       ;=> compute depth,depth-1
        exit
        unexpected:
        err     'Unexpected instruction'
        pt
end calminstruction
    

Edit: Transformed lines by 'pt' in comment
Post 08 Mar 2025, 20:21
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4162
Location: vpcmpistri
bitRAKE 09 Mar 2025, 01:25
m_stery wrote:
Sorry, I'm using a machine translator to English ...

I like to play with the language CALM.
Thank you for being so candid, but there is nothing lacking in the translation nor your CALM. This is an interesting approach and I look forward to seeing more of your work. Very Happy

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 09 Mar 2025, 01:25
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.