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

Adding decimal literals #208

Merged
merged 8 commits into from
Oct 13, 2017
Merged

Adding decimal literals #208

merged 8 commits into from
Oct 13, 2017

Conversation

aupiff
Copy link
Collaborator

@aupiff aupiff commented Oct 6, 2017

fixes #90

READY TO MERGE.

NOTE:

  • An ordinary decimal literal is assumed to to be of type uint256. To write a uint8 literal one must add the suffix u8, as in 5u8.

aupiff added 2 commits October 6, 2017 11:38
- finished lexing
- finished parsing
- wrote placeholder for codegen
- added test case that uses decimal literal (025)
@aupiff aupiff changed the title (WIP) Adding Decimal literals (WIP) Adding decimal literals Oct 6, 2017
- this might go away when better type inference is implemented
- expanding uint8 and uint256 tests
@aupiff
Copy link
Collaborator Author

aupiff commented Oct 11, 2017

I am working on automated gethtests in another branch.

I'll test various functions which use decimal literals on a local blockchain and then include those tests and the script to run them in separate PR. The feature-automated-geth-test branch is in the very early stages, but it should be ready by the end of the week. I'll be confident about the correctness of this decimal literals PR by Thursday.

@pirapira
Copy link
Owner

Did you have a look at src/exec/endToEnd.ml? It uses eth to test the compiled bytecode.

@pirapira
Copy link
Owner

The changes in this PR look good so far.

@aupiff
Copy link
Collaborator Author

aupiff commented Oct 11, 2017

@pirapira src/exec/endToEnd.ml looks good, but I have issues running make endToEnd.

ocamlbuild -use-ocamlfind -Is src/basics,src/ast,src/parse,src/lib,src/codegen -package batteries -package cryptokit -package rope -package rpclib -package rpclib.unix -package unix -package rpclib.json -package ppx_deriving -package ppx_deriving_rpc -package hex -use-menhir src/exec/endToEnd.native
Finished, 0 targets (0 cached) in 00:00:00.
+ /Users/aupiff/.opam/system/bin/ocamlfind ocamldep -package batteries -package cryptokit -package hex -package rope -package hex -package ppx_deriving_rpc -package ppx_deriving -package rpclib.json -package unix -package rpclib.unix -package rpclib -package rope -package cryptokit -package batteries -modules src/exec/endToEnd.ml > src/exec/endToEnd.ml.depends
ocamlfind: Package `ppx_deriving_rpc' not found                       
Command exited with code 2.        
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.
make: *** [endToEnd] Error 10

I'll write my own geth tests in bash for now and report on their results in a comment. Afterwards, I'll figure out how to compile add automated tests to endToEnd.ml

@aupiff
Copy link
Collaborator Author

aupiff commented Oct 11, 2017

Did some manually testing with geth, everything seems to work as expected. The contract below refers to A() from 025_declit_numeric.bbo

> contract.multiply5.call(2)       
10               
> contract.multiply7.call(3)       
21               
> contract.multiply7.call(30000)   
210000           
> contract.s.call()                
true             
> contract.ggg.call()              
7.771213812919199999999e+22        
> contract.g.call(324234)          
10               
> contract.f.call(1000)            
false            
> contract.f.call(4)               
true             
> contract.f.call(5)               
false            
> contract.gg.call(23)             
12138138405817283711        
contract A ()
{
    case(bool f(uint256 a))
    {
        return a < 5 then become A();
    }
    case(uint256 g(uint256 a))
    {
        return 1 + 9 then become A();
    }
    case(uint256 gg(uint256 a))
    {
        return 12138129191999999999 + 9213817283712 then become A();
    }
    case(uint256 ggg(uint256 a))
    {
        return 77712138129191999999999 - 9 then become A();
    }
    case(bool s())
    {
        return 239842934 > 289302 then become A();
    }
    case(uint8 i(uint8 a))
    {
        return 12u8 + 5u8 then become A();
    }
    case(uint8 j())
    {
        return 12u8 - 5u8 then become A();
    }
    case(bool k())
    {
        return 12u8 > 5u8 then become A();
    }
    case(bool q(uint8 a))
    {
        return a < 5u8 then become A();
    }
    case(uint8 multiply5(uint8 a))
    {
        return a * 5u8 then become A();
    }
    case(uint256 multiply7(uint256 a))
    {
        return a * 7 then become A();
    }
}

@aupiff aupiff changed the title (WIP) Adding decimal literals Adding decimal literals Oct 11, 2017
@pirapira
Copy link
Owner

The compilation error about endToEnd can be solved by this line: https://github.com/pirapira/bamboo/blob/master/.travis.yml#L40

Oh, now I notice (WIP) is gone. I'll have a look.

@aupiff
Copy link
Collaborator Author

aupiff commented Oct 12, 2017

@pirapira just fixed some silly bugs and got endToEnd to compile, thanks for letting me know what deps I was missing.

@pirapira
Copy link
Owner

Documentation is missing about endToEnd.

@pirapira
Copy link
Owner

I created an issue #210 about the documentation.

| SenderExp -> "sender"
| TrueExp -> "true"
| FalseExp -> "false"
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@@ -70,5 +70,10 @@ rule read =
| "event" { EVENT }
| "log" { LOG }
| "indexed" { INDEXED }
| digit+ as i { DECLIT256 (Big_int.big_int_of_string i) }
(* uint has at most three digits *)
Copy link
Owner

Choose a reason for hiding this comment

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

(* uint8 has at most three digits *)

{
return a < 300u8 then become A();
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Will you add a similar uint256_too_big.bbo?

Copy link
Owner

@pirapira pirapira left a comment

Choose a reason for hiding this comment

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

I found very minor things, but the PR is already good to merge.

@pirapira pirapira merged commit 46e6a74 into pirapira:master Oct 13, 2017
@pirapira
Copy link
Owner

I'll deal with my own comments.

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.

implement decimal numeric literal
2 participants