Skip to content

Get owned predicates and basic preconditions working#19

Open
msaljuk wants to merge 5 commits intomainfrom
lua_owned_predicate
Open

Get owned predicates and basic preconditions working#19
msaljuk wants to merge 5 commits intomainfrom
lua_owned_predicate

Conversation

@msaljuk
Copy link
Copy Markdown
Owner

@msaljuk msaljuk commented Mar 10, 2026

This CL:

  • Adds support for Apply terms.
  • Gets owned predicates working in Lua. This required adding support for an owned function in the core lua runtime and then calling it during cn_to_ail_resource. The resulting owned resource is then added to the frame locals as well using set_local
  • Adds an entire frame_locals tracking structure in the CnL library that tracks any locals (names and types) that have been set in Lua. This is a little icky but here's why I need something like this:
    • When we take ownership of a resource in the C runtime, we call owned_x and 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 like cn.assert(Or_cn, cn_i32(0)) and it's fine
    • In Lua, there are no explicit types. All I have are variable names. BUT when I have a frame local for a ctype, I need to know what type this is so that I can call the right function to marshall the data of this variable back from C (e.g. cn.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.
  • Uses this frame_locals tracking structure to properly get and 'dereference' any frame locals back from C

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 StructMember type working in cn_to_ail_expr to allow recursive dereferencing here)

msaljuk added 3 commits March 10, 2026 00:33
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
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)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@msaljuk msaljuk force-pushed the lua_owned_predicate branch from 2908493 to fb2ef52 Compare March 10, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant