Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global variables in JBallerina #13870

Closed
Kishanthan opened this issue Feb 25, 2019 · 1 comment
Closed

Global variables in JBallerina #13870

Kishanthan opened this issue Feb 25, 2019 · 1 comment
Assignees
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/NewFeature

Comments

@Kishanthan
Copy link
Contributor

Global variables are visible across the module that they are defined and also visible to external modules, if they are defined as public variables/constants. The concern with global variables is that they can be defined in one bal file, but can be accessed from any other bal files within that module without knowing which bal file it is defined. But when we are mapping this at JVM level, the classes need to know the class that the global variable/constants are defined.

Design considerations

  • We can separate the global variable definition and initialization part.
  • The definition of the global variables can be in the same class file as with bal file mapping.
  • The initialization (assigning values) can be in a common class file per module. This class will have a method which contain all the global variable initialization for that module. This is similar to the package functions at ballerina level.
  • Similarly, the same approach can be followed for imported modules, where, for each module, we will be generating a java package and the global variable initialization can be in a common class file per each module.
  • The ordering of invocation of this variable initialization classes will be based on the same order that the BIR produces.
    • This ordering will produce the correct initialized values for the global variables.
    • Need to check on how to get line number info for global variable that have function invocations.
  • This initialization class should be invoked using a startup routine (crt0) when the jar file is being executed.
  • The important point to note that, there should a mapping generated for global variables names against the class names in which those variables are defined. This mapping will be used when compiling the user code which has references to these variables.
@Kishanthan Kishanthan self-assigned this Feb 25, 2019
@anupama-pathirage anupama-pathirage added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Apr 30, 2019
@SupunS
Copy link
Contributor

SupunS commented May 6, 2019

Closing the issue since the global variables are now supported.

@SupunS SupunS closed this as completed May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/NewFeature
Projects
None yet
Development

No branches or pull requests

3 participants