relaton-un 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Un
5
+ module Wasm
6
+ class Memory
7
+ PAGE = 65_536
8
+
9
+ attr_reader :max_pages
10
+
11
+ def initialize(initial_pages:, max_pages: nil)
12
+ @pages = initial_pages
13
+ @max_pages = max_pages
14
+ @buf = String.new("\x00".b * (initial_pages * PAGE), encoding: Encoding::ASCII_8BIT)
15
+ end
16
+
17
+ def size_pages
18
+ @pages
19
+ end
20
+
21
+ def grow(delta)
22
+ new_pages = @pages + delta
23
+ return -1 if @max_pages && new_pages > @max_pages
24
+
25
+ old = @pages
26
+ @pages = new_pages
27
+ @buf << ("\x00".b * (delta * PAGE))
28
+ old
29
+ end
30
+
31
+ def read(addr, len)
32
+ bounds!(addr, len)
33
+ @buf.byteslice(addr, len)
34
+ end
35
+
36
+ def write(addr, bytes)
37
+ bytes = bytes.b
38
+ bounds!(addr, bytes.bytesize)
39
+ @buf.bytesplice(addr, bytes.bytesize, bytes)
40
+ end
41
+
42
+ def load_u8(addr)
43
+ bounds!(addr, 1)
44
+ @buf.getbyte(addr)
45
+ end
46
+
47
+ def load_i8(addr)
48
+ v = load_u8(addr)
49
+ v >= 0x80 ? v - 0x100 : v
50
+ end
51
+
52
+ def load_u16(addr)
53
+ bounds!(addr, 2)
54
+ @buf.byteslice(addr, 2).unpack1("v")
55
+ end
56
+
57
+ def load_i16(addr)
58
+ v = load_u16(addr)
59
+ v >= 0x8000 ? v - 0x10000 : v
60
+ end
61
+
62
+ def load_u32(addr)
63
+ bounds!(addr, 4)
64
+ @buf.byteslice(addr, 4).unpack1("V")
65
+ end
66
+
67
+ def load_i32(addr)
68
+ v = load_u32(addr)
69
+ v >= 0x8000_0000 ? v - 0x1_0000_0000 : v
70
+ end
71
+
72
+ def load_u64(addr)
73
+ bounds!(addr, 8)
74
+ @buf.byteslice(addr, 8).unpack1("Q<")
75
+ end
76
+
77
+ def load_i64(addr)
78
+ v = load_u64(addr)
79
+ v >= 0x8000_0000_0000_0000 ? v - 0x1_0000_0000_0000_0000 : v
80
+ end
81
+
82
+ def store_u8(addr, val)
83
+ bounds!(addr, 1)
84
+ @buf.setbyte(addr, val & 0xff)
85
+ end
86
+
87
+ def store_u16(addr, val)
88
+ bounds!(addr, 2)
89
+ @buf.bytesplice(addr, 2, [val & 0xffff].pack("v"))
90
+ end
91
+
92
+ def store_u32(addr, val)
93
+ bounds!(addr, 4)
94
+ @buf.bytesplice(addr, 4, [val & 0xffff_ffff].pack("V"))
95
+ end
96
+
97
+ def store_u64(addr, val)
98
+ bounds!(addr, 8)
99
+ @buf.bytesplice(addr, 8, [val & 0xffff_ffff_ffff_ffff].pack("Q<"))
100
+ end
101
+
102
+ private
103
+
104
+ def bounds!(addr, len)
105
+ return if addr >= 0 && addr + len <= @buf.bytesize
106
+
107
+ raise Trap, "out of bounds memory access (addr=#{addr}, len=#{len}, size=#{@buf.bytesize})"
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Un
5
+ module Wasm
6
+ FuncType = Struct.new(:params, :results)
7
+ Import = Struct.new(:mod, :field, :kind, :desc)
8
+ Export = Struct.new(:name, :kind, :index)
9
+ Global = Struct.new(:type, :mutable, :init_expr)
10
+ Element = Struct.new(:table_idx, :offset_expr, :func_indices)
11
+ Data = Struct.new(:mem_idx, :offset_expr, :bytes)
12
+ Code = Struct.new(:locals, :body)
13
+
14
+ MemoryType = Struct.new(:initial, :max)
15
+ TableType = Struct.new(:elem_type, :initial, :max)
16
+
17
+ class Module
18
+ attr_reader :types, :imports, :function_type_indices, :tables, :memories,
19
+ :globals, :exports, :elements, :code, :data, :start
20
+
21
+ def initialize
22
+ @types = []
23
+ @imports = []
24
+ @function_type_indices = []
25
+ @tables = []
26
+ @memories = []
27
+ @globals = []
28
+ @exports = []
29
+ @elements = []
30
+ @code = []
31
+ @data = []
32
+ @start = nil
33
+ end
34
+
35
+ def self.parse(bytes)
36
+ Decoder.new(bytes).decode
37
+ end
38
+
39
+ # Number of imported functions (they precede module-defined functions
40
+ # in the funcidx space).
41
+ def imported_function_count
42
+ @imports.count { |i| i.kind == :func }
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Un
5
+ module Wasm
6
+ class Trap < StandardError; end
7
+ class DecodeError < StandardError; end
8
+ class LinkError < StandardError; end
9
+ end
10
+ end
11
+ end
12
+
13
+ require_relative "wasm/memory"
14
+ require_relative "wasm/decoder"
15
+ require_relative "wasm/module"
16
+ require_relative "wasm/interpreter"
17
+ require_relative "wasm/instance"
data/relaton-un.gemspec CHANGED
@@ -36,6 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "faraday", "~> 2.7"
37
37
  spec.add_dependency "relaton-bib", "~> 2.1.0"
38
38
  spec.add_dependency "relaton-core", "~> 0.0.13"
39
- spec.add_dependency "wasmtime", "~> 41.0"
40
39
  end
41
40
  # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-un
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-04 00:00:00.000000000 Z
11
+ date: 2026-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.0.13
69
- - !ruby/object:Gem::Dependency
70
- name: wasmtime
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '41.0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '41.0'
83
69
  description: 'Relaton::Un: retrieve CC Standards for bibliographic use using the IsoBibliographicItem
84
70
  model'
85
71
  email:
@@ -101,11 +87,6 @@ files:
101
87
  - bin/console
102
88
  - bin/rspec
103
89
  - bin/setup
104
- - grammars/basicdoc.rng
105
- - grammars/biblio-standoc.rng
106
- - grammars/biblio.rng
107
- - grammars/relaton-un-compile.rng
108
- - grammars/relaton-un.rng
109
90
  - lib/relaton/un.rb
110
91
  - lib/relaton/un/bibdata.rb
111
92
  - lib/relaton/un/bibitem.rb
@@ -122,6 +103,12 @@ files:
122
103
  - lib/relaton/un/token_generator.rb
123
104
  - lib/relaton/un/util.rb
124
105
  - lib/relaton/un/version.rb
106
+ - lib/relaton/un/wasm.rb
107
+ - lib/relaton/un/wasm/decoder.rb
108
+ - lib/relaton/un/wasm/instance.rb
109
+ - lib/relaton/un/wasm/interpreter.rb
110
+ - lib/relaton/un/wasm/memory.rb
111
+ - lib/relaton/un/wasm/module.rb
125
112
  - lib/relaton/un/wasm_v_bg.wasm
126
113
  - relaton-un.gemspec
127
114
  - resp.html