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

Support static specifier #4

Open
dennwc opened this issue Jan 10, 2021 · 2 comments
Open

Support static specifier #4

dennwc opened this issue Jan 10, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@dennwc
Copy link
Contributor

dennwc commented Jan 10, 2021

Currently static specifier is ignored, leading to incorrect code (variable is defined in the local scope, with the lifetime of a block).

This is a serious issue and it must be addressed.

@dennwc dennwc added the bug Something isn't working label Jan 10, 2021
@dennwc dennwc self-assigned this Jan 10, 2021
@TotallyGamerJet
Copy link
Contributor

static variables should be able to be implemented with closures. For example:
int fun() { static int count = 0; count++; return count; }
can be implemented as:

var fun = _Static_fun()

func _Static_fun() func() int {
	var count int
	return func() int {
		count++
		return count
	}
}

This should be easy to implement because all that must be done is move all static variables to the top and create the closure with the rest of the code.

@dennwc
Copy link
Contributor Author

dennwc commented Jul 13, 2021

Indeed, that could be a way, but closures proved to be problematic, since the expression might appear either as lhs or rhs, so you will need to return pointer there. And the code gets far less readable which I'd like to avoid as much as I can. So the plan was to allocate unique names for static, and just keep them in the global scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants