Skip to content

Commit

Permalink
Remove comments, fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
udzura committed Nov 2, 2024
1 parent 0ce2895 commit c975bc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 56 deletions.
55 changes: 2 additions & 53 deletions lib/wardite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ class Runtime
include ValueHelper

# TODO: add types of class that the stack accomodates
attr_accessor :stack #: Array[I32|I64|F32|F64|Block]
attr_accessor :stack #: Array[I32|I64|F32|F64]

attr_accessor :call_stack #: Array[Frame]

Expand Down Expand Up @@ -886,59 +886,8 @@ def eval_insn(frame, insn)
if !value
raise EvalError, "value should be pushed"
end
if value.is_a?(Block)
raise EvalError, "block value detected"
end
frame.locals[idx] = value

# when :i32_lts
# right, left = stack.pop, stack.pop
# if !right.is_a?(Integer) || !left.is_a?(Integer)
# raise EvalError, "maybe empty stack"
# end
# value = (left < right) ? 1 : 0
# stack.push(value)
# when :i32_leu
# right, left = stack.pop, stack.pop
# if !right.is_a?(Integer) || !left.is_a?(Integer)
# raise EvalError, "maybe empty stack"
# end
# value = (left >= right) ? 1 : 0
# stack.push(value)
# when :i32_add
# right, left = stack.pop, stack.pop
# if !right.is_a?(Integer) || !left.is_a?(Integer)
# raise EvalError, "maybe empty stack"
# end
# stack.push(left + right)
# when :i32_sub
# right, left = stack.pop, stack.pop
# if !right.is_a?(Integer) || !left.is_a?(Integer)
# raise EvalError, "maybe empty stack"
# end
# stack.push(left - right)
# when :i32_const
# const = insn.operand[0]
# if !const.is_a?(Integer)
# raise EvalError, "[BUG] invalid type of operand"
# end
# stack.push(const)
# when :i32_store
# _align = insn.operand[0] # TODO: alignment support?
# offset = insn.operand[1]
# raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)

# value = stack.pop
# addr = stack.pop
# if !value.is_a?(Integer) || !addr.is_a?(Integer)
# raise EvalError, "maybe stack too short"
# end

# at = addr + offset
# data_end = at + 4 # sizeof(i32)
# memory = self.instance.store.memories[0] || raise("[BUG] no memory")
# memory.data[at...data_end] = [value].pack("I")

when :call
idx = insn.operand[0]
raise EvalError, "[BUG] local operand not found" if !idx.is_a?(Integer)
Expand Down Expand Up @@ -1023,7 +972,7 @@ def stack_unwind(sp, arity)
end

# @rbs finish: Integer
# @rbs return: Array[I32|I64|F32|F64|Block]
# @rbs return: Array[I32|I64|F32|F64]
def drained_stack(finish)
drained = stack[0...finish]
if ! drained
Expand Down
6 changes: 3 additions & 3 deletions sig/generated/wardite.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ module Wardite
include ValueHelper

# TODO: add types of class that the stack accomodates
attr_accessor stack: Array[I32 | I64 | F32 | F64 | Block]
attr_accessor stack: Array[I32 | I64 | F32 | F64]

attr_accessor call_stack: Array[Frame]

Expand Down Expand Up @@ -265,8 +265,8 @@ module Wardite
def stack_unwind: (Integer sp, Integer arity) -> void

# @rbs finish: Integer
# @rbs return: Array[I32|I64|F32|F64|Block]
def drained_stack: (Integer finish) -> Array[I32 | I64 | F32 | F64 | Block]
# @rbs return: Array[I32|I64|F32|F64]
def drained_stack: (Integer finish) -> Array[I32 | I64 | F32 | F64]

# @rbs name: Symbol
# @rbs args: Array[Object]
Expand Down

0 comments on commit c975bc9

Please sign in to comment.