forked from TrueCloudLab/neoneo-go
compiler: use parameter directly in writeJumps
`Next` doesn't longer copy parameter. Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
f5d1277bfd
commit
dc9287bf5c
1 changed files with 4 additions and 10 deletions
|
@ -2097,20 +2097,17 @@ func (c *codegen) resolveFuncDecls(f *ast.File, pkg *types.Package) {
|
||||||
func (c *codegen) writeJumps(b []byte) ([]byte, error) {
|
func (c *codegen) writeJumps(b []byte) ([]byte, error) {
|
||||||
ctx := vm.NewContext(b)
|
ctx := vm.NewContext(b)
|
||||||
var offsets []int
|
var offsets []int
|
||||||
for op, _, err := ctx.Next(); err == nil && ctx.IP() < len(b); op, _, err = ctx.Next() {
|
for op, param, err := ctx.Next(); err == nil && ctx.IP() < len(b); op, param, err = ctx.Next() {
|
||||||
switch op {
|
switch op {
|
||||||
case opcode.JMP, opcode.JMPIFNOT, opcode.JMPIF, opcode.CALL,
|
case opcode.JMP, opcode.JMPIFNOT, opcode.JMPIF, opcode.CALL,
|
||||||
opcode.JMPEQ, opcode.JMPNE,
|
opcode.JMPEQ, opcode.JMPNE,
|
||||||
opcode.JMPGT, opcode.JMPGE, opcode.JMPLE, opcode.JMPLT:
|
opcode.JMPGT, opcode.JMPGE, opcode.JMPLE, opcode.JMPLT:
|
||||||
case opcode.TRYL:
|
case opcode.TRYL:
|
||||||
nextIP := ctx.NextIP()
|
_, err := c.replaceLabelWithOffset(ctx.IP(), param)
|
||||||
catchArg := b[nextIP-8:]
|
|
||||||
_, err := c.replaceLabelWithOffset(ctx.IP(), catchArg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
finallyArg := b[nextIP-4:]
|
_, err = c.replaceLabelWithOffset(ctx.IP(), param[4:])
|
||||||
_, err = c.replaceLabelWithOffset(ctx.IP(), finallyArg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2118,10 +2115,7 @@ func (c *codegen) writeJumps(b []byte) ([]byte, error) {
|
||||||
opcode.JMPEQL, opcode.JMPNEL,
|
opcode.JMPEQL, opcode.JMPNEL,
|
||||||
opcode.JMPGTL, opcode.JMPGEL, opcode.JMPLEL, opcode.JMPLTL,
|
opcode.JMPGTL, opcode.JMPGEL, opcode.JMPLEL, opcode.JMPLTL,
|
||||||
opcode.CALLL, opcode.PUSHA, opcode.ENDTRYL:
|
opcode.CALLL, opcode.PUSHA, opcode.ENDTRYL:
|
||||||
// we can't use arg returned by ctx.Next() because it is copied
|
offset, err := c.replaceLabelWithOffset(ctx.IP(), param)
|
||||||
nextIP := ctx.NextIP()
|
|
||||||
arg := b[nextIP-4:]
|
|
||||||
offset, err := c.replaceLabelWithOffset(ctx.IP(), arg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue