It is currently Wed Sep 19, 2018 2:55 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Mar 04, 2018 4:09 pm 
Offline

Joined: Sun Aug 28, 2016 9:01 pm
Posts: 18
Location: Seattle
I like the built-in namespacing ca65 provides through .SCOPE/.ENDSCOPE and am hoping to use it in my project. It works fine when I put all of my code in a single file, but when I start to break the code out into separate files, I find I'm unable to make the scopes available other files via the usual mechanisms (.IMPORT, .EXPORT). Has anyone had any luck exporting/importing their scopes?


Top
 Profile  
 
PostPosted: Sun Mar 04, 2018 6:05 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6801
Location: Canada
.import and .export are for passing actual labels around (i.e. something that can be assigned a value), not scopes.

If you want to import/export something that's inside a scope:
Code:
; in exporting file
.scope scoped
   .export thing
   ; thing definied here somewhere
.endscope

; in importing file
.scope scoped
   .import thing
.endscope

Edit: replaced non-working example: .export scoped::thing

I don't think there's any kind of mechanism to import/export all symbols in a scope.

You could make a "header" file like C and use .global for all the symbols within a scope that should be public.
Edit: duplicate scope error seems to prevent the ability to use .global for scoped exports.


Last edited by rainwarrior on Sun Mar 04, 2018 7:04 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sun Mar 04, 2018 6:14 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20556
Location: NE Indiana, USA (NTSC)
rainwarrior wrote:
If you want to import/export something that's inside a scope:
Code:
.export scoped::thing


I don't think there's any kind of mechanism to import/export all symbols in a scope.

There's an open feature request for something similar to .import scoped::*.


Top
 Profile  
 
PostPosted: Sun Mar 04, 2018 6:17 pm 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 358
rainwarrior wrote:
Code:
.export scoped::thing



I've never been able to get that to work. I've resorted to doing hacks like this:

Code:
.export foo
foo = scoped::thing


Otherwise I get errors.


Top
 Profile  
 
PostPosted: Sun Mar 04, 2018 7:01 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6801
Location: Canada
Ah apologies, was going by my fallible memory. (Haven't actually done it in a while.)

You can put the .export within the .scope, and on the .import side you can do the same.

Unfortunately this seems to preclude the use of .global for this, because they assembler has a "duplicate scope" error for some reason.


Top
 Profile  
 
PostPosted: Sun Mar 04, 2018 7:17 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10806
Location: Rio de Janeiro - Brazil
Scopes in ca65 are pretty cool, but there are several gotchas that prevent them from being as useful as they initially appear to be. To avoid these problems, I currently use scopes only to delimit labels, and if any scoped labels need access from the outside, I create global aliases for them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group