On Tue, Jul 6, 2021 at 4:44 AM FallingFromBed <
falling...@gmail.com> wrote:
>
> "...and I'm not really sure what
> you are looking for. C++ is a very complex language and does have
> many constructs that can be rewritten in simpler ways. Go is a much
> simpler language...."
>
> Surely I say to Ian, if we have `var i interface{int(10)}` there must be some code generated to turn the variable `i` into an `interFaceType` type and that must be a compiler generated go code, same goes to `var j []int` will change the `j` into a sliceStruct
> that must be done by a compiler generated Go code. so these are insights we miss before the user code getting turned into assembly-code...... Did you now get what I am looking for, Ian?
That's true, I suppose it would be possible for a Go compiler to
translate interfaces and slices into (unsafe) Go code that uses
structs. However, I do not know of any Go compiler that actually
works that way. When you say "that must be a compiler generate go
code" I think that you are mistaken. The Go compilers that I am
familiar with translate Go code into an intermediate representation
(IR) and then operate on that IR. But the IR is not Go. For example,
for this (non-idiomatic) Go code
package p
func F() []int {
var j []int
j = make([]int, 10)
j[1] = 2
return j
}
the gccgo compiler produces
F() (.go.p.$ret0 (g._6_7int)) : (g.func_8_9_8_6_7int_9)
{
var .go.p.j (g._6_7int) // foo7.go:4
tmp.55498688 = makeslice((int),10,10) // foo7.go:5
j = (g._6_7int)(slicevalue(values: (g._2int)(tmp.55498688) , length:
10, capacity: 10)) // foo7.go:5
tmp.55517040 = sliceinfo(j,length) // foo7.go:6
tmp.55517200 = sliceinfo(j,capacity ) // foo7.go:6
(((1 >= 0) && (1 < tmp.55517040) ) ? true :
goPanicIndex(1,tmp.55517040) ) // foo7.go:6
j[1] = 2 // foo7.go:6
{
$ret0 = j // foo7.go:7
return // foo7.go:7
}
}
It's not entirely unlike Go, but it's not really Go.
Ian
> On Monday, July 5, 2021 at 10:34:31 PM UTC+5:30 Ian Lance Taylor wrote:
>>
>> On Mon, Jul 5, 2021 at 12:59 AM FallingFromBed <
falling...@gmail.com> wrote:
>> >
>> > To give an example, for C++ we have
https://cppinsights.io/ and I am not asking for any web based tools as such.... Any native cmd (go tool) available to achieve what I am looking for? Thanks.
>>
>> I'm not aware of any such tools for Go, and I'm not really sure what
>> you are looking for. C++ is a very complex language and does have
>> many constructs that can be rewritten in simpler ways. Go is a much
>> simpler language. At first glance the only Go construct that can be
>> rewritten is the three-element for statement, and the code that it
>> gets rewritten into is only slightly simpler.
>>
>> Ian
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/39cd7fa3-01f3-4fff-ae09-81fe0441605bn%40googlegroups.com.