diff --git a/yunq/codegen_message.py b/yunq/codegen_message.py index 9eb043d..1458486 100644 --- a/yunq/codegen_message.py +++ b/yunq/codegen_message.py @@ -5,6 +5,8 @@ HEADER_PRELUDE = """ // Generated file - DO NOT MODIFY #pragma once +#include +#include #include #include @@ -90,7 +92,7 @@ const uint64_t header_size = 24; // 4x uint32, 1x uint64 struct ExtPointer {{ uint32_t offset; uint32_t length; -}} +}}; void CheckHeader(const glcr::ByteBuffer& bytes) {{ // TODO: Check ident. @@ -113,12 +115,12 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint32_t core_size, uint32_t extension IMPL_PARSE_DEF = """ void {name}::ParseFromBytes(const glcr::ByteBuffer& bytes) {{ - CheckHeader(); + CheckHeader(bytes); """ IMPL_PARSE_DEF_CAP = """ void {name}::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) {{ - CheckHeader(); + CheckHeader(bytes); """ IMPL_PARSE_U64 = """ @@ -142,7 +144,7 @@ IMPL_SET_CAP_EMPTY = """ IMPL_PARSE_CAP = """ uint64_t {name}_ptr = bytes.At(header_size + (8 * {offset})); - set_{name}(caps.at({name}_ptr)); + set_{name}(caps.At({name}_ptr)); """ IMPL_PARSE_DEF_END = """ @@ -174,14 +176,14 @@ def _generate_message_parse_impl(message: Message) -> str: return impl IMPL_SER_DEF = """ -{name}::SerializeToBytes(glcr::ByteBuffer& bytes) {{ +void {name}::SerializeToBytes(glcr::ByteBuffer& bytes) {{ uint32_t next_extension = header_size + 8 * {num_fields}; const uint32_t core_size = next_extension; """ IMPL_SER_CAP_DEF = """ -{name}::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {{ +void {name}::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {{ uint32_t next_extension = header_size + 8 * {num_fields}; const uint32_t core_size = next_extension; @@ -200,7 +202,7 @@ IMPL_SER_STRING = """ ExtPointer {name}_ptr{{ .offset = next_extension, // FIXME: Check downcast of str length. - .length = {name}().length(), + .length = (uint32_t){name}().length(), }}; bytes.WriteStringAt(next_extension, {name}()); @@ -214,7 +216,7 @@ IMPL_SER_CAP_EMPTY = """ """ IMPL_SER_CAP = """ - caps.Write(next_cap, {name}()); + caps.WriteAt(next_cap, {name}()); bytes.WriteAt(header_size + (8 * {offset}), next_cap++); """ diff --git a/yunq/example.yunq.cpp b/yunq/example.yunq.cpp index 4b29f0c..f782b1c 100644 --- a/yunq/example.yunq.cpp +++ b/yunq/example.yunq.cpp @@ -8,7 +8,7 @@ const uint64_t header_size = 24; // 4x uint32, 1x uint64 struct ExtPointer { uint32_t offset; uint32_t length; -} +}; void CheckHeader(const glcr::ByteBuffer& bytes) { // TODO: Check ident. @@ -29,7 +29,7 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint32_t core_size, uint32_t extension } // namespace void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes) { - CheckHeader(); + CheckHeader(bytes); auto path_pointer = bytes.At(header_size + (8 * 0)); @@ -40,7 +40,7 @@ void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes) { } void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) { - CheckHeader(); + CheckHeader(bytes); auto path_pointer = bytes.At(header_size + (8 * 0)); @@ -50,7 +50,7 @@ void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr:: } -OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) { +void OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) { uint32_t next_extension = header_size + 8 * 2; const uint32_t core_size = next_extension; @@ -58,7 +58,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) { ExtPointer path_ptr{ .offset = next_extension, // FIXME: Check downcast of str length. - .length = path().length(), + .length = (uint32_t)path().length(), }; bytes.WriteStringAt(next_extension, path()); @@ -72,7 +72,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) { WriteHeader(bytes, core_size, next_extension); } -OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { +void OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { uint32_t next_extension = header_size + 8 * 2; const uint32_t core_size = next_extension; @@ -81,7 +81,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps ExtPointer path_ptr{ .offset = next_extension, // FIXME: Check downcast of str length. - .length = path().length(), + .length = (uint32_t)path().length(), }; bytes.WriteStringAt(next_extension, path()); @@ -96,7 +96,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps } void File::ParseFromBytes(const glcr::ByteBuffer& bytes) { - CheckHeader(); + CheckHeader(bytes); auto path_pointer = bytes.At(header_size + (8 * 0)); @@ -109,7 +109,7 @@ void File::ParseFromBytes(const glcr::ByteBuffer& bytes) { } void File::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) { - CheckHeader(); + CheckHeader(bytes); auto path_pointer = bytes.At(header_size + (8 * 0)); @@ -119,11 +119,11 @@ void File::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& uint64_t mem_cap_ptr = bytes.At(header_size + (8 * 2)); - set_mem_cap(caps.at(mem_cap_ptr)); + set_mem_cap(caps.At(mem_cap_ptr)); } -File::SerializeToBytes(glcr::ByteBuffer& bytes) { +void File::SerializeToBytes(glcr::ByteBuffer& bytes) { uint32_t next_extension = header_size + 8 * 3; const uint32_t core_size = next_extension; @@ -131,7 +131,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes) { ExtPointer path_ptr{ .offset = next_extension, // FIXME: Check downcast of str length. - .length = path().length(), + .length = (uint32_t)path().length(), }; bytes.WriteStringAt(next_extension, path()); @@ -147,7 +147,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes) { WriteHeader(bytes, core_size, next_extension); } -File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { +void File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { uint32_t next_extension = header_size + 8 * 3; const uint32_t core_size = next_extension; @@ -156,7 +156,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { ExtPointer path_ptr{ .offset = next_extension, // FIXME: Check downcast of str length. - .length = path().length(), + .length = (uint32_t)path().length(), }; bytes.WriteStringAt(next_extension, path()); @@ -166,7 +166,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { bytes.WriteAt(header_size + (8 * 1), attrs()); - caps.Write(next_cap, mem_cap()); + caps.WriteAt(next_cap, mem_cap()); bytes.WriteAt(header_size + (8 * 2), next_cap++); // The next extension pointer is the length of the message. diff --git a/yunq/example.yunq.h b/yunq/example.yunq.h index 3648617..86b6358 100644 --- a/yunq/example.yunq.h +++ b/yunq/example.yunq.h @@ -2,6 +2,8 @@ // Generated file - DO NOT MODIFY #pragma once +#include +#include #include #include diff --git a/yunq/parser.py b/yunq/parser.py index a11f20f..8d90af2 100644 --- a/yunq/parser.py +++ b/yunq/parser.py @@ -1,4 +1,5 @@ from enum import Enum +import sys class LexemeType(Enum): NONE = 0 diff --git a/yunq/yunq.py b/yunq/yunq.py old mode 100644 new mode 100755 index 4e07328..a74f2e7 --- a/yunq/yunq.py +++ b/yunq/yunq.py @@ -1,3 +1,4 @@ +#! /usr/bin/python import os import sys