Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Golang run on a virtual machine?

Tags:

say for some very simple Golang code:

package main  import "fmt"  func plus( a int, b int) int {      return a+b }  func plusPlus(a,b,c int) int {     return a  +b  + c }  func main() {      ptr := plus     ptr2 := plusPlus      fmt.Println(ptr)     fmt.Println(ptr2) } 

This has the following output:

0x2000 0x2020 

What is going on here? This doesn't look like a function pointer, or any kind of pointer for that matter, that one would find in the stack. I also understand that Go, while offering some nice low level functionality in the threading department, also requires an OS for it to function; C is functional across all computer platforms and operating systems can be written in it while Go needs an operating system to function and in fact only works on a few OS right now. Do the very regular function pointers mean that this works on a VM? Or is the compiler just linked to low level C functions?

like image 408
abgordon Avatar asked Jul 08 '15 00:07

abgordon


People also ask

Does Golang run in a VM?

Go does not run on a virtual machine. From the view of the language specification, ptr and ptr2 are function values. They can be called as ptr(1, 2) and ptr2(1, 2, 3) . Diving down into the implementation, the variables ptr and ptr2 are pointers to func values.

Does Golang run on JVM?

Go does not provide any VM such as Java JVM. This language only compiles to metal like c++/c. It combines both the interpretation and compilation approach.

Is Golang machine independent?

Golang Pros Like Java, it's platform independent. You can compile it for any platform your servers and applications run on.

Is Golang cross-platform?

Cross-Platform LanguageGolang is open-source; therefore, making it efficient, cleaner, and better with time remains an easy task. The cross-platform language can be used with various platforms like UNIX, Linux, Windows, and other operating systems that work on mobile devices as well.

What is this Golang project?

This project is a golang based compiler and interpreter for a simple virtual machine. It is a port of the existing project: The original project has a perl based compiler/decompiler. The original interpreter was written in C.

How can I embed a virtual machine in my Golang application?

If you want to see a real virtual machine, interpreting a scripting language, which you can embed inside your Golang applications: There are two ways to install this project from source, which depend on the version of the go version you're using. If you prefer you can fetch a binary from our release page.

How to do machine learning in Golang?

Golang for Machine Learning? 1 Setup. First, we will need to install the following packages in our terminal. ... 2 DataFrame. We will be using the IRIS dataset that describes the different types of iris flower. ... 3 Data Manipulation. Now let’s explore how to perform data manipulation in Go. ... 4 Machine Learning in Go. ...

What is meant by the simplicity of Golang?

"Simplicity" here means that we support only a small number of instructions, and the 16-registers the virtual CPU possesses can store strings and integers, but not floating-point values. If you want to see a real virtual machine, interpreting a scripting language, which you can embed inside your Golang applications:


1 Answers

Go does not run on a virtual machine.

From the view of the language specification, ptr and ptr2 are function values. They can be called as ptr(1, 2) and ptr2(1, 2, 3).

Diving down into the implementation, the variables ptr and ptr2 are pointers to func values. See the Function Call design document for information on func values. Note the distinction between the language's "function" value and the implementation's "func" value.

Because the reflection API used by the fmt package indirects through the func values to get the pointer to print, the call tofmt.Println(ptr) prints the actual address of the plus function.

like image 101
Bayta Darell Avatar answered Sep 18 '22 17:09

Bayta Darell