GithubHelp home page GithubHelp logo

IR for compiler backend about fathom HOT 4 CLOSED

yeslogic avatar yeslogic commented on April 28, 2024
IR for compiler backend

from fathom.

Comments (4)

brendanzab avatar brendanzab commented on April 28, 2024

We might want to build up an abstract semantic graph at some stage to assist in compilation. Petgraph is a good library for working with graph data structures in Rust - might be good to take advantage of it. In fact LALRPOP actually uses it for this purpose!

from fathom.

brendanzab avatar brendanzab commented on April 28, 2024

Here's a sketch of what an owned IR might look like.

Source data description:

Pixel = struct {
    r : u8,
    g : u8,
    b : u8,
};

Bitmap = struct {
    w : u32le,
    h : u32le,
    data : [Pixel; w * h],
};

Bmp = Bitmap;

Owned IR:

define Pixel {
    type = struct {
      r : u8,
      g : u8,
      b : u8,
    };

    parse = \buf -> do {
        (r, buf1) <- parse_u32le_to_u32 buf;
        (g, buf2) <- parse_u32le_to_u32 buf1;
        (b, buf3) <- parse_u32le_to_u32 buf2;
        wrap (struct { w = w, h = h, data = data }, buf3);
    }
};

define Bitmap {
    type = struct {
        w : u32,
        h : u32,
        data : Vec u8,
    };

    parse = \buf -> do {
        (w, buf1) <- parse_u32le_to_u32 buf;
        (h, buf2) <- parse_u32le_to_u32 buf1;
        (data, buf3) <- parse_array_to_vec Pixel::parse (w * h) buf2;
        wrap (struct { w = w, h = h, data = data }, buf3);
    };
};

define Bmp {
    type = Bitmap;
    parse = Bitmap::parse;
};

from fathom.

brendanzab avatar brendanzab commented on April 28, 2024

I'm thinking that instead of those monadic expressions for the owned IR, maybe I could have a small set of parser combinators:

define Pixel {
    type = struct {
      r : u32le::type,
      g : u32le::type,
      b : u32le::type,
    };

    parser = struct {
        r = u32le::parser,
        g = u32le::parser,
        b = u32le::parser,
    };
};

define Bitmap {
    type = struct {
        w : u32le::type,
        h : u32le::type,
        data : Vec Pixel::type,
    };

    parser = struct {
        w = u32le::parser,
        h = u32le::parser,
        data = vec_len_parser Pixel::parser (w * h),
    };
};

define Bmp {
    type = Bitmap::type;
    parser = Bitmap::parser;
};

That would do implicit passing of the buffer around - an extra detail that would be added later. 🤔

from fathom.

brendanzab avatar brendanzab commented on April 28, 2024

Another pass on what a parser combinator IR might look like:

define Pixel {
    type = struct {
      r : u8,
      g : u8,
      b : u8,
    };

    parser =
      (r : u32be) (g : u32be) (b : u32be) =>
        (struct { w, h, data });
};

define Bitmap {
    type = struct {
        w : u32,
        h : u32,
        data : Vec Pixel,
    };

    parser =
      (w : u32be) (h : u32be) (data : many Pixel (w * h)) =>
        (struct { w, h, data});
};

define Bmp {
    type = Bitmap;
    parser = Bitmap;
};

from fathom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.