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

Support Formal Front-End of Float Type Data #470

Merged
merged 8 commits into from
Nov 25, 2017

Conversation

Alexius-Huang
Copy link
Member

@Alexius-Huang Alexius-Huang commented Oct 20, 2017

Currently using the Go float64 datatype to support for Goby's float type data

Small issue to address - cases below will show the correct result

(3.14159265358979).to_d.to_s # => "3.14159265358979"
(-273.150000000).to_d.to_s # => "-273.15"

# and without the round bracket
3.14159265358979.to_d.to_s # => "3.14159265358979"

However, there is a case when a negative valued float type number cannot call method without round bracket which I've labeled with a TODO

-273.150000000.to_d.to_s # ERROR

See #526

Another thing to address is that, currently this PR only support the basic format of Float API (and because this PR is big enough), so to implement the special format of float, e.g. the exponential format as described in issue #471, welcome to contribute another PR

@Alexius-Huang Alexius-Huang requested a review from a team October 20, 2017 07:07
@ghost ghost assigned Alexius-Huang Oct 20, 2017
@ghost ghost added the in progress label Oct 20, 2017
if ok && p.peekTokenIs(token.Int) {
// When both receiver & caller are integer => Float
return p.parseFloatLiteral(receiver)
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

}

func (il *FloatLiteral) expressionNode() {}
func (il *FloatLiteral) TokenLiteral() string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method FloatLiteral.TokenLiteral should have comment or be unexported

@@ -19,6 +19,19 @@ func (il *IntegerLiteral) String() string {
return il.Token.Literal
}

type FloatLiteral struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type FloatLiteral should have comment or be unexported

if ok && p.peekTokenIs(token.Int) {
// When both receiver & caller are integer => Float
return p.parseFloatLiteral(receiver)
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

}

func (il *FloatLiteral) expressionNode() {}
func (il *FloatLiteral) TokenLiteral() string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method FloatLiteral.TokenLiteral should have comment or be unexported

@@ -19,6 +19,19 @@ func (il *IntegerLiteral) String() string {
return il.Token.Literal
}

type FloatLiteral struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type FloatLiteral should have comment or be unexported

if ok && p.peekTokenIs(token.Int) {
// When both receiver & caller are integer => Float
return p.parseFloatLiteral(receiver)
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

}

func (il *FloatLiteral) expressionNode() {}
func (il *FloatLiteral) TokenLiteral() string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method FloatLiteral.TokenLiteral should have comment or be unexported

@@ -19,6 +19,19 @@ func (il *IntegerLiteral) String() string {
return il.Token.Literal
}

type FloatLiteral struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type FloatLiteral should have comment or be unexported

@Alexius-Huang
Copy link
Member Author

@st0012 Can you hint me on writing tests about parseFloatLiteral or other kind of tests? I'm still a little confused and not sure about I'm on the right track. QAQ

Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just need to make VM's tests all be passed for now

vm/float_test.go Outdated
@@ -200,8 +200,8 @@ func TestFloatConversions(t *testing.T) {
input string
expected interface{}
}{
{`'100.3'.to_f.to_i`, 100},
{`'100.3'.to_f.to_s`, "100.3"},
{`(100.3).to_i`, 100},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also support (or raise parsing error) when there's no parentheses around the float.

@st0012
Copy link
Member

st0012 commented Oct 20, 2017

@Maxwell-Alexius We'll have an large reconstruction for our compiler's tests, so don't worry about adding parser tests now.

@64kramsystem
Copy link
Member

64kramsystem commented Oct 20, 2017

For reference, programming languages generally support also the exponential format:

2E2
2e2
2e-2
20.0e2

I think this should be either implemented in this PR, or a separate issue should be created, for tracking purposes.

@st0012
Copy link
Member

st0012 commented Oct 20, 2017

@saveriomiroddi Thanks for reminding, I'll create another issue for this format.

@Alexius-Huang Alexius-Huang force-pushed the feature/issue-379-float-type-front-end branch 2 times, most recently from a26852c to d968d3f Compare October 24, 2017 09:00
@codecov
Copy link

codecov bot commented Oct 24, 2017

Codecov Report

Merging #470 into master will decrease coverage by 0.3%.
The diff coverage is 44.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #470      +/-   ##
==========================================
- Coverage    83.6%   83.29%   -0.31%     
==========================================
  Files          53       53              
  Lines        9325     9369      +44     
==========================================
+ Hits         7796     7804       +8     
- Misses       1289     1320      +31     
- Partials      240      245       +5
Impacted Files Coverage Δ
compiler/token/token.go 100% <ø> (ø) ⬆️
compiler/bytecode/instruction.go 62.5% <ø> (ø) ⬆️
compiler/bytecode/expression_generation.go 74.4% <0%> (-0.72%) ⬇️
compiler/parser/data_type_parsing.go 59.66% <0%> (-9.95%) ⬇️
compiler/parser/parser.go 79.47% <100%> (ø) ⬆️
vm/float.go 83.87% <100%> (-4.84%) ⬇️
vm/json.go 72.27% <62.5%> (-0.85%) ⬇️
compiler/parser/expression_parsing.go 52.22% <62.5%> (+0.31%) ⬆️
vm/instruction.go 94.36% <90%> (-0.38%) ⬇️

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 407c3c1...3f86f8c. Read the comment docs.

@Alexius-Huang Alexius-Huang force-pushed the feature/issue-379-float-type-front-end branch 2 times, most recently from e428340 to 5991cbe Compare October 27, 2017 07:08
@Alexius-Huang Alexius-Huang changed the title [WIP] Support Formal Front-End of Float Type Data Support Formal Front-End of Float Type Data Oct 27, 2017
@Alexius-Huang Alexius-Huang changed the title Support Formal Front-End of Float Type Data [WIP] Support Formal Front-End of Float Type Data Oct 27, 2017
@Alexius-Huang Alexius-Huang changed the title [WIP] Support Formal Front-End of Float Type Data Support Formal Front-End of Float Type Data Oct 27, 2017
@Alexius-Huang Alexius-Huang force-pushed the feature/issue-379-float-type-front-end branch from e0c381c to c365987 Compare October 27, 2017 08:42
@st0012 st0012 mentioned this pull request Nov 5, 2017
23 tasks
@Alexius-Huang Alexius-Huang force-pushed the feature/issue-379-float-type-front-end branch from 4d9bb06 to e935aec Compare November 18, 2017 11:19
@Alexius-Huang Alexius-Huang force-pushed the feature/issue-379-float-type-front-end branch from e935aec to 19972aa Compare November 18, 2017 11:24
@Alexius-Huang
Copy link
Member Author

Alexius-Huang commented Nov 18, 2017

@st0012 Currently there is a small problem -- cases below will show the correct result

(3.14159265358979).to_d.to_s # => "3.14159265358979"
(-273.150000000).to_d.to_s # => "-273.15"

# and without the round bracket
3.14159265358979.to_d.to_s # => "3.14159265358979"

However, there is a case when a negative valued float type number cannot call method without round bracket which I've labeled with a TODO

-273.150000000.to_d.to_s # ERROR

3.14159265358979.to_d.to_s`,
"3.14159265358979"},
// TODO: Able to parse negative float value and call method without parentheses
//{`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the small problem which is described in PR

@Alexius-Huang
Copy link
Member Author

Another thing to address is that, currently this PR only support the basic format of Float API (and because this PR is big enough), so to implement the special format of float, e.g. the exponential format as described in issue #471, welcome to contribute another PR

@st0012
Copy link
Member

st0012 commented Nov 18, 2017

@saveriomiroddi Do you want to take a look before I merge this?

_, ok := receiver.(*ast.IntegerLiteral)

// When both receiver & caller are integer => Float
if ok && p.peekTokenIs(token.Int) {
Copy link
Member

@64kramsystem 64kramsystem Nov 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this code, expresions with spaces on the sides of the dot will be parsed as floats (eg. 2 . 3).

If this is intended (other scripting languages forbid it), I think it should be documented with a test case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually currently Goby doesn't recognize white space, so it's not just float has this issue, like:

[] . length #=> 0

But this shouldn't be too hard to solve I think, already have a rough idea. But that won't be included in this PR.

@@ -438,7 +438,7 @@ func (f *FloatObject) numericComparison(t *thread, rightObject Object, operation
// toString returns the object's value as the string format, in non
// exponential format (straight number, without exponent `E<exp>`).
func (f *FloatObject) toString() string {
return strconv.FormatFloat(f.value, 'f', -1, 64)
return strconv.FormatFloat(f.value, 'f', -1, 64) // fmt.Sprintf("%f", f.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment intended?

@ghost ghost assigned st0012 Nov 25, 2017
@st0012 st0012 merged commit fd60f81 into master Nov 25, 2017
@ghost ghost removed the in progress label Nov 25, 2017
@st0012 st0012 deleted the feature/issue-379-float-type-front-end branch January 15, 2018 11:41
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.

4 participants