weixin_39731807
2020-12-02 08:53 阅读 0

BigInteger writing

Currently in compiled mode only writing BigIntegers out as strings has been implemented. We should implement the other encoding as well.

该提问来源于开源项目:pixie-lang/pixie

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

9条回答 默认 最新

  • weixin_39933026 weixin_39933026 2020-12-02 08:53

    I'd like to work on this. Am I correct that the primary places this will need work are in pixie/vm/libs/pxic/writer.py and reader.py (same location)?

    点赞 评论 复制链接分享
  • weixin_39731807 weixin_39731807 2020-12-02 08:53

    That's correct. You should almost be able to copy whats done for Integers.

    点赞 评论 复制链接分享
  • weixin_39933026 weixin_39933026 2020-12-02 08:53

    There's a bit of a challenge with this one. Because BigIntegers have a potentially infinite length, rather than a set length as do ordinary integers, we have to have a way of knowing how many characters to read in as part of the BigInteger. This is similar to the problem of knowing when to end a string. Since we can't do null-terminators to end like you would in a string, I'm doing an integer first to say how many 8-bit characters represent the integer. That will allow numbers up to 2^(MAX_INTEGER), which should be large enough for almost any conceivable use.

    点赞 评论 复制链接分享
  • weixin_39614834 weixin_39614834 2020-12-02 08:53

    You could work around that by writing in chunks. Fressian does that if a string (or a byte array) is too long.

    However, it's probably not necessary. A comment indicating that there is a limit should be enough.

    点赞 评论 复制链接分享
  • weixin_39731807 weixin_39731807 2020-12-02 08:53

    Indicating the length sounds like a smart choice.

    点赞 评论 复制链接分享
  • weixin_39731807 weixin_39731807 2020-12-02 08:53

    In the pixie-vm2 branch the pxic writer is implemented in pixie itself so it would be quite easy. Unfortunately, in master there isn't any obvious way to test this kind of thing nicely. You could try and expose some of the underlying rpython to pixie, but those functions would really only useful for testing I imagine.

    点赞 评论 复制链接分享
  • weixin_39933026 weixin_39933026 2020-12-02 08:53

    Ugh. That makes it difficult to test my code. I'll go through it a few more times and then submit a pull request probably, so others can catch pitfalls.

    点赞 评论 复制链接分享
  • weixin_39933026 weixin_39933026 2020-12-02 08:53

    That pull request now includes my implementation of big integer writing to pxic.

    点赞 评论 复制链接分享
  • weixin_39614834 weixin_39614834 2020-12-02 08:53

    Merged as part of #342.

    点赞 评论 复制链接分享

相关推荐