commit 9962a1941e9557370c09c120cc685774b48071d6 Author: Ludovic 'Archivist' Lagouardette Date: Mon Oct 21 21:01:48 2019 +0200 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..163eb75 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.cr] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..145a099 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/docs/ +/lib/ +/bin/ +/.shards/ +*.dwarf +andrew diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..765f0e9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: crystal + +# Uncomment the following if you'd like Travis to run specs and check code formatting +# script: +# - crystal spec +# - crystal tool format --check diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0bfc21c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 your-name-here + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e2439a --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# andrew + +TODO: Write a description here + +## Installation + +TODO: Write installation instructions here + +## Usage + +TODO: Write usage instructions here + +## Development + +TODO: Write development instructions here + +## Contributing + +1. Fork it () +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request + +## Contributors + +- [your-name-here](https://github.com/your-github-user) - creator and maintainer diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..c2e7158 --- /dev/null +++ b/shard.yml @@ -0,0 +1,13 @@ +name: andrew +version: 0.1.0 + +authors: + - your-name-here + +targets: + andrew: + main: src/andrew.cr + +crystal: 0.30.1 + +license: MIT diff --git a/spec/andrew_spec.cr b/spec/andrew_spec.cr new file mode 100644 index 0000000..acc9680 --- /dev/null +++ b/spec/andrew_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Andrew do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100644 index 0000000..74ab028 --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/andrew" diff --git a/src/andrew.cr b/src/andrew.cr new file mode 100644 index 0000000..5f8c28c --- /dev/null +++ b/src/andrew.cr @@ -0,0 +1,118 @@ +require "ecr" +require "yaml" + + +module Andrew + VERSION = "0.1.0" + + # TODO: Put your code here +end + +class FileGenerator + YAML.mapping( + classes: Array(ClassGenerator), + includes: Array(String) + ) + + def initialize + @classes = Array(ClassGenerator).new + @includes = Array(String).new + end + + ECR.def_to_s "src/views/file.ecr" +end + +class ClassGenerator + YAML.mapping( + name: String, + bitfields: Array(BitfieldGenerator), + attributes: Array(AttributeGenerator), + repeats: Array(RepeatGenerator), + attributeafters: Array(AttributeAfterGenerator) + ) + + def initialize(@name : String) + @bitfields = Array(BitfieldGenerator).new + @attributes = Array(AttributeGenerator).new + @repeats = Array(RepeatGenerator).new + @attributeafters = Array(AttributeAfterGenerator).new + end + + def push(attr : AttributeGenerator) + attr.class_name = @name + @attributes.push(attr) + end + + def push(bitf : BitfieldGenerator) + end + + ECR.def_to_s "src/views/class.ecr" +end + +class BitfieldGenerator + YAML.mapping( + class_name: String, + name: String, + out_type: String, + start: Int32, + size: Int32 + ) + + def initialize(@name : String, @out_type : String, @start : Int32, @size : Int32) + @class_name = "no_class" + end +end + +class AttributeGenerator + YAML.mapping( + class_name: String, + name: String, + out_type: String, + start: Int32 + ) + + def initialize(@name : String, @out_type : String, @start : Int32) + @class_name = "no_class" + end + + ECR.def_to_s "src/views/attribute.ecr" +end + +class RepeatGenerator + YAML.mapping( + class_name: String, + name: String, + out_type: String, + start: Int32, + count_name: String + ) + def initialize(@name : String, @out_type : String, @start : Int32, @count_name : String) + @class_name = "no_class" + end +end + +class AttributeAfterGenerator + YAML.mapping( + class_name: String, + name: String, + out_type: String, + start: Int32, + after_name: String + ) + def initialize(@name : String, @out_type : String, @start : Int32, @after_name : String) + @class_name = "no_class" + end +end + +#v = ClassGenerator.new("record") +#v.push(AttributeGenerator.new("uuid", "std::array", 0)) +#v.push(AttributeGenerator.new("x", "bitops::regulated", 16)) +#v.push(AttributeGenerator.new("y", "bitops::regulated", 20)) +#f = FileGenerator.new +#f.classes << v +#f.includes << "" +#f.includes << "\"bitops.hpp\"" +#puts f.to_s +File.open(ARGV[0]) do |file| + puts FileGenerator.from_yaml(file).to_s +end diff --git a/src/views/attribute.ecr b/src/views/attribute.ecr new file mode 100644 index 0000000..ec263d4 --- /dev/null +++ b/src/views/attribute.ecr @@ -0,0 +1,11 @@ + <%= @out_type %> get_<%= @name %>(const <%= class_name %>& alter) { + auto ptr = (char*)&alter; + ptr+=<%= @start %>; + return *(<%= @out_type %>*)ptr; + } + + void set_<%= @name %>(<%= class_name %>& alter, const <%= @out_type %>& param) { + auto ptr = (char*)&alter; + ptr+=<%= @start %>; + *(<%= @out_type %>*)ptr = param; + } \ No newline at end of file diff --git a/src/views/class.ecr b/src/views/class.ecr new file mode 100644 index 0000000..c45b4e0 --- /dev/null +++ b/src/views/class.ecr @@ -0,0 +1,9 @@ + +class <%= @name %> { +virtual <%= @name %>() = 0; +<%- @attributes.each do |attr| -%> + +<%= attr.to_s %> + +<%- end -%> +}; diff --git a/src/views/file.ecr b/src/views/file.ecr new file mode 100644 index 0000000..4b18309 --- /dev/null +++ b/src/views/file.ecr @@ -0,0 +1,9 @@ +#pragma once +<%- @includes.each do |v| -%> +#include <%= v%> +<%- end -%> + + +<%- @classes.each do |v| -%> +<%= v.to_s %> +<%- end -%> \ No newline at end of file diff --git a/tests/record.yml b/tests/record.yml new file mode 100644 index 0000000..e1fd38b --- /dev/null +++ b/tests/record.yml @@ -0,0 +1,51 @@ +includes: + - + - "\"bitops.hpp\"" +classes: + - + name: record_identifier + attributes: + - + name: uuid + out_type: std::array + start: 0 + class_name: record_identifier + - + name: x + out_type: bitops::regulated + start: 16 + class_name: record_identifier + - + name: y + out_type: bitops::regulated + start: 20 + class_name: record_identifier + bitfields: [] + repeats: [] + attributeafters: [] + - + name: record + attributes: + - + name: record_id + out_type: std::array + start: 0 + class_name: record + - + name: timestamp + out_type: bitops::regulated + start: 24 + class_name: record + - + name: offset + out_type: bitops::regulated + start: 32 + class_name: record + - + name: flags + out_type: bitops::regulated + start: 40 + class_name: record + bitfields: [] + repeats: [] + attributeafters: [] \ No newline at end of file