Skip to content

Commit

Permalink
Removed redundant operand
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Oct 2, 2024
1 parent 3de5145 commit 43e59fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
23 changes: 10 additions & 13 deletions pkg/compiler/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (v *visitor) VisitFunctionCallExpression(ctx *fql.FunctionCallExpressionCon

isNonOptional := ctx.ErrorOperator() == nil

v.emit(runtime.OpConstant, v.addConstant(values.String(name)))
v.emitConstant(values.String(name))

var size int

Expand Down Expand Up @@ -526,7 +526,7 @@ func (v *visitor) VisitObjectLiteral(ctx *fql.ObjectLiteralContext) interface{}
comProp.Accept(v)
pac.Expression().Accept(v)
} else if variable := pac.Variable(); variable != nil {
v.emitConstant(runtime.OpConstant, values.NewString(variable.GetText()))
v.emitConstant(values.NewString(variable.GetText()))
variable.Accept(v)
}
}
Expand All @@ -538,13 +538,13 @@ func (v *visitor) VisitObjectLiteral(ctx *fql.ObjectLiteralContext) interface{}

func (v *visitor) VisitPropertyName(ctx *fql.PropertyNameContext) interface{} {
if id := ctx.Identifier(); id != nil {
v.emitConstant(runtime.OpConstant, values.NewString(ctx.GetText()))
v.emitConstant(values.NewString(ctx.GetText()))
} else if str := ctx.StringLiteral(); str != nil {
str.Accept(v)
} else if word := ctx.SafeReservedWord(); word != nil {
v.emitConstant(runtime.OpConstant, values.NewString(ctx.GetText()))
v.emitConstant(values.NewString(ctx.GetText()))
} else if word := ctx.UnsafeReservedWord(); word != nil {
v.emitConstant(runtime.OpConstant, values.NewString(ctx.GetText()))
v.emitConstant(values.NewString(ctx.GetText()))
}

return nil
Expand Down Expand Up @@ -602,7 +602,7 @@ func (v *visitor) VisitStringLiteral(ctx *fql.StringLiteralContext) interface{}
}
}

v.emitConstant(runtime.OpConstant, values.NewString(b.String()))
v.emitConstant(values.NewString(b.String()))

return nil
}
Expand All @@ -614,7 +614,7 @@ func (v *visitor) VisitIntegerLiteral(ctx *fql.IntegerLiteralContext) interface{
panic(err)
}

v.emitConstant(runtime.OpConstant, values.NewInt(val))
v.emitConstant(values.NewInt(val))

return nil
}
Expand All @@ -626,7 +626,7 @@ func (v *visitor) VisitFloatLiteral(ctx *fql.FloatLiteralContext) interface{} {
panic(err)
}

v.emitConstant(runtime.OpConstant, values.NewFloat(val))
v.emitConstant(values.NewFloat(val))

return nil
}
Expand Down Expand Up @@ -1004,8 +1004,8 @@ func (v *visitor) defineVariable(index int) {
}

// emitConstant emits an opcode with a constant argument.
func (v *visitor) emitConstant(op runtime.Opcode, constant core.Value) {
v.emit(op, v.addConstant(constant))
func (v *visitor) emitConstant(constant core.Value) {
v.emit(runtime.OpPush, v.addConstant(constant))
}

// emitLoop emits a loop instruction.
Expand Down Expand Up @@ -1083,9 +1083,6 @@ func (v *visitor) updateStackTracker(op runtime.Opcode, arg int) {
case runtime.OpNone:
v.operandsStackTracker++

case runtime.OpConstant:
v.operandsStackTracker++

case runtime.OpCastBool:
break

Expand Down
1 change: 0 additions & 1 deletion pkg/runtime/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ type Opcode byte

const (
OpNone Opcode = iota
OpConstant
OpCastBool
OpTrue
OpFalse
Expand Down
3 changes: 0 additions & 3 deletions pkg/runtime/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ loop:
case OpNone:
stack.Push(values.None)

case OpConstant:
stack.Push(program.Constants[arg])

case OpCastBool:
stack.Push(values.ToBoolean(stack.Pop()))

Expand Down

0 comments on commit 43e59fe

Please sign in to comment.