wardite 0.8.2 → 0.9.0

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.
data/lib/wardite/load.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # rbs_inline: enabled
2
- require "wardite/revisitor"
3
2
 
4
3
  module Wardite
5
4
  class Section
@@ -128,7 +127,7 @@ module Wardite
128
127
 
129
128
  attr_accessor :locals_type #: Array[Symbol]
130
129
 
131
- attr_accessor :body #: Array[Op]
130
+ attr_accessor :body #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
132
131
 
133
132
  # @rbs &blk: (CodeBody) -> void
134
133
  # @rbs return: void
@@ -603,25 +602,25 @@ module Wardite
603
602
  locals_type << Op.i2type(value_type || -1)
604
603
  end
605
604
  body = code_body(cbuf)
606
- revisitor = Revisitor.new(body)
607
- revisitor.revisit!
608
605
 
609
606
  dest.func_codes << CodeSection::CodeBody.new do |b|
610
607
  b.locals_count = locals_count
611
608
  b.locals_type = locals_type
612
- b.body = revisitor.ops
609
+ b.body = body
613
610
  end
614
611
  end
615
612
  dest
616
613
  end
617
614
 
618
615
  # @rbs buf: StringIO
619
- # @rbs return: Array[::Wardite::Op]
616
+ # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
620
617
  def self.code_body(buf)
621
- dest = [] #: Array[Op]
618
+ dest = [] #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
619
+ # HINT: [symname, index of op, index of else, index of end]
620
+ branching_stack = [] #: Array[[Symbol, Integer, Integer, Integer]]
621
+ fixed_stack = [] #: Array[[Symbol, Integer, Integer, Integer]]
622
622
  while c = buf.read(1)
623
- namespace, code = resolve_code(c, buf)
624
- operand_types = Op.operand_of(code)
623
+ namespace, code, operand_types = resolve_code(c, buf)
625
624
  operand = [] #: Array[operandItem]
626
625
  operand_types.each do |typ|
627
626
  case typ
@@ -676,9 +675,42 @@ module Wardite
676
675
  end
677
676
  end
678
677
 
679
- dest << Op.new(namespace, code, operand)
678
+ # HINT: [namespace, code, operand, else_pos, end_pos]
679
+ dest << [namespace, code, operand, nil, nil]
680
+ if code == :block || code == :loop || code == :if
681
+ branching_stack << [code, dest.size - 1, -1, -1]
682
+ elsif code == :else
683
+ if branching_stack.empty?
684
+ raise "broken sequence: unmatched else"
685
+ else
686
+ last = branching_stack.pop || raise("[BUG] empty pop")
687
+ if last[0] != :if
688
+ raise "broken sequence: else without if"
689
+ end
690
+ branching_stack << [last[0], last[1], dest.size - 1, -1]
691
+ end
692
+ elsif code == :end
693
+ unless branching_stack.empty?
694
+ last = branching_stack.pop || raise("[BUG] empty pop")
695
+ fixed_stack << [last[0], last[1], last[2], dest.size - 1]
696
+ end
697
+ end
680
698
  end
681
699
 
700
+ fixed_stack.each do |(sym, begin_idx, else_idx, end_idx)|
701
+ if end_idx == -1
702
+ raise "broken sequence: branching without end"
703
+ end
704
+ case sym
705
+ when :block, :loop
706
+ dest[begin_idx][-1] = end_idx
707
+ when :if
708
+ dest[begin_idx][-2] = else_idx == -1 ? end_idx : else_idx
709
+ dest[begin_idx][-1] = end_idx
710
+ else
711
+ raise "[BUG] unknown sym #{sym.inspect}"
712
+ end
713
+ end
682
714
  dest
683
715
  rescue => e
684
716
  require "pp"
@@ -690,14 +722,18 @@ module Wardite
690
722
 
691
723
  # @rbs c: String
692
724
  # @rbs buf: StringIO
693
- # @rbs return: [Symbol, Symbol]
725
+ # @rbs return: [Symbol, Symbol, Array[Symbol]]
694
726
  def self.resolve_code(c, buf)
695
- namespace, code = Op.to_sym(c)
696
- if namespace == :fc
727
+ ord = c.ord
728
+ code = Op::SYMS[ord]
729
+ if code == :fc
697
730
  lower = fetch_uleb128(buf)
698
- return Op.resolve_fc_sym(lower) #: [Symbol, Symbol]
731
+ sym = Op::FC_SYMS[lower]
732
+ namespace = Op::FC_OPERANDS[lower] || :default
733
+ return [namespace, sym, Op.operand_of(sym)]
699
734
  end
700
- return [namespace, code] #: [Symbol, Symbol]
735
+ namespace = Op::NAMESPACES[ord] || raise("unsupported code: #{ord}")
736
+ return [namespace, code, Op::OPERANDS[ord]]
701
737
  end
702
738
 
703
739
  # @rbs return: DataSection
@@ -774,7 +810,7 @@ module Wardite
774
810
  code
775
811
  end
776
812
 
777
- # @rbs ops: Array[Op]
813
+ # @rbs ops: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
778
814
  # @rbs return: Integer
779
815
  def self.decode_expr(ops)
780
816
  # sees first opcode
@@ -782,19 +818,19 @@ module Wardite
782
818
  if !op
783
819
  raise LoadError, "empty opcodes"
784
820
  end
785
- case op.code
821
+ case op[1]
786
822
  when :i32_const
787
- arg = op.operand[0]
823
+ arg = op[2][0]
788
824
  if !arg.is_a?(Integer)
789
825
  raise "Invalid definition of operand"
790
826
  end
791
827
  return arg
792
828
  else
793
- raise "Unimplemented offset op: #{op.code.inspect}"
829
+ raise "Unimplemented offset op: #{op.inspect}"
794
830
  end
795
831
  end
796
832
 
797
- # @rbs ops: Array[Op]
833
+ # @rbs ops: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
798
834
  # @rbs return: wasmValue
799
835
  def self.decode_global_expr(ops)
800
836
  # sees first opcode
@@ -802,33 +838,33 @@ module Wardite
802
838
  if !op
803
839
  raise LoadError, "empty opcodes"
804
840
  end
805
- case op.code
841
+ case op[1]
806
842
  when :i32_const
807
- arg = op.operand[0]
843
+ arg = op[2][0]
808
844
  if !arg.is_a?(Integer)
809
845
  raise "Invalid definition of operand"
810
846
  end
811
847
  return I32(arg)
812
848
  when :i64_const
813
- arg = op.operand[0]
849
+ arg = op[2][0]
814
850
  if !arg.is_a?(Integer)
815
851
  raise "Invalid definition of operand"
816
852
  end
817
853
  return I64(arg)
818
854
  when :f32_const
819
- arg = op.operand[0]
855
+ arg = op[2][0]
820
856
  if !arg.is_a?(Float)
821
857
  raise "Invalid definition of operand"
822
858
  end
823
859
  return F32(arg)
824
860
  when :f64_const
825
- arg = op.operand[0]
861
+ arg = op[2][0]
826
862
  if !arg.is_a?(Float)
827
863
  raise "Invalid definition of operand"
828
864
  end
829
865
  return F64(arg)
830
866
  else
831
- raise "Unimplemented offset op: #{op.code.inspect}"
867
+ raise "Unimplemented offset op: #{op.inspect}"
832
868
  end
833
869
  end
834
870
 
@@ -15,17 +15,25 @@ module Wardite
15
15
  case op.code
16
16
  when :block
17
17
  next_pc = fetch_ops_while_end(idx)
18
- op.meta[:end_pos] = next_pc
18
+ if op.meta[:end_pos] != next_pc
19
+ raise "mismatched end_pos for block at #{op}: #{op.meta[:end_pos]} vs #{next_pc}"
20
+ end
19
21
 
20
22
  when :loop
21
23
  next_pc = fetch_ops_while_end(idx)
22
- op.meta[:end_pos] = next_pc
24
+ if op.meta[:end_pos] != next_pc
25
+ raise "mismatched end_pos for loop at #{op}: #{op.meta[:end_pos]} vs #{next_pc}"
26
+ end
23
27
 
24
28
  when :if
25
29
  next_pc = fetch_ops_while_end(idx)
26
30
  else_pc = fetch_ops_while_else_or_end(idx)
27
- op.meta[:end_pos] = next_pc
28
- op.meta[:else_pos] = else_pc
31
+ if op.meta[:end_pos] != next_pc
32
+ raise "mismatched end_pos for if at #{op}: #{op.meta[:end_pos]} vs #{next_pc}"
33
+ end
34
+ if op.meta[:else_pos] != else_pc
35
+ raise "mismatched else_pos for if at #{op}: #{op.meta[:else_pos]} vs #{else_pc}"
36
+ end
29
37
  end
30
38
  end
31
39
  end
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Wardite
5
- VERSION = "0.8.2" #: String
5
+ VERSION = "0.9.0" #: String
6
6
  end
data/lib/wardite.rb CHANGED
@@ -425,7 +425,7 @@ module Wardite
425
425
  break
426
426
  end
427
427
  cur_frame.pc += 1
428
- insn = cur_frame.body[cur_frame.pc] #: Op
428
+ insn = cur_frame.body[cur_frame.pc]
429
429
  if !insn
430
430
  break
431
431
  end
@@ -434,37 +434,38 @@ module Wardite
434
434
  end
435
435
 
436
436
  # @rbs frame: Frame
437
- # @rbs insn: Op
437
+ # @rbs insn: [Symbol, Symbol, Array[operandItem], Integer?, Integer?]
438
438
  # @rbs return: void
439
439
  def eval_insn(frame, insn)
440
- case insn.namespace
440
+ namespace, code, operand, else_pos, end_pos = *insn
441
+ case namespace
441
442
  when :convert
442
- return Evaluator.convert_eval_insn(self, frame, insn)
443
+ return Evaluator.convert_eval_insn(self, frame, code, operand)
443
444
  when :i32
444
- return Evaluator.i32_eval_insn(self, frame, insn)
445
+ return Evaluator.i32_eval_insn(self, frame, code, operand)
445
446
  when :i64
446
- return Evaluator.i64_eval_insn(self, frame, insn)
447
+ return Evaluator.i64_eval_insn(self, frame, code, operand)
447
448
  when :f32
448
- return Evaluator.f32_eval_insn(self, frame, insn)
449
+ return Evaluator.f32_eval_insn(self, frame, code, operand)
449
450
  when :f64
450
- return Evaluator.f64_eval_insn(self, frame, insn)
451
+ return Evaluator.f64_eval_insn(self, frame, code, operand)
451
452
  end
452
453
 
453
454
  # unmached namespace...
454
- case insn.code
455
+ case code
455
456
  when :unreachable
456
457
  raise Unreachable, "unreachable op"
457
458
  when :nop
458
459
  return
459
460
 
460
461
  when :br
461
- level = insn.operand[0]
462
+ level = operand[0]
462
463
  raise EvalError, "br op without level" if !level.is_a?(Integer)
463
464
  pc = do_branch(frame.labels, stack, level)
464
465
  frame.pc = pc
465
466
 
466
467
  when :br_if
467
- level = insn.operand[0]
468
+ level = operand[0]
468
469
  raise EvalError, "br op without level" if !level.is_a?(Integer)
469
470
  cond = stack.pop
470
471
  raise EvalError, "cond not found" if !cond.is_a?(I32)
@@ -475,9 +476,9 @@ module Wardite
475
476
  frame.pc = pc
476
477
 
477
478
  when :br_table
478
- level_vec = insn.operand[0]
479
+ level_vec = operand[0]
479
480
  raise EvalError, "no level vector" if !level_vec.is_a?(Array)
480
- default = insn.operand[1]
481
+ default = operand[1]
481
482
  raise EvalError, "no default specified" if !default.is_a?(Integer)
482
483
  idx = stack.pop
483
484
  raise EvalError, "idx not found" if !idx.is_a?(I32)
@@ -490,29 +491,29 @@ module Wardite
490
491
  frame.pc = pc
491
492
 
492
493
  when :block
493
- block = insn.operand[0]
494
+ block = operand[0]
494
495
  raise EvalError, "block op without block" if !block.is_a?(Block)
495
- next_pc = insn.meta[:end_pos]
496
+ next_pc = end_pos || -1
496
497
  label = Label.new(:block, next_pc, stack.size, block.result_size)
497
498
  frame.labels.push(label)
498
499
 
499
500
  when :loop
500
- block = insn.operand[0]
501
+ block = operand[0]
501
502
  raise EvalError, "loop op without block" if !block.is_a?(Block)
502
503
  start = frame.pc
503
- next_pc = insn.meta[:end_pos]
504
+ next_pc = end_pos || -1
504
505
  label = Label.new(:loop, next_pc, stack.size, block.result_size, start)
505
506
  frame.labels.push(label)
506
507
 
507
508
  when :if
508
- block = insn.operand[0]
509
+ block = operand[0]
509
510
  raise EvalError, "if op without block" if !block.is_a?(Block)
510
511
  cond = stack.pop
511
512
  raise EvalError, "cond not found" if !cond.is_a?(I32)
512
- next_pc = insn.meta[:end_pos]
513
+ next_pc = end_pos || -1
513
514
 
514
515
  if cond.value.zero?
515
- frame.pc = insn.meta[:else_pos]
516
+ frame.pc = else_pos || -1
516
517
  end
517
518
 
518
519
  if frame.pc == next_pc
@@ -532,7 +533,7 @@ module Wardite
532
533
  end
533
534
 
534
535
  when :call
535
- idx = insn.operand[0]
536
+ idx = operand[0]
536
537
  raise EvalError, "[BUG] local operand not found" if !idx.is_a?(Integer)
537
538
  fn = self.instance.store.funcs[idx]
538
539
  case fn
@@ -548,9 +549,9 @@ module Wardite
548
549
  when :call_indirect
549
550
  table = self.instance.store.tables[0]
550
551
  raise EvalError, "table required but not found" if !table
551
- type_idx = insn.operand[0]
552
+ type_idx = operand[0]
552
553
  raise EvalError, "[BUG] index operand invalid" if !type_idx.is_a?(Integer)
553
- nullbyte = insn.operand[1]
554
+ nullbyte = operand[1]
554
555
  raise EvalError, "[BUG] invalid bytearray of call_indirect" if nullbyte != 0x0
555
556
  table_idx = stack.pop
556
557
  raise EvalError, "[BUG] index stack invalid" if !table_idx.is_a?(I32)
@@ -618,7 +619,7 @@ module Wardite
618
619
  stack.push(cond.value != 0 ? left : right)
619
620
 
620
621
  when :local_get
621
- idx = insn.operand[0]
622
+ idx = operand[0]
622
623
  if !idx.is_a?(Integer)
623
624
  raise EvalError, "[BUG] invalid type of operand"
624
625
  end
@@ -630,7 +631,7 @@ module Wardite
630
631
  stack.push(local)
631
632
 
632
633
  when :local_set
633
- idx = insn.operand[0]
634
+ idx = operand[0]
634
635
  if !idx.is_a?(Integer)
635
636
  raise EvalError, "[BUG] invalid type of operand"
636
637
  end
@@ -641,7 +642,7 @@ module Wardite
641
642
  frame.locals[idx] = value
642
643
 
643
644
  when :local_tee
644
- idx = insn.operand[0]
645
+ idx = operand[0]
645
646
  if !idx.is_a?(Integer)
646
647
  raise EvalError, "[BUG] invalid type of operand"
647
648
  end
@@ -653,7 +654,7 @@ module Wardite
653
654
  stack.push value
654
655
 
655
656
  when :global_get
656
- idx = insn.operand[0]
657
+ idx = operand[0]
657
658
  if !idx.is_a?(Integer)
658
659
  raise EvalError, "[BUG] invalid type of operand"
659
660
  end
@@ -664,7 +665,7 @@ module Wardite
664
665
  stack.push(global.value)
665
666
 
666
667
  when :global_set
667
- idx = insn.operand[0]
668
+ idx = operand[0]
668
669
  if !idx.is_a?(Integer)
669
670
  raise EvalError, "[BUG] invalid type of operand"
670
671
  end
@@ -695,11 +696,11 @@ module Wardite
695
696
  stack.push(I32(memory.grow(delta.value)))
696
697
 
697
698
  when :memory_init
698
- idx = insn.operand[0]
699
+ idx = operand[0]
699
700
  if !idx.is_a?(Integer)
700
701
  raise EvalError, "[BUG] invalid type of operand"
701
702
  end
702
- if insn.operand[1] != 0x0
703
+ if operand[1] != 0x0
703
704
  $stderr.puts "warning: :memory_init is not ending with 0x00"
704
705
  end
705
706
  data_sec = instance.data_section
@@ -721,7 +722,7 @@ module Wardite
721
722
  memory.data[dest_offset.value...(dest_offset.value+length.value)] = source
722
723
 
723
724
  when :memory_copy
724
- if insn.operand[0] != 0x0 || insn.operand[1] != 0x0
725
+ if operand[0] != 0x0 || operand[1] != 0x0
725
726
  $stderr.puts "warning: :memory_copy is not ending with 0x00"
726
727
  end
727
728
  length, src_offset, dest_offset = stack.pop, stack.pop, stack.pop
@@ -734,7 +735,7 @@ module Wardite
734
735
  memory.data[dest_offset.value...(dest_offset.value+length.value)] = source
735
736
 
736
737
  when :memory_fill
737
- if insn.operand[0] != 0x0
738
+ if operand[0] != 0x0
738
739
  $stderr.puts "warning: :memory_fill is not ending with 0x00"
739
740
  end
740
741
  length, byte, dest_offset = stack.pop, stack.pop, stack.pop
@@ -857,7 +858,7 @@ module Wardite
857
858
  attr_accessor :pc #: Integer
858
859
  attr_accessor :sp #: Integer
859
860
 
860
- attr_accessor :body #: Array[Op]
861
+ attr_accessor :body #: Array[[Symbol, Symbol, Array[Wardite::operandItem], Integer?, Integer?]]
861
862
 
862
863
  attr_accessor :arity #: Integer
863
864
 
@@ -869,7 +870,7 @@ module Wardite
869
870
 
870
871
  # @rbs pc: Integer
871
872
  # @rbs sp: Integer
872
- # @rbs body: Array[Op]
873
+ # @rbs body: Array[[Symbol, Symbol, Array[Wardite::operandItem], Integer?, Integer?]]
873
874
  # @rbs arity: Integer
874
875
  # @rbs locals: Array[wasmValue]
875
876
  # @rbs returb: void
@@ -1263,7 +1264,7 @@ module Wardite
1263
1264
  @default_locals = construct_default_locals
1264
1265
  end
1265
1266
 
1266
- # @rbs return: Array[Op]
1267
+ # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
1267
1268
  def body
1268
1269
  code_body.body
1269
1270
  end
@@ -1271,7 +1272,7 @@ module Wardite
1271
1272
  # @rbs return: Array[Symbol]
1272
1273
  def locals_type
1273
1274
  code_body.locals_type
1274
- end
1275
+ end
1275
1276
 
1276
1277
  # @rbs return: Array[Integer]
1277
1278
  def locals_count
data/scripts/gen_alu.rb CHANGED
@@ -49,8 +49,8 @@ module GenAlu
49
49
  DEFS = { #: Hash[Symbol, String]
50
50
  load: <<~RUBY,
51
51
  when :${PREFIX}_load
52
- _align = insn.operand[0] # TODO: alignment support?
53
- offset = insn.operand[1]
52
+ _align = operand[0] # TODO: alignment support?
53
+ offset = operand[1]
54
54
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
55
55
 
56
56
  addr = runtime.stack.pop
@@ -70,8 +70,8 @@ module GenAlu
70
70
 
71
71
  load8_s: <<~RUBY,
72
72
  when :${PREFIX}_load8_s
73
- _align = insn.operand[0] # TODO: alignment support?
74
- offset = insn.operand[1]
73
+ _align = operand[0] # TODO: alignment support?
74
+ offset = operand[1]
75
75
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
76
76
 
77
77
  addr = runtime.stack.pop
@@ -91,8 +91,8 @@ module GenAlu
91
91
 
92
92
  load8_u: <<~RUBY,
93
93
  when :${PREFIX}_load8_u
94
- _align = insn.operand[0] # TODO: alignment support?
95
- offset = insn.operand[1]
94
+ _align = operand[0] # TODO: alignment support?
95
+ offset = operand[1]
96
96
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
97
97
 
98
98
  addr = runtime.stack.pop
@@ -112,8 +112,8 @@ module GenAlu
112
112
 
113
113
  load16_s: <<~RUBY,
114
114
  when :${PREFIX}_load16_s
115
- _align = insn.operand[0] # TODO: alignment support?
116
- offset = insn.operand[1]
115
+ _align = operand[0] # TODO: alignment support?
116
+ offset = operand[1]
117
117
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
118
118
 
119
119
  addr = runtime.stack.pop
@@ -133,8 +133,8 @@ module GenAlu
133
133
 
134
134
  load16_u: <<~RUBY,
135
135
  when :${PREFIX}_load16_u
136
- _align = insn.operand[0] # TODO: alignment support?
137
- offset = insn.operand[1]
136
+ _align = operand[0] # TODO: alignment support?
137
+ offset = operand[1]
138
138
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
139
139
 
140
140
  addr = runtime.stack.pop
@@ -154,8 +154,8 @@ module GenAlu
154
154
 
155
155
  load32_s: <<~RUBY,
156
156
  when :${PREFIX}_load32_s
157
- _align = insn.operand[0] # TODO: alignment support?
158
- offset = insn.operand[1]
157
+ _align = operand[0] # TODO: alignment support?
158
+ offset = operand[1]
159
159
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
160
160
 
161
161
  addr = runtime.stack.pop
@@ -175,8 +175,8 @@ module GenAlu
175
175
 
176
176
  load32_u: <<~RUBY,
177
177
  when :${PREFIX}_load32_u
178
- _align = insn.operand[0] # TODO: alignment support?
179
- offset = insn.operand[1]
178
+ _align = operand[0] # TODO: alignment support?
179
+ offset = operand[1]
180
180
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
181
181
 
182
182
  addr = runtime.stack.pop
@@ -196,8 +196,8 @@ module GenAlu
196
196
 
197
197
  store: <<~RUBY,
198
198
  when :${PREFIX}_store
199
- _align = insn.operand[0] # TODO: alignment support?
200
- offset = insn.operand[1]
199
+ _align = operand[0] # TODO: alignment support?
200
+ offset = operand[1]
201
201
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
202
202
 
203
203
  value = runtime.stack.pop
@@ -214,8 +214,8 @@ module GenAlu
214
214
 
215
215
  store8: <<~RUBY,
216
216
  when :${PREFIX}_store8
217
- _align = insn.operand[0] # TODO: alignment support?
218
- offset = insn.operand[1]
217
+ _align = operand[0] # TODO: alignment support?
218
+ offset = operand[1]
219
219
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
220
220
 
221
221
  value = runtime.stack.pop
@@ -232,8 +232,8 @@ module GenAlu
232
232
 
233
233
  store16: <<~RUBY,
234
234
  when :${PREFIX}_store16
235
- _align = insn.operand[0] # TODO: alignment support?
236
- offset = insn.operand[1]
235
+ _align = operand[0] # TODO: alignment support?
236
+ offset = operand[1]
237
237
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
238
238
 
239
239
  value = runtime.stack.pop
@@ -250,8 +250,8 @@ module GenAlu
250
250
 
251
251
  store32: <<~RUBY,
252
252
  when :${PREFIX}_store32
253
- _align = insn.operand[0] # TODO: alignment support?
254
- offset = insn.operand[1]
253
+ _align = operand[0] # TODO: alignment support?
254
+ offset = operand[1]
255
255
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
256
256
 
257
257
  value = runtime.stack.pop
@@ -268,7 +268,7 @@ module GenAlu
268
268
 
269
269
  const: <<~RUBY,
270
270
  when :${PREFIX}_const
271
- const = insn.operand[0]
271
+ const = operand[0]
272
272
  if !const.is_a?(Integer)
273
273
  raise EvalError, "invalid type of operand"
274
274
  end
@@ -277,7 +277,7 @@ module GenAlu
277
277
 
278
278
  const__f: <<~RUBY,
279
279
  when :${PREFIX}_const
280
- const = insn.operand[0]
280
+ const = operand[0]
281
281
  if !const.is_a?(Float)
282
282
  raise EvalError, "invalid type of operand"
283
283
  end
@@ -5,14 +5,16 @@ module Wardite
5
5
  module Evaluator
6
6
  # @rbs runtime: Runtime
7
7
  # @rbs frame: Frame
8
- # @rbs insn: Op
9
- # @rbs return: void
10
- def self.${PREFIX}_eval_insn(runtime, frame, insn)
11
- case insn.code
8
+ # @rbs code: Symbol
9
+ # @rbs operand: Array[operandItem]
10
+ # @rbs return: bool?
11
+ def self.${PREFIX}_eval_insn(runtime, frame, code, operand)
12
+ case code
12
13
  ${DEFS}
13
14
  else
14
- raise "Unknown opcode for namespace #{insn.namespace}: #{insn.code}"
15
+ return
15
16
  end
17
+ return true
16
18
  end
17
19
  end
18
20
  end
@@ -5,14 +5,16 @@ module Wardite
5
5
  module Evaluator
6
6
  # @rbs runtime: Runtime
7
7
  # @rbs frame: Frame
8
- # @rbs insn: Op
9
- # @rbs return: void
10
- def self.convert_eval_insn(runtime, frame, insn)
11
- case insn.code
8
+ # @rbs code: Symbol
9
+ # @rbs operand: Array[operandItem]
10
+ # @rbs return: bool?
11
+ def self.convert_eval_insn(runtime, frame, code, operand)
12
+ case code
12
13
  ${DEFS}
13
14
  else
14
- raise "Unknown opcode for namespace #{insn.namespace}: #{insn.code}"
15
+ return
15
16
  end
17
+ return true
16
18
  end
17
19
  end
18
20
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.f32_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.f32_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.f64_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.f64_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.i32_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.i32_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end