sannybuilder / dev

Sanny Builder Bug Tracker and Roadmap development
https://sannybuilder.com
49 stars 0 forks source link

Global Constants #291

Closed MiranDMC closed 8 months ago

MiranDMC commented 1 year ago

I have some thoughts about constants. It is bit problematic that constants are valid only in code after they were declared. In bigger projects with includes it is getting very difficult as at certain point it is even impossible to manage correct include order to make sure constants can be used everywhere. I mean there are some cases where defined constants should be available globally in same way labels are:

const
  Stuff_Red = 0
  Stuff_Green = 1
  Stuff_Blue = 2
end

// arg 0 - stuff value
:FUNC_SET_STUFF  
  // DO SOMETHING WITH STUFF
cleo_return

In this example function FUNC_SET_STUFF will be available globally but depending on includes order calling cleo_call @FUNC_SET_STUFF args 1 Stuff_Blue will cause argument of function to be actually default 0, as constant Stuff_Blue will be unknown.

Modifying behaviour of existing constants might probably not be wise idea, so how about add extra keyword to declaration like global const?

x87 commented 1 year ago

Use $INCLUDE_ONCE to add the same constants in any scope and avoid compiler error on duplicate name.

the only problem is that language service does not know about INCLUDE_ONCE and you won't get constants in auto-complete. I fixed it, try this core.zip

MiranDMC commented 1 year ago

I noticed the problem with language service too.

Include_Once won't help in case of circular references, as one of two will be always included first. It leads to need of spiting code into header and source files. This makes code in example less readable as scm

x87 commented 1 year ago

Can you provide a complete project with includes so I can see it for myself?

MiranDMC commented 8 months ago

Header with constant definitions offers walk-around.