diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-24 22:33:22 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-24 22:33:22 -0300 |
| commit | e8c8ba1ffd920aedaf24449322e8aaab9300aaec (patch) | |
| tree | a23a4e6592956e19d6a755deef633e5b5b550813 /subsystem | |
| parent | 4994bc0aacf08cf69bfaa3e31bd6767050f55efd (diff) | |
| download | RNT-e8c8ba1ffd920aedaf24449322e8aaab9300aaec.tar.gz RNT-e8c8ba1ffd920aedaf24449322e8aaab9300aaec.zip | |
abstract translator so the program term uses the same shape as tuple
Diffstat (limited to 'subsystem')
| -rw-r--r-- | subsystem/karuta/Translator.ml | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/subsystem/karuta/Translator.ml b/subsystem/karuta/Translator.ml index 0d7e7b7..5dec2e7 100644 --- a/subsystem/karuta/Translator.ml +++ b/subsystem/karuta/Translator.ml @@ -40,7 +40,7 @@ let encode {Concepts.Tuple.type_; attributes} = exception Malformed -let decode bytes = +let read arity bytes = let position = ref 0 in let take n = if !position + n > String.length bytes then raise Malformed; @@ -91,13 +91,17 @@ let decode bytes = match expect 131; expect 104; - expect 2; - expect 109; - let type_ = binary () in + expect arity; + let names = List.init (arity - 1) (fun _ -> expect 109; binary ()) in expect 116; let attributes = attributes (u32 ()) BatMap.String.empty in if !position <> String.length bytes then raise Malformed; - {Concepts.Tuple.type_; attributes} + names, attributes with - | tuple -> Ok tuple - | exception Malformed -> Error (Error.malformed ()) + | read -> Some read + | exception Malformed -> None + +let decode bytes = + match read 2 bytes with + | Some ([type_], attributes) -> Ok {Concepts.Tuple.type_; attributes} + | _ -> Error (Error.malformed ()) |
