Skip to content

Commit

Permalink
Implement OP_GETCONST
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Dec 28, 2023
1 parent 58447c8 commit 68afb83
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func (feat *RubyFeature) thereShouldReturnFalse() error {
return nil
}

func (feat *RubyFeature) thereShouldReturnNil() error {
if feat.ret != nil {
return fmt.Errorf("expected nil, got %T", feat.ret)
}

return nil
}

func (feat *RubyFeature) thereShouldReturnString(expected string) error {
actual, ok := feat.ret.(string)
if !ok {
Expand Down Expand Up @@ -96,6 +104,7 @@ func InitializeScenario(s *godog.ScenarioContext) {
s.Step(`^there should return integer (-?\d+)$`, feat.thereShouldReturnInteger)
s.Step(`^there should return true$`, feat.thereShouldReturnTrue)
s.Step(`^there should return false$`, feat.thereShouldReturnFalse)
s.Step(`^there should return nil$`, feat.thereShouldReturnNil)
s.Step(`^there should return string "([^"]*)"$`, feat.thereShouldReturnString)
s.Step(`^there should return symbol "([^"]*)"$`, feat.thereShouldReturnSymbol)
}
Expand Down
7 changes: 7 additions & 0 deletions features/constant.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Constant
Scenario: I can get non existing constant
When I execute ruby code:
"""
MY_CONSTANT
"""
Then there should return nil
4 changes: 4 additions & 0 deletions irep.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (ir *iRep) Execute(state *State) (Value, error) {
a := ir.iSeq.ReadB()
b := ir.iSeq.ReadB()
regs[offset+int(a)] = ir.syms[b]
case opGetConst:
a := ir.iSeq.ReadB()
b := ir.iSeq.ReadB()
regs[a] = state.GetConst(ir.syms[b])
case opSelfSend:
a := ir.iSeq.ReadB()
b := ir.iSeq.ReadB()
Expand Down
5 changes: 5 additions & 0 deletions variable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mruby

func (mrb *State) GetConst(sym Symbol) Value {
return nil
}

0 comments on commit 68afb83

Please sign in to comment.