flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] namespaces

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 479
Location: Marseille/France
sylware 09 Sep 2021, 18:05
I am structuring in a tree-like hierarchy my app using fasmg namespaces (in C89, I use the preprocessor).
Since a raw namespace (no symbol class instance attached to it) has not its direct children "browsable" by siblings or its children of any depth while upward walking the namespace hierarchy... I was wondering if there is a "better" way to "push" into a specific namespace external dependencies, like external labels for instance.
Post 09 Sep 2021, 18:05
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4180
Location: vpcmpistri
bitRAKE 10 Sep 2021, 15:33
This confused me for a great while (maybe still). I would write little tests to wrap my head around it. Namespace, in many ways, is not like namespace of other languages.
Code:
banana equ

namespace TacoLand

        ; change parent context
        banana. reequ 'banana0'

        ; existing local context overrides setting parent
        ; the symbol is shadowed
        define banana
        banana. reequ 'taco0'

        ; can't reach parent context once local context exists
        ; or if parent context doesn't exist (obviously)
        grape equ banana.
        define banana 'taco1'
end namespace

display 10,banana
display 10,9,TacoLand.grape
display 10,9,TacoLand.banana

; non-dot symbols search in the present namespace
PizzaLand:
        define .banana 'pizza0'
        banana reequ 'banana1'
        ; can access both non-/dot banana
        .grape equ .banana
        define .banana 'pizza1'

display 10,banana
display 10,9,PizzaLand.grape
display 10,9,PizzaLand.banana

namespace NoodleLand

        ; get parent value
broth:
        .grape equ banana. ; save real banana!

        ; change parent context
        banana. reequ 'banana2'

        define banana
        banana. reequ 'noodle0'

        grape equ broth.grape
        define banana 'noodle1'
end namespace

display 10,banana
display 10,9,NoodleLand.grape
display 10,9,NoodleLand.banana    
Namespace provides almost complete isolation. Once a symbol is defined in a namespace the parent is unreachable (so, if you need it, assign to local symbol before). The following dot isn't needed above (just there to indicate 'trying to reach parent'). If forward references are allowed then the parent also is not reachable because the symbol is defined everywhere in the namespace.

Presently, my use of namespace is to assign local symbols as needed - collapsing the hierarchy. I haven't tried maintaining a symbolic tree, yet.

I did run some tests also to transport symbols from one namespace to another using calminstruction's transform. With no success unfortunately. Is resolving the second parameter to transform possible - must it always be a literal value and not a value defined by a parameter/symbol?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Sep 2021, 15:33
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4180
Location: vpcmpistri
bitRAKE 10 Sep 2021, 16:17
Here is another perspective:
Code:
; GreatParent
name equ 'Adam'

GrandParent: ; colon names create an anchor point in the hierarchy
namespace GrandParent
        father equ name
        define name
        name reequ 'George'

        Parent:
        namespace Parent
                father equ name
                define name
                name reequ 'Michael'

                child:
                        ; must use more complex paths at depth
                        ; or unique names (linearize/flatten)
                        .great equ GrandParent.father
                        .grand equ father ; or GrandParent.name or Parent.father or GrandParent.Parent.father
                        .father equ name ; or Parent.name
                        .name equ 'Bobby'

                        display 10,.great,'->',.grand,'->',.father,'->',.name
        end namespace
end namespace    
Post 10 Sep 2021, 16:17
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 479
Location: Marseille/France
sylware 10 Sep 2021, 16:58
Actually, until a symbol of expression class is attached to a namespace, it is not possible to "browse" it depth upward from its children, and sidewise from its siblings (of the same symbol class).
symbols of [labeled] instruction class seems to allow those though.

Hope I am not too wrong there Smile

I ended explicitely "importing" the symbols of expression class in a child namespace from the namespaces of the parent/siblings.

For "global" namespaces, I do add a symbol of expression class explicitely:
Code:
myglobalnamespace = 'visible'    


for instance:
Code:
libc = 'visible'
linux = 'visible'
    


It seems to enforce strong isolation of symbols of expression class in their namespaces: more typing, but provides an explicit inventory of what is 'imported' instead of to have to read the whole code.
Code:
namespace parent

namespace sibling
    ...
end namespace ; sibling

label child.parent.symexpcls0 at parent.symexpcls0
label child.sibling.symexpcls1 at sibling.symexpcls1

namespace child
    ...
end namespace ; parent
end namespace ; child
    
Post 10 Sep 2021, 16:58
View user's profile Send private message Reply with quote
Melissa



Joined: 12 Apr 2012
Posts: 125
Melissa 18 Sep 2021, 11:57
namespaces are only needed if you work in teams, not to collide with others symbols or when you make library for same reasons
Post 18 Sep 2021, 11:57
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4180
Location: vpcmpistri
bitRAKE 18 Sep 2021, 15:39
The new features of fasmg make stuff like ...
Code:
include 'ns04.fasmg',namespace Oh_Wow
end namespace    
... possible. Where a library can be wrapped to isolate it.
(If it wasn't written initially with that intention.)
Post 18 Sep 2021, 15:39
View user's profile Send private message Visit poster's website Reply with quote
Melissa



Joined: 12 Apr 2012
Posts: 125
Melissa 18 Sep 2021, 21:11
Beautifull I bet future on fasmg.
Post 18 Sep 2021, 21:11
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.