brotorift 0.4.5 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56fe846d536851843daf4ea29ae6008d7a7ec4c56cf5042ae8a490d43b1f3090
4
- data.tar.gz: fa127162d9209be518ad43fbad966196e9a2b960ccbe0f6c607743d738766291
3
+ metadata.gz: f8dd2908d1aaf2325114a587b14657d7199a7ba5db291c58bd3d935d9671eec5
4
+ data.tar.gz: f9c6d28421e7b7fb49721df7947a2e300b81fb3446ba7e96ddfda3731434887a
5
5
  SHA512:
6
- metadata.gz: 2494c9384ced85c380a65235fe753b820c54158a024795b5f0d4604448ffdeea1a30e02ba7e736408e9580c12595003fe390151da4b6ae932b6e6ac8cf78a506
7
- data.tar.gz: 7dfec5bc7385195c1809785cd43585a788d6eb1a93767274e4760a98bdce1b06244348369b1216627585f1e585bd1f3c24233537248cf7aeea4f428d53fde78c
6
+ metadata.gz: 4cee1927befbfcdfa63c01709926be18794293a4dc602bf7b6cb97899cdfae261135eaa6d59ec3a4c3959104d5969f90cbd73850c7c89cf694b1ac45ffe05b2d
7
+ data.tar.gz: 436bad9efd9fd12c515f4148810eed58c9a7d81cc13a6d6f57b9cd400886fc798684701f8ecefcfeb8d06b2d751c71b45174adfdeefe6b695d194116d3fedccc
data/lib/ast.rb CHANGED
@@ -41,6 +41,16 @@ end
41
41
  class TopDecl < ASTNode
42
42
  end
43
43
 
44
+ class FileDecl < ASTNode
45
+ value :version, Integer
46
+ value :decls, [TopDecl]
47
+
48
+ def to_s
49
+ decls_str = decls.join "\n"
50
+ "version #{version}\n\n#{decls_str}"
51
+ end
52
+ end
53
+
44
54
  class IncludeDecl < TopDecl
45
55
  value :filename, String
46
56
 
data/lib/compiler.rb CHANGED
@@ -38,7 +38,8 @@ class Compiler
38
38
 
39
39
  def compile_ast runtime, ast
40
40
  @runtime = runtime
41
- ast.each do |decl|
41
+ @runtime.version = ast.version
42
+ ast.decls.each do |decl|
42
43
  begin
43
44
  case decl
44
45
  when IncludeDecl
@@ -42,6 +42,10 @@ end
42
42
  defmodule <%= node.namespace %>.<%= node.elixir_connection %> do
43
43
  use GenServer, restart: :temporary
44
44
 
45
+ @version <%= runtime.version %>
46
+
47
+ @sc_packet_data 128
48
+
45
49
  import <%= node.namespace %>.Enums
46
50
 
47
51
  @behaviour Brotorift.ConnectionBehaviour
@@ -64,6 +68,10 @@ defmodule <%= node.namespace %>.<%= node.elixir_connection %> do
64
68
  GenServer.cast(connection, {:<%= m.elixir_name %><%= m.elixir_params %>})
65
69
  end
66
70
  <% end %>
71
+ def version() do
72
+ @version
73
+ end
74
+
67
75
  def start_link(args) do
68
76
  GenServer.start_link(__MODULE__, args)
69
77
  end
@@ -89,7 +97,7 @@ defmodule <%= node.namespace %>.<%= node.elixir_connection %> do
89
97
  def handle_cast({:<%= m.elixir_name %><%= m.elixir_params %>}, {socket, transport, handler, state}) do
90
98
  data = <<<%= m.elixir_header_name %>::32-little>><% for p in m.members %>
91
99
  data = <%= p.type.elixir_write node, p.elixir_name %><% end %>
92
- data = <<byte_size(data)::32-little, data::binary>>
100
+ data = <<@sc_packet_data::8, byte_size(data)::32-little, data::binary>>
93
101
  transport.send(socket, data)
94
102
  {:noreply, {socket, transport, handler, state}}
95
103
  end
@@ -62,12 +62,15 @@ namespace <%= node.namespace %>
62
62
 
63
63
  public class <%= node_direction.connector_name %> : Client
64
64
  {
65
+ public const int ClientVersion = <%= runtime.version %>;
66
+
65
67
  public <%= node_direction.handler_name %> handler { get; set; }
66
68
 
67
69
  public PacketProcessPolicy policy { get; set; }
68
70
 
69
71
  public <%= node_direction.connector_name %>( <%= node_direction.handler_name %> handler, long dataHead )
70
72
  {
73
+ this.Version = ClientVersion;
71
74
  this.handler = handler;
72
75
  this.dataHead = dataHead;
73
76
  this.policy = PacketProcessPolicy.Discard;
data/lib/lexer.rb CHANGED
@@ -6,6 +6,7 @@ class Lexer < RLTK::Lexer
6
6
  rule(/\s/)
7
7
 
8
8
  # Keyword
9
+ rule(/version/) { :VERSION }
9
10
  rule(/namespace/) { :NAMESPACE }
10
11
  rule(/include/) { :INCLUDE }
11
12
  rule(/node/) { :NODE }
data/lib/parser.rb CHANGED
@@ -16,6 +16,15 @@ end
16
16
  class Parser < RLTK::Parser
17
17
  @@enum_value = 0
18
18
 
19
+ production(:file) do
20
+ clause('version_decl decl_list') { |version_number, decls| FileDecl.new self.position, version_number, decls }
21
+ clause('decl_list') { |decls| FileDecl.new self.position, 1, decls }
22
+ end
23
+
24
+ production(:version_decl) do
25
+ clause('VERSION NUMBER') { |_, version_number| version_number }
26
+ end
27
+
19
28
  list(:decl_list, :decl)
20
29
 
21
30
  production(:decl) do
data/lib/runtime.rb CHANGED
@@ -188,6 +188,7 @@ end
188
188
  class Runtime
189
189
  attr_reader :filename
190
190
  attr_reader :builtins
191
+ attr_accessor :version
191
192
  attr_reader :nodes
192
193
  attr_reader :enums
193
194
  attr_reader :structs
@@ -197,6 +198,7 @@ class Runtime
197
198
  def initialize filename
198
199
  @filename = filename
199
200
  @builtins = {}
201
+ @version = 1
200
202
  @enums = {}
201
203
  @nodes = {}
202
204
  @structs = {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brotorift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ren