-
Notifications
You must be signed in to change notification settings - Fork 148
WIP: Go Module with JS Runtime Environment #70
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #70 +/- ##
===========================================
+ Coverage 39.64% 63.48% +23.84%
===========================================
Files 35 24 -11
Lines 3105 1920 -1185
===========================================
- Hits 1231 1219 -12
+ Misses 1796 626 -1170
+ Partials 78 75 -3
Continue to review full report at Codecov.
|
BufferAt(offset, length int64) ([]byte, error) | ||
} | ||
|
||
func (g *Go) setUInt8(ba BufferAt, addr int32, v uint8) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be written as:
func (g *Go) setUInt8(w io.WriterAt, addr int32, v uint8) {
var buf = [1]byte{v}
_, err := w.WriteAt(buf[:], int64(addr))
if err != nil {
panic(err)
}
}
buf[0] = byte(v) | ||
} | ||
|
||
func (g *Go) setUInt32(ba BufferAt, addr int32, v uint32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this:
func (g *Go) setUInt32(w io.WriterAt, addr int32, v uint32) {
var buf [4]byte
binary.LittleEndian.PutUint32(buf[:], v)
_, err := w.WriteAt(buf[:], int64(addr))
if err != nil {
panic(err)
}
}
g.setUInt32(ba, addr, uint32(v)) | ||
} | ||
|
||
func (g *Go) setUInt64(ba BufferAt, addr int32, v uint64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly:
func (g *Go) setUInt64(w io.WriterAt, addr int32, v uint64) {
var buf [8]byte
binary.LittleEndian.PutUint64(buf[:], v)
_, err := w.WriteAt(buf[:], int64(addr))
if err != nil {
panic(err)
}
}
g.setUInt64(ba, addr, uint64(v)) | ||
} | ||
|
||
func (g *Go) getUInt64(ba BufferAt, addr int32) uint64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conversely:
func (g *Go) getUInt64(r io.ReaderAt, addr int32) uint64 {
var buf [8]byte
n, err := r.ReadAt(buf[:], int64(addr))
if err != nil {
panic(err)
}
if n != 8 {
panic("short read") // or some more meaningful error message. io.ErrUnexpectedEOF ?
}
return binary.LittleEndian.Uint64(buf[:])
}
@@ -0,0 +1,476 @@ | |||
package modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would need a license header.
@sbinet not sure how you feel about 3rd party libraries being used, but I wonder if it wouldn't be better to make a generic javascript module loader using something like https://github.com/robertkrimen/otto ? Basically have that parse wasm_exec.js and then just act as a go-between between the two vms. Potentially other javascript wasm import modules would work too, such as those for lvvm and other wasm compilers. It could be a separate repo so that wagon itself doesn't depend on a dependency like that. I don't know otto at all so I don't know if it's fully featured, but the idea would be to completely eliminate the need to emulate anything. Just thought it'd be worth the discussion before I go too far down the rabbit hole with this. Might be worth a spike of sorts. Thoughts? |
I know of In general, I tried very hard to keep that said, reimplementing a robust JS VM doesn't sound like efficient use of anyone's time :) (at least for being able to plug in LLVM (via github.com/llir/llvm perhaps?) sounds very interesting. (when I started |
@evandigby @sbinet I think it depends on the intended use whether or not one should look at using |
@evandigby - I was planning to pull this down and give it a go. What should I expect? |
@sbinet can you unpack being able to plug in LLVM a little more ? One thing that would be really interesting would be having the ability to call native functions i.e
Where Logvalue would be implemented as either a true wasm module or native function ( in this case in go ) and added as a wasm.Module to the vm instance. Just found #58 and looking through the code this seems to be more of what I am talking about. Would still love to hear more about an LLVM IR. |
FYI, there is a parallel effort at https://github.com/neelance/go_js_wasm_exec. |
This is a WIP PR to start the discussion.
This change is