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

cl: support const & iota #683

Merged
merged 13 commits into from
Mar 14, 2021
Merged

cl: support const & iota #683

merged 13 commits into from
Mar 14, 2021

Conversation

visualfc
Copy link
Member

@visualfc visualfc commented Mar 7, 2021

fix #682
fix #684

  • support constant declarations
  • predeclared identifier iota
  • fix golang const float64 typecast

Go+ code

const Pi float64 = 3.14159265358979323846
const zero = 0.0         // untyped floating-point constant
const (
	size int64 = 1024
	eof        = -1  // untyped integer constant
)
const va, vb, vc = 3, 4, "foo"  // a = 3, b = 4, c = "foo", untyped integer and string constants
const fu, fv float32 = 0, 3    // u = 0.0, v = 3.0

const (
	c0 = iota  // c0 == 0
	c1 = iota  // c1 == 1
	c2 = iota  // c2 == 2
)

const (
	a = 1 << iota  // a == 1  (iota == 0)
	b = 1 << iota  // b == 2  (iota == 1)
	c = 3          // c == 3  (iota == 2, unused)
	d = 1 << iota  // d == 8  (iota == 3)
)

const (
	u         = iota * 42  // u == 0     (untyped integer constant)
	v float64 = iota * 42  // v == 42.0  (float64 constant)
	w         = iota * 42  // w == 84    (untyped integer constant)
)

const x = iota  // x == 0
const y = iota  // y == 0

const (
	bit0, mask0 = 1 << iota, 1<<iota - 1  // bit0 == 1, mask0 == 0  (iota == 0)
	bit1, mask1                           // bit1 == 2, mask1 == 1  (iota == 1)
	_, _                                  //                        (iota == 2, unused)
	bit3, mask3                           // bit3 == 8, mask3 == 7  (iota == 3)
)

println(Pi)
println(zero,size,eof)
println(va,vb,vc)
println(fu,fv)

println(c0,c1,c2)
println(a,b,c,d)
println(x,y)
println(u,v,w)
println(bit0,mask0,bit1,mask1,bit3,mask3)

generate Golang code

package main

import fmt "fmt"

func main() { 
//line ./main.gop:40
	fmt.Println(float64(3.141592653589793))
//line ./main.gop:41
	fmt.Println(float64(0), int64(1024), -1)
//line ./main.gop:42
	fmt.Println(3, 4, "foo")
//line ./main.gop:43
	fmt.Println(float32(0), float32(3))
//line ./main.gop:45
	fmt.Println(0, 1, 2)
//line ./main.gop:46
	fmt.Println(1, 2, 3, 8)
//line ./main.gop:47
	fmt.Println(0, 0)
//line ./main.gop:48
	fmt.Println(0, float64(42), 84)
//line ./main.gop:49
	fmt.Println(1, 0, 2, 1, 8, 7)
}

@codecov-io
Copy link

codecov-io commented Mar 7, 2021

Codecov Report

Merging #683 (52aa5b9) into master (6b6993f) will increase coverage by 0.06%.
The diff coverage is 95.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #683      +/-   ##
==========================================
+ Coverage   90.06%   90.12%   +0.06%     
==========================================
  Files          42       42              
  Lines        9298     9339      +41     
==========================================
+ Hits         8374     8417      +43     
+ Misses        655      654       -1     
+ Partials      269      268       -1     
Impacted Files Coverage Δ
cl/compile.go 86.04% <94.11%> (+3.43%) ⬆️
cl/expr.go 89.55% <100.00%> (+0.09%) ⬆️
exec/golang/expr.go 94.11% <100.00%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b6993f...52aa5b9. Read the comment docs.

@visualfc visualfc changed the title cl: support const cl: support const & iota Mar 8, 2021
@xushiwei xushiwei merged commit fd45fed into goplus:master Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

golang: const float64 missing conversion unsupport define const value
3 participants