World: r3wp
[Tech News] Interesting technology
older newer | first last |
BrianH 14-May-2007 [2232x2] | One of the tricks you would need is to realize that there is no "REBOL" language. Each dialect is semantically a seperate language, with a different execution model. You can't treat REBOL data as a particular dialect until you know which one, and you often don't know until runtime. Because of this you would have to compile at runtime, or at least function build time. Any attempt to compile ahead of time would change the semantics, in a similar way to how prebol does. Even at runtime the semantics would be different, but not as different as you think. Few people realize that while the DO dialect looks a lot like a Lisp or Scheme clone, its underlying semantics are quite different - and yet they still are able to program in REBOL just fine. You could change the underlying semantics to a completely different model and keep all but the most guru of programming similar enough that most people won't notice the difference. The only main change would be to make the code blocks of compiled functions unchangeable once the function is built - so no more patching running code. |
Don't expect too much of a speedup though. REBOL is really fast already, and runtime compilation has some overhead itself. | |
Volker 14-May-2007 [2234x3] | Yes, compilation must be done on block-level, and preferably after the block has already been interpret. to find function-boundaries. but self could go half as fast as c, and hotspot even faster. while switching back and forth between compiled and interpreted code. |
and for scripting there would be a slowdown, except if the vm could store the results of the compilation as exe, with the original interpreter-code. kind of quick loadable memory-dump. | |
(dont ask me how that works, i only know some system can do it) | |
btiffin 14-May-2007 [2237] | Volker; Thank you. Your parsing data code made me and REBOL look like heroes today. :) Another happy boss, less afraid of his computer. We all win. Thanks! |
Oldes 14-May-2007 [2238] | I really would like to see some of my functions compilable, using rebcode or something else... Since I'm now working on a new version of my rebol/flash dialect, I found very difficult to bind functions into another (recursive) function's context. At this moment I still have to define these "inside" functions in the recursive function always when I call it, so it must be slower. Maybe it would be enough form me, just to have some more easy and fast way how to get such functions into specified context. But maybe I just have bad approach. |
JaimeVargas 14-May-2007 [2239x6] | (f a b) *must* be quoted or be in a quoted list (maybe using the funny" way of quoting available for macros ;) for it not being a function call." This is simply not true. Not with syntax-case macros. You need to know that Scheme Macro system is different and a lot better than the one used by lisp as pointed by the article. |
See example 6. That introduces a macro for setters and getters, and depending the position of the variable it behaves one way or another. | |
I don't think the compilation of Rebol language has anything to do with CPU features. But CPU are algorithms in silicon, so maybe you could in the future expedite branch searching. | |
And regarding quotation, every block in rebol is quoted in the sense that it is just data. It only acquires meaning when passed thru some form of evaluation. Like DO or a Func eval on a block. Square Bracket become the form (quote arg ...) of Scheme. | |
Regarding the conclusing I find this base less. There is nothing missing in Scheme. The first Rebol interpreter was written in Scheme. I already said this both languages are Turing complete so they can perform the same computations. As I said the topic of compilation vs interpretation is arid regarding PLD. But compilation vs compilation is important for performance considerations and for bootstrapping. | |
Compiling Scheme to Rebol has nothing to do with that argument. imo. | |
Volker 15-May-2007 [2245x2] | There is nothing missing in scheme, but there is something missing in rebol :) Lots of parens for example. To solve such situations, rebol needs runtime-informations. Which function do i have here at this moment, with how many arguments? Without that information the meaning of some code is not clear, and it is only available at runtime. So early macros have no chance here. Then there are dialects. They are data with rebol inside. Which parts of a parse-rule can be compiled to rebol? Could work if 'parse is a macro, up to some point. But then there is vid. A macro would need to write a lot [ make face[] ]. Such things grow big. And even then, look at [text a b] . At runtime this is easy, [a: 60x24 b: "Hello Scheme"], no problem. At macro-time no chance IMHO. Scheme can be compiled to rebol, because a scheme-programmer has to give enough informations at compile-time. Rebol can not be compiled to scheme because rebol lacks that information. Making the life for the programmer easier, because more can be implicit. Scheme could interpet dialects too, but then its no longer compiled. ANd it can not as good, because rebol-data can reference locals. Symbols with context. And scheme can not AFAIK, symbols are only unique strings. (i still hope i miss something, maybe a schemer would use little closures?) |
(MY first counter: making to much implicit actually makes life for programmers harder, when he reads it. But that holds for large programms, and rebol is optimized for small. | |
Gabriele 15-May-2007 [2247x2] | the first rebol interpreter was written in C (not Scheme) by a Schemer... and indeed it was *not* rebol and Carl had to rewrite it from scratch. :) |
so, if there's nothing missing in scheme, i challenge you to write a translator from rebol to scheme. i will do a translator from scheme to rebol if you want me to. this has nothing to do with being turing complete. brainfuck is turing complete, but don't tell me it's the same as scheme. | |
Henrik 15-May-2007 [2249] | i will do a translator from scheme to rebol if you want me to. <--- don't you have R3 stuff to do? :-) |
Gabriele 15-May-2007 [2250x2] | do you expect me to do that overnight? ;) also, i think it's very easy to do. (a translator does not mean that all the function are then available, just that you translate code, and as long as you define the functions in rebol, then you can evaluate it) |
and anyway, i don't think jaime will ever be able to do a rebol>scheme so there's no problem ;) | |
Maxim 15-May-2007 [2252x3] | although I'm not an expert on languages (even if I have been fiddling with antidote a bit) the binding of code in REBOL seems to be the compilation killer. the fact that any data only gets meaning when a particular part of code is reached and depending on the current state of the whole heap, means its impossible to compile by default. |
btw, trying to bring the discussion to a less tech level ;-) some people are way lost here ;-) I know I am just at the edge of understanding! | |
but wouldn't the bind command and any internal rebol binding, be in fact where the JIT calls are made? aren't these explicit points in time where a JIT could be applied? | |
btiffin 15-May-2007 [2255] | It is Relative Expression Based... :) Human hinting in source code may alleviate some of the late binding issues, but I'd think a REBOL compiler would always need access to the interpreter at runtime (or JIT compile component like you said), or restrict use of external code loaders in compiled code and a myriad of other features. |
Maxim 15-May-2007 [2256x2] | as brian said, the vast majority of rebol code can be compiled, but I also know that 100% of my gui using code cannot, cause of a patch in glayout ;-) |
things like insert second myfunc [print "hehe"] can't be compiled... | |
JaimeVargas 15-May-2007 [2258x5] | Gabriele, Just look at Sherman. A Rebol to Scheme compiler. |
Written by Joe Marshall. | |
Maxim your code modifications to predifine mezzanies could be compiled. | |
Let me restate the problem with rebol and compilation is not that is impossible. It is just not practical without given some dynamism. | |
The dynamism that makes compilation hard is related to the order of execution of certain code. | |
btiffin 15-May-2007 [2263] | Jaime; I think Maxim might be pointing out that the [print "hehe"] may not be know. It could be external or generated etc... But I don't want to speak for Maxim, it was a feature I was thinking about. |
JaimeVargas 15-May-2007 [2264] | The majority of the code in rebol follows a straight line. But you can make that straight line have a twist depending on the order of evaluation for some expressions. Which a compiler can predict. Because this predictions can be broken with any function call the compiler must pick one branch of the call-tree. Which may not be what the programmer intended. |
Maxim 15-May-2007 [2265] | Let me rephrase my sentence... ;-) can't be pre-compiled... only a JIT could detect that and then make a copy of the (new) compiled function and start using its new pointer. |
JaimeVargas 15-May-2007 [2266] | Yes. But those type of code modifications are easy to tackle by current compilations techniques. |
Maxim 15-May-2007 [2267x3] | it obviously depends where that code insertion is done no? think about a situation where the insert is done in a button action.... how could the compiler understand that? |
binding is done when the dialect is parsed... so only a JIT could detect that no? | |
unless they invented a new compiler called HAL ;-) | |
JaimeVargas 15-May-2007 [2270] | The exponential problem of compiling a call-tree becomes impractical as the number of functions increases. There are some techniques to mitigate this, but rebol is atypical in the sense that his CFG lacks any punctuation. Without punctuation there is no easy way to determine where the expression begin or end. |
Maxim 15-May-2007 [2271x2] | true. |
which is why we all like it ;-) | |
JaimeVargas 15-May-2007 [2273x3] | A compiler works at the expression level. Thats the reason in Scheme anything between parens is considered a compilation unit. The same for C anything between not white space and the semicolon. |
I am not 100% sure that having no punctuation is great. There is some very cryptic one liners that it takes two or three times checking before figuring out what it is doing. | |
Not only because the expression maybe cryptic but also because you need to keep track of context and state in your head. | |
btiffin 15-May-2007 [2276] | I love the REBOL rarity lexical scanning. Drove me nuts at first, it looked reverse polish, as an ex-forther, that was a hard one to get round. But now...no going back :) |
JaimeVargas 15-May-2007 [2277] | Which can make debugging a bit difficult if one it is not disciplined enough. |
Maxim 15-May-2007 [2278] | jaime: yes, when these occur in my head I sometimes add parens... just to make it easier to update later on. |
JaimeVargas 15-May-2007 [2279] | Gabriele, "brainfuck is turing complete, but don't tell me it's the same as scheme". Well it depends on what you mean by sameness. I am using Turing Complete as the base of the definition. Because if the language is Turing Complete you can construct an emulator of any other language. After all that is needed is bits, memory and register to carry out any computation. It maybe hard to make a Rebol interpreter in brainfuck but it is certainly possible. |
Maxim 15-May-2007 [2280] | but you'd need about IQ 5000 to get it done...which probably means only an alien could get it done ;-) |
JaimeVargas 15-May-2007 [2281] | Nah. You make the compiler of C to brainfuck. Take Orca's C source compile to brainfuck and you are done. |
older newer | first last |