Get owned predicates and basic preconditions working#19
Open
Get owned predicates and basic preconditions working#19
Conversation
This commit: - Adds an option to wrap any symbols with a 'cn.frames.get_local' if they're a frame local - Adds support for tracking all locals that have been currently set in lua (a little gross but need this to do lua work) - Adds support for dereferencing any pointer type frame locals
msaljuk
commented
Mar 10, 2026
| cn.frames.set_local("Or", cn.owned(cn.frames.get_local("random"), cn.spec_mode.PRE, 0)) | ||
| cn.error_stack.pop() | ||
| cn.error_stack.push(" *random == 0i32;\n ^~~~~~~~~~~~~~~~ ./lua_gen_output/basic_owned_example.c:5:3-19") | ||
| cn.assert(cn.equals(cn.c.get_integer(cn.frames.get_local("Or")), 0), cn.spec_mode.PRE) |
Owner
Author
There was a problem hiding this comment.
For struct members, this might start to get considerably nesty/convoluted. I'll work on getting them working first but given time, I might try to break this up into multiple lines using local variables
2908493 to
fb2ef52
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This CL:
Applyterms.ownedpredicates working in Lua. This required adding support for anownedfunction in the core lua runtime and then calling it duringcn_to_ail_resource. The resulting owned resource is then added to the frame locals as well usingset_localowned_xand create a stack typed variable with a name (e.g.struct_s_cn* s = owned_struct_s(origin);). In later CN statement translation, we don't have access to the full type (i.e. if it's a pointer, a pointer to what type) of our owned resource (see cn_to_ail_resource as an example). But that's okay, because the stack variable knows what type it is, and so we can spit out statements likecn.assert(Or_cn, cn_i32(0))and it's finecn.c.get_integer,cn.c.get_pointer,cn.c.peek_int_list). Therefore, I need to retain this info somewhere so that I can leverage it when I come upon later statements for frame locals to interpret them properly.See the last commit for a basic working example of an owned precondition (the parameter is an integer pointer type, but this works for structs too. I just need to get the
StructMembertype working incn_to_ail_exprto allow recursive dereferencing here)