Git Product home page Git Product logo

Comments (3)

akeep avatar akeep commented on August 11, 2024

The issue here is your use of e0 and e1 in the catamorphisms in the Eval processor of the M->N. The names you use here are actually significant because it is used to determine the type of the processor that should be called (it is not simply recursion to the current processor).

,[e0] is effectively shorthand for ,[e -> e0] (where the first e is determined from looking at the production and determining that an e is what is produced there, so it is looking for there to be an e metavariable in the base. However you are not converting from Math in M to some variant on Math in N, you converting from Math in M to Num in N so you need to use an appropriately named output variable like n0 and n1.

If you were just matching (e.g. not doing a catamorphism) than ((+ ,e0 ,e1) ---) would be correct, since there it would be looking to match an incoming Math` production.

from nanopass-framework-scheme.

akeep avatar akeep commented on August 11, 2024

Ah, sorry you actually also need to give the Num production some sort of metavariable so that you can use it in expressions. Or you could just change your transform to be:

(define-pass M->N : M (e) -> N ()
    (Eval : Math (e) -> number ()
      ((+ ,(n0) ,(n1)) (+ n0 n1))
      ((* ,(n0) ,(n1)) (* n0 n1))
      ((- ,(n0) ,(n1)) (- n0 n1))
      ((/ ,(n0) ,(n1)) (/ n0 n1))
      (,n n)))

All of this is really type driven, and since you've made the type of Eval :: Math -> Num, but Num doesn't have an associated metavariable, you cannot express the type of the processor in metavariables for the catamorphism.

If you did want to keep something that looked more like the original, you could choose a different metavariable for Num, like num to avoid conflicting with other names:

(define-language N
  (terminals (number (n)))
  (Num (num)
    n))
(define-pass M->N : M (e) -> N ()
  (Eval : Math (e) -> Num ()
    ((+ ,(num0) ,(num1)) (+ num0 num1))
    ((* ,(num0) ,(num1)) (* num0 num1))
    ((- ,(num0) ,(num1)) (- num0 num1))
    ((/ ,(num0) ,(num1)) (/ num0 num1))
    (,n n)))

I did notice that it is not possible to have a nanopass language without a nonterminal, which is probably a bug I should fix.

from nanopass-framework-scheme.

gwatt avatar gwatt commented on August 11, 2024

Ah, perfect. Replacing eX with nX in the cataform worked. Thank you!

from nanopass-framework-scheme.

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.