Skip to content

Commit

Permalink
luajit: opcodes: implement scalar.UintMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dlatchx committed Jun 20, 2023
1 parent 08ae661 commit 715f850
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion format/luajit/luajit.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (j *jumpBias) MapUint(u scalar.Uint) (scalar.Uint, error) {
}

func LuaJITDecodeBCIns(d *decode.D) {
op := d.FieldU8("op", bcOpSyms)
op := d.FieldU8("op", opcodes)

d.FieldU8("a")

Expand Down
44 changes: 24 additions & 20 deletions format/luajit/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import (
"github.com/wader/fq/pkg/scalar"
)

type BcDef struct {
Name string
MA int
MB int
MC int
}

const (
BcMnone = iota
BcMdst
Expand All @@ -29,7 +22,24 @@ const (
BcMcdata
)

var opcodes = []BcDef{
type BcDef struct {
Name string
MA int
MB int
MC int
}

func (op *BcDef) HasD() bool {
return op.MB == BcMnone
}

func (op *BcDef) IsJump() bool {
return op.MC == BcMjump
}

type BcDefList []BcDef

var opcodes = BcDefList{
{"ISLT", BcMvar, BcMnone, BcMvar},
{"ISGE", BcMvar, BcMnone, BcMvar},
{"ISLE", BcMvar, BcMnone, BcMvar},
Expand Down Expand Up @@ -157,18 +167,12 @@ var opcodes = []BcDef{
{"FUNCCW", BcMrbase, BcMnone, BcMnone},
}

func (op *BcDef) HasD() bool {
return op.MB == BcMnone
}

func (op *BcDef) IsJump() bool {
return op.MC == BcMjump
}

var bcOpSyms = scalar.UintMapSymStr{}
func (opcodes BcDefList) MapUint(s scalar.Uint) (scalar.Uint, error) {
listIdx := int(s.Actual)

func init() {
for i := 0; i < len(opcodes); i++ {
bcOpSyms[uint64(i)] = opcodes[i].Name
if listIdx < len(opcodes) {
s.Sym = opcodes[listIdx].Name
}

return s, nil
}

0 comments on commit 715f850

Please sign in to comment.