-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add pre-processer into Processing.R #9
Comments
processing
prefix in built-in function calls
processing
prefix in built-in function calls
See http://stackoverflow.com/questions/2439782/overload-with-different-return-type-in-java And there is one thing else should be noticed: The implementation of built-in alpha function is tricky, I don't know why I can't define two function: public double alpha(int rgb) {
}
public float alpha(int rgb) {
} in one class, javac tells me that they are one function, and it is an override function. It seems that same function name, same parameter lists and different return types is treated as override, not overloading. Pre-processor should solve this problem. |
Have you looked at the Processing default (Java mode) preprocessor? https://github.com/processing/processing/tree/master/java/src/processing/mode/java/preproc I'm not familiar with it but I believe it is based on ANTLR -- quite complex and heavy-duty, but it might give you some ideas for reusing parts or for just making a very lightweight R preprocessing. Once you have studied it if you have questions you could consult with @JakubValtar and @benfry |
IMO, the goal of pre-processor is to reorganize the code and transfer the syntax sugars to regular syntax. Then we need a tokenizer and a parser to achieve this. I am not sure if renjin could do that. I will have a look before the implementation. BTW, processing.py's pre-processor is another way. It parses the AST from the code as the standard python and does some operations in the AST to achieve the same goal. |
Nice example from processing.py's pre-processor. Is there is a similar AST library approach available for Java? That might work. If I understand you, the single biggest pre-processor issue right now is identifying a list of implemented functions If I'm understanding the big problem correctly, renjin parses R for JVM -- because it isn't "translating R into Java" there is no way to simply use these aspects of Processing's Java pre-processor. This would be ideal, but is impossible. |
The big problem is right, and renjin could not access Java AST. But I think there may be some tools that could access R AST. Code could be re-organized in R before it is sent to renjin to parse. |
Different return type is not enough to make two functions different. Having two different return types introduces ambiguity into the type system. As for Java, you should leave only The question is what are you trying to achieve here? Processing uses only float foo() {
return 1.23f;
}
void setup() {
float f = foo();
double d = foo();
} The other way around is narrowing and you have to tell the compiler that you are aware that some data will be lost: double bar() {
return 1.23;
}
void setup() {
double d = bar();
float f = (float) bar(); // cast to float, otherwise you get a compiler error:
} // Type mismatch, double does not match with float I will write you a general overview of our Java preprocessor later this week, as I'm busy with school these days. |
Oh, It is my fault. Widening conversion works for alpha. Pre-processor in Processing.R is to remove the prefix. ref https://forum.processing.org/two/discussion/comment/90747/#Comment_90747 And thank you for the overview. It is not so urgent 😄 We will start to write pre-processing logic after a few weeks. |
@gaocegege -- Regarding pre-processing to remove the
Regarding the second half of pre-processing -- is http://www.r-fiddle.org/#/fiddle?id=k5Ytlpdb ...and I didn't see any. The closest I saw was Processing's It still might be a good idea to simply pre-process |
ref https://stat.ethz.ch/R-manual/R-devel/library/stats/html/line.html
|
Got it. I should have checked the whole core, not just built-ins!
Line is a good example / test case of namespace collision, then.
…On Fri, May 19, 2017 at 17:30 Ce Gao ***@***.***> wrote:
ref https://stat.ethz.ch/R-manual/R-devel/library/stats/html/line.html
line is in stats package in r-core. I have tried to define the function
directly, and it doesn't works.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAwvaon6sVPi8q8fVyWZCQJ2X_b11ZrAks5r7jQogaJpZM4MU_xS>
.
|
Yeah, r-core and r-dev are the main dependencies for R 😄 |
Yet another potential solutionThere is one function |
Attach couldn't work since But I have a new idea: write a renjin extension(package) to package processing and run |
AST way like processing.pyTool: https://github.com/graalvm/fastr or https://github.com/bedatadriven/renjin Just a reminder to me. |
RParserTest in renjin is helpful to understand the RParser in renjin, which may be used to pre-parse the code. |
P3D <- "processing.opengl.PGraphics3D"
box <- function(...) {
processing$box(...)
}
P3D <- "processing.opengl.PGraphics3D"
settings <- function() {
processing$size(100, 100, P3D)
}
setup <- function() {
processing$noLoop()
}
draw <- function() {
processing$translate(58, 48, 0)
processing$rotateY(0.5)
processing$noFill()
box(40, 20, 50)
} I think I find a better way than AST or regex: define functions in an R script and evaluate it before the sketch, the evaluate the sketch, just like processing.py's preprocessor does. |
Thes functions are not defined in PApplet, need to deal with them manually. Wont fix:
TODO
|
Great list! I believe that some of these functions (like sin cos atan2) also have R equivalent built-ins. So one question is whether to map those function manually or whether to leave them accessing their default R built-ins. We should eventually choose a policy that makes sense -- either mapping everything to Processing, or keeping certain categories of things "native" to R. |
Yes, I think if these functions have same behavior as in Processing, there if no need to put them in a new category 🤔 If they have different behaviors, tag them and show in different color or something else. |
ref https://forum.processing.org/two/discussion/comment/90750/#Comment_90750
implement the pre-processor to solve the problem
The text was updated successfully, but these errors were encountered: