|
| 1 | +```k |
| 2 | +
|
| 3 | +module MX-RUST-MODULES-MULTI-VALUE-ENCODED |
| 4 | + imports private MX-RUST-REPRESENTATION |
| 5 | + imports private RUST-SHARED-SYNTAX |
| 6 | +
|
| 7 | + syntax MxRustInstruction ::= toVec(Expression) [strict] |
| 8 | +
|
| 9 | + rule |
| 10 | + normalizedMethodCall |
| 11 | + ( #token("MultiValueEncoded", "Identifier"):Identifier |
| 12 | + , #token("to_vec", "Identifier"):Identifier |
| 13 | + , ( ptr(SelfId) , .PtrList) |
| 14 | + ) |
| 15 | + => toVec(ptr(SelfId)) |
| 16 | +
|
| 17 | + rule toVec |
| 18 | + ( ptrValue |
| 19 | + ( _ |
| 20 | + , struct |
| 21 | + ( _ |
| 22 | + , ( #token("mx_buffer_id", "Identifier"):Identifier |-> _ |
| 23 | + #token("value_type", "Identifier"):Identifier |-> _ |
| 24 | + .Map |
| 25 | + ) #as M:Map |
| 26 | + ) |
| 27 | + ) |
| 28 | + ) |
| 29 | + => ptrValue(null, struct(#token("ManagedVec", "Identifier"):Identifier , M)) |
| 30 | +
|
| 31 | + // -------------------------------------- |
| 32 | +
|
| 33 | + syntax MxRustType ::= "multiValueEncodedType" [function, total] |
| 34 | + rule multiValueEncodedType |
| 35 | + => rustStructType |
| 36 | + ( #token("MultiValueEncoded", "Identifier"):Identifier |
| 37 | + , ( mxRustStructField |
| 38 | + ( #token("mx_buffer_id", "Identifier"):Identifier |
| 39 | + , MxRust#buffer |
| 40 | + ) |
| 41 | + , mxRustStructField |
| 42 | + ( #token("value_type", "Identifier"):Identifier |
| 43 | + , MxRust#Type |
| 44 | + ) |
| 45 | + , .MxRustStructFields |
| 46 | + ) |
| 47 | + ) |
| 48 | +
|
| 49 | + rule mxValueToRust |
| 50 | + ( #token("MultiValueEncoded", "Identifier") < ValueType:Type , .GenericArgList > |
| 51 | + , V:MxValue |
| 52 | + ) |
| 53 | + => mxToRustTyped(multiValueEncodedType, mxListValue(V , mxRustType(ValueType) , .MxValueList)) |
| 54 | +
|
| 55 | + rule rustValueToMx |
| 56 | + ( struct |
| 57 | + ( #token("MultiValueEncoded", "Identifier"):Identifier |
| 58 | + , #token("mx_buffer_id", "Identifier"):Identifier |-> VecValueId:Int |
| 59 | + #token("value_type", "Identifier"):Identifier |-> _:Int |
| 60 | + .Map |
| 61 | + ) |
| 62 | + ) |
| 63 | + => mxRustGetBuffer(ptr(VecValueId)) |
| 64 | +
|
| 65 | + syntax MxRustInstruction ::= mxRustGetBuffer(Expression) [strict] |
| 66 | + rule mxRustGetBuffer(ptrValue(_, i32(BufferId:MInt{32}))) |
| 67 | + => mxGetBuffer(MInt2Unsigned(BufferId)) |
| 68 | +
|
| 69 | + // -------------------------------------- |
| 70 | +
|
| 71 | +endmodule |
| 72 | +
|
| 73 | +``` |
0 commit comments