Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: method call on interface receiver #268

Open
zapateo opened this issue Aug 6, 2019 · 4 comments
Open

compiler: method call on interface receiver #268

zapateo opened this issue Aug 6, 2019 · 4 comments
Labels
bug Bug: something already implemented does not work as it should emitter/builder Related to VM's emitter and builder needsInvestigation Need to investigate RuntimeError A bug in Scriggo caused an error/panic at runtime

Comments

@zapateo
Copy link
Member

zapateo commented Aug 6, 2019

package main

import "crypto/sha1"

func main() {
	h := sha1.New()
	sb := []byte("abc")
	h.Write(sb)
}

reports the error value of type *sha1.digest is not assignable to type []uint8

@zapateo zapateo added bug Bug: something already implemented does not work as it should needsInvestigation Need to investigate labels Aug 6, 2019
@gazerro gazerro added the emitter/builder Related to VM's emitter and builder label Aug 6, 2019
@gazerro
Copy link
Member

gazerro commented Aug 6, 2019

The emitted code is:

Package main

Import "sha1"

Func main()
	; regs(1,0,1,7)
	Call sha1.New _ _ _ g3	; func() (g3 hash.Hash)
	Move g3 g2
	Move g2 g1
	Move "abc" s1
	Convert s1 []uint8 g3
	Move g3 g2
	Move g1 g3
	MethodValue g3 "Write" g4
	Move g1 g6
	Move g2 g7
	Call (g4) ...0 i1 _ _ g5	; func(g6 []uint8) (i1 int, g5 error)
	Return

@gazerro gazerro added this to the Milestone 1 milestone Aug 17, 2019
@zapateo
Copy link
Member Author

zapateo commented Aug 19, 2019

Note that h has type hash.Hash, which is an interface that embeds io.Writer.

@zapateo
Copy link
Member Author

zapateo commented Aug 19, 2019

The emitted code is:

Package main

Import "sha1"

Func main()
	; regs(1,0,0,9)
	CallPredefined sha1.New	; New() (g3 hash.Hash)
	Move g3 g2
	Move g2 g1
	Move nil g5
	Move g5 g4
	Move g4 g3
	
	Move g1 g8
	Move g3 g9
	CallIndirect g6 ...0	; Stack shift: 0, 0, 0, 6
	Return

That was a problem of the disassembler, which has been resolved in e291a02.

The disassembled code is now

   1 
   2 Package main
   3 
   4 Import "sha1"
   5 
   6 Func main()
   7     ; regs(1,0,1,9)
   8     CallPredefined sha1.New ; New() (g3 hash.Hash)
   9     Move g3 g2
  10     Move g2 g1
  11     Move "abc" s1
  12     Convert s1 []uint8 g4
  13     Move g4 g3
  14     Move g1 g5
  15     MethodValue g5 "Write" g6
  16     Move g1 g8
  17     Move g3 g9
  18     CallIndirect g6 ...0    ; Stack shift: 0, 0, 1, 6
  19     Return

but the problem still persists.

@zapateo zapateo changed the title compiler: value of type *sha1.digest is not assignable to type []uint8 compiler: method call on interface receiver Aug 19, 2019
@zapateo zapateo added the RuntimeError A bug in Scriggo caused an error/panic at runtime label Jan 9, 2020
zapateo added a commit that referenced this issue Jan 9, 2020
@gazerro gazerro removed this from the Milestone 1 milestone Jun 9, 2021
@gazerro
Copy link
Member

gazerro commented Aug 28, 2021

This is the current disassembled code:

Package main

Import "sha1"

Func main()
	; regs(1,0,1,7)
	Call sha1.New _ _ _ g3	; func() (g3 hash.Hash)
	Move g3 g2
	Move g2 g1
	Move "abc" s1
	Convert s1 []uint8 g3
	Move g3 g2
	Move g1 g3
	MethodValue g3 "Write" g4
	Move g1 g6
	Move g2 g7
	Call (g4) ...0 i1 _ _ g5	; func(g6 []uint8) (i1 int, g5 error)
	Return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug: something already implemented does not work as it should emitter/builder Related to VM's emitter and builder needsInvestigation Need to investigate RuntimeError A bug in Scriggo caused an error/panic at runtime
Projects
None yet
Development

No branches or pull requests

2 participants