World: r4wp
[#Red] Red language group
older newer | first last |
DocKimbel 22-Dec-2012 [4773] | In other words, we need some kind of Red wrapper (or maybe dialect) on top of Red/System to make it easier to construct programmatically. |
Kaj 22-Dec-2012 [4774] | Sounds right |
DocKimbel 22-Dec-2012 [4775x3] | I haven't had time yet to think about such replacement solution, so ideas are welcome. |
Routine preliminary support pushed. See commit log for examples. The routine! type still needs to be added. | |
Routine! datatype added, reflection is supported. | |
NickA 22-Dec-2012 [4778] | Doc, I'm very glad to see you're still working hard on Red! I was concerned that the psychological effect of everyone paying attention to R3 source, plus your own curiousity about it, might derail you for a while. I'm still eagerly awaiting every advance you make! |
DocKimbel 23-Dec-2012 [4779] | Actually, I still haven't found time to read the whole R3 sources base. I was too busy this week designing some new parts of Red. |
Pekr 23-Dec-2012 [4780x2] | doc, congrats you were accepted to the dev program of Leap motion :-) |
... and yes, please do continue with Red development, I believe that in the end it is good to have rebol like alternative :-) | |
DocKimbel 23-Dec-2012 [4782] | Pekr: thanks, I hope to get the device + SDK in January. My application to their developer program was based on an innovative IDE for Red powered by Leap Motion device. ;-) |
Pekr 23-Dec-2012 [4783] | sounds cool :-) Lately I was wondering about the possible benefits of Red and R3. Difficult to judge, but could there be any overlapping ground, where twose two projects could cooperate? e.g your IDE for R3 to, simply a language would be a plugin, or - both projects want to address Android - could one bridge to JNI be used for both? |
DocKimbel 23-Dec-2012 [4784] | Pekr: I don't know. We'll see how things evolve in the next month. In order to cooperate with R3, it would be first necessary to determine who's really in charge of R3 or what R3 fork should Red cooperate with... :-) |
Pekr 23-Dec-2012 [4785] | I thought it is already coordinated here on Altme :-) Well, my typical what's next for Red? Objects? IO? dyn lib emmiter? Android? :-) |
DocKimbel 23-Dec-2012 [4786x2] | I'm working on objects and ports currently. |
I might release some other features for end of year though. | |
Janko 23-Dec-2012 [4788] | Yes, go Doc! I wish I was better at low-level programming so I could help a little. If there would be any examples of simple bindings or base of TCP that we could extend to different protocols I would try to participate a little. |
DocKimbel 23-Dec-2012 [4789] | Kaj, just a remark about Red and bindings: there is still an additional feature to come that will allow to import both Red/System and external libs functions directly in Red in a declarative way. It will use almost the same syntax as #import in Red/System but will convert the datatypes automatically (in the same way R2 does with routines and structs). A struct! datatype would then be added also to Red. The routine! datatype primary purpose is provide a way to write ultra-fast code and enable system programming, even if it can be also used to wrap Red/System bindings. I'm still unsure which approach would work the best for building bindings to C libraries. I guess you'll be the first to find out. ;-) |
Jerry 23-Dec-2012 [4790] | Red/System Question: In a function, a local variable v1 is declared as struct! [ v2 [integer!] ]. Once the function is called, v1 is in stack, v2 is in heap. When the function call is over, v1 is gone, but v2 is still in heap, right? |
Kaj 23-Dec-2012 [4791x4] | Yes, structs are currently always on the heap |
Well, static memory, actually, if you didn't create it with allocate | |
Doc, thanks for the heads-up. I'm also unsure which route to go, but I want to have the option to write Red/System only programs, so I guess I will usually build a Red binding on a Red/System binding | |
On the other hand, if a binding is mostly the #import section, the future format sounds more concise than writing all wrappers as routines | |
Jerry 23-Dec-2012 [4795x3] | Thanks. Kaj |
### Red/System Question ### To get cpu count, I can do this in C: sysctlbyname("hw.ncpu", &cpuCount, &len, ((void *)0), 0); But Red/System doesn't support &. How can I do this in Red/System? Thanks. | |
&cpuCount, &len are the two parameters that I don't know how to express in R/S. | |
Kaj 23-Dec-2012 [4798x3] | It does support &, but it's written : like in REBOL :-) |
Use :cpu-count :len | |
What does len specify? | |
Jerry 23-Dec-2012 [4801] | len ... the length of buffer in the next parameter??? not sure. |
DocKimbel 24-Dec-2012 [4802] | From Announce: Great Kaj! The optimizer should be able to do a pretty good job on simple cases like Fibonacci function. Still, you'll have the Red stack management overhead, which is currently unavoidable, but in the future, we might found ways to optimize it too. Actually, I have two options to reduce stack overhead: stack multiple openings/closing compression and inlining stack calls, but we'll see that in Red v2. |
Jerry 25-Dec-2012 [4803] | Red/System Questions: I am translating a piece of code from C to Red/System, I don't know how to translate the following C code: success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, (void * volatile *)&_zone_); // C my problems are: 1. In Red/Sys, _sqliteZone_ is a struct! (which is a pointer in Red/Sys), so I cannot use :_zone_ to get it's address. 2. "(void * volatile *)" in C => "as byte-ptr!" in Red/Sys ?? Thanks! |
DocKimbel 25-Dec-2012 [4804] | 1) Is _zone_ a struct or a struct pointer? If it is a struct, then in Red/System, you just pass the struct! variable. 2) Correct, use "as byte-ptr!" in such case. |
Jerry 25-Dec-2012 [4805] | 1. _zone_ is a struct pointer. I need to pass a pointer to a struct pointer as the 3rd parameter, that's why I try to use get-word here. |
DocKimbel 25-Dec-2012 [4806] | For 1., you can achieve it this way: s: declare struct! [n [integer!]] p: declare int-ptr! p/value: as-integer s then `p` becomes a pointer on `s`. I might extend get-word syntax to struct! and pointer! too, someone just needs to add a ticket to Github to remind me of that. |
Jerry 25-Dec-2012 [4807] | Thanks, Doc |
Kaj 25-Dec-2012 [4808x5] | I usually solve such double references by wrapping the needed pointer in an extra struct. See the *-reference! types here: |
http://red.esperconsultancy.nl/Red-common/artifact/aad3c29d7fb6647bb1e5d8b404d05211f5ed33c1 | |
Speaking about atomic operations, any thought to get them in Red/System? I could use them well | |
Perhaps an atomic! type for an integer with guarantees about the generated code? | |
What are the chances that current integer operations already have atomic behaviour? | |
DocKimbel 25-Dec-2012 [4813x3] | I'm not sure what you mean by "atomic operation"? |
Red/System integer! operations are as atomic as the CPU permits. | |
Red/System maps its datatypes as closely as possible to the CPU (the same way C does). | |
Andreas 25-Dec-2012 [4816] | Re atomic operation: atomic "x: x + 1", for example. |
Kaj 25-Dec-2012 [4817x3] | Atomic means safe from corruptions by other CPU cores accessing the same memory |
http://syllable.cvs.sourceforge.net/viewvc/syllable/syllable/system/sys/include/atheos/atomic.h?view=markup | |
These become vital when you start doing multi-core concurrency | |
DocKimbel 25-Dec-2012 [4820] | Ok, I see what you mean. Like in C, you can already write "thread-safe" code in Red/System by using only variables on stack. If you need concurrent access to global variables, usually, the OS are already providing some API for that (locks, semaphores, mutex,...). I haven't chosen yet how it will be implemented at Red/System level, there are different options. For example, it could be handled by the language directly using a similar construct as in Java: synchronize [ x: x + 1 ] In my early design notes, I have researched only how to handle concurrency at Red level, I've left the underlying Red/System part as an "implementation detail". I plan to start working on it after I/O will be implemented. |
Kaj 25-Dec-2012 [4821x2] | I'm thinking about the case where you want to implement operating system level code yourself. For example, I have been fixing many bugs in Syllable's PThreads implementation, but I would like to replace it with a Red/System implementation. PThreads adds quite a few constructs that Syllable's kernel primitives don't implement as such, so to add them you need to write extra concurrency code |
For example, there are spinlock-like constructions in Syllable's PThreads implementation that can often prevent having to call a kernel mutex. This makes them much more efficient, but you need atomic operations on access flags and counters to implement the user-space spinlocks and mutex shells | |
older newer | first last |