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

Context managers #33

Closed
akovari opened this issue Feb 19, 2020 · 2 comments
Closed

Context managers #33

akovari opened this issue Feb 19, 2020 · 2 comments
Assignees
Labels
syntax Syntax-related bugs or features
Milestone

Comments

@akovari
Copy link
Member

akovari commented Feb 19, 2020

Introduce a new type of with expression. This expression will allow accessing and manipulating local context variables within the expression in the body of the with expression.

Standard library module will be necessary to allow reading/writing context variables.

Syntax

with <expr1> (as <identifier>)?
<expr2>
end

Usecases

  • transaction context
  • dict/set hasher, seed

Further considerations

  • the context needs to be thread-safe and work across threads whenever necessary (such as calling async)
  • the distinction between builtin functions context and user library context (so that for example STM TX id cannot be overridden by the user code - either intentionally or by mistake)
@akovari
Copy link
Member Author

akovari commented Jun 3, 2020

@kurobako I'm thinking about something like this:

  • I add some kind of ThreadLocal<Dict> that will hold "context variables", which will be accessible anywhere inside of the with <expr2>. The key will be the <identifier> part of the with syntax, or if not provided, then the name has to be returned as the first element of a tuple from <expr>1.

  • This ThreadLocal<Dict> is set/removed in Threading.advance.

  • There will be an internal and external API to access this ThreadLocal<Dict>, probably in the Context class, so that for example STMBuiltinModule can access them, or anyone implementing functions using them, such as Dict/Set can access them (like the hasher function for instance).

akovari added a commit that referenced this issue Jun 14, 2020
#28 STM: attempt to make it work with async
akovari added a commit that referenced this issue Jun 14, 2020
#28 STM: attempt to make it work with async
akovari added a commit that referenced this issue Jun 21, 2020
akovari added a commit that referenced this issue Jun 21, 2020
@akovari
Copy link
Member Author

akovari commented Jun 21, 2020

@akovari akovari closed this as completed Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
syntax Syntax-related bugs or features
Projects
None yet
Development

No branches or pull requests

1 participant