Comments (3)
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.
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.
Ah, perfect. Replacing eX
with nX
in the cataform worked. Thank you!
from nanopass-framework-scheme.
Related Issues (20)
- Framework cannot handle languages with simple list of terminals HOT 2
- Terminal names not checked for uniqueness HOT 1
- Nonterminals can have multiple instances of the same production
- Add auto-generation of transformers when the output is the non-language (*)
- Add foldable transformers
- trace does not seem to work properly with multiple return values
- Using nanopass with non-Lispy source language. HOT 2
- not an issue
- Allow wider variety of suffixes for meta-variables.
- trace-define-pass problem on cross compile HOT 3
- trace-define-pass should use current-error-port HOT 2
- Question: check duplicated terms/alts/nonterms/meta-vars, compares symbolically? HOT 2
- Test Fails on Windows 10. HOT 1
- let example didn't work. HOT 2
- Could nanopass-framework-scheme be published on AKKU? HOT 1
- define-pass should work with a language with no nonterminals.
- Need a way to define passes that do not auto-generate transformers.
- Why no top-level cata if the full "in -> out" cata syntax is used? HOT 1
- Other documentation ideas: cheatsheet/table + gentle tutorial HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanopass-framework-scheme.