Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 13 2016 03:25
    @PeterWAWood banned @Vexercizer
hiiamboris
@hiiamboris
so you're on your own
Maciej Łoziński
@loziniak
string/load calls stack/push so I thought buffer already is on top of stack. Anyway, SET_RETURN fixed my problem. Thanks!
Maciej Łoziński
@loziniak
It's interesting, that it worked earlier. Perhaps it was only thanks to it being the only routine called? (no safe_default then)
Do you think I also need SET_RETURN in safe_default routine, and it's only a matter of time when it turns out to be broken without it?
Vladimir Vasilyev
@9214

@loziniak the result of the evaluation is passed at the bottom of the stack frame, not at the top: this is what SET_RETURN macro essentially does for you. Note that 08B78C40 is the same address that ref, the first argument being passed to routine (at the bottom of the stack frame), has.

Your earlier code worked simply because string! slot, pushed by string/load, was already in the right place (since xorurl-base routine has 0 arguments and the evaluation stack was empty).

Maciej Łoziński
@loziniak
Is there any info online on Red stack mechanics?
Maciej Łoziński
@loziniak
Thanks a lot anyway! :-)
hiiamboris
@hiiamboris
Only the source code (:
Greg T
@gltewalt
Related enough to #4247 that I started commenting.
I don't see why it fails. Yet.
Gregg Irwin
@greggirwin
Thanks for digging in @gltewalt. :+1:
Guaracy
@guaracy
ROT-13 in Red and 880 bytes after compiled? Why not? Suggestions are welcome.
Red/System []

#define STDIN      0
#define STDOUT     1

; http://asm.sourceforge.net/syscall.html
#define SYS-write  4 ; ssize_t sys_write(unsigned int fd, const char * buf, size_t count)
#define SYS-read   3 ; ssize_t sys_read (unsigned int fd,       char * buf, size_t count)
#define SYS-exit   1 ; int sys_exit(int status)

#define null-byte  #"^@"
#define rot 13

#syscall [
   write: SYS-write [
       fd      [integer!]
       buffer  [c-string!]
       count   [integer!]
       return: [integer!]
   ]
   read: SYS-read [
       fd      [integer!]
       buffer  [c-string!]
       count   [integer!]
       return: [integer!]
   ]
   quit: SYS-exit [
       status  [integer!]
   ]
]

c: #" "
ix: 0  ; upper = 65, lower = 97, 0 otherwise
s: " " ; for sys_read

case?: func [c [byte!] return: [integer!]][
    if all[c >= #"A" c <= #"Z"][return 65]
    if all[c >= #"a" c <= #"z"][return 97]
    return 0
]

length?: func [str [c-string!] return: [integer!] /local i [integer!]][
    i: 0
    while [str/1 <> null-byte][
        str: str + 1
        i: i + 1
    ]
    return i
]

print: func [msg [c-string!] return: [integer!]][
    write STDOUT msg length? msg
]

getch: func[return: [byte!] /local l][
    l: read STDIN s 1
    if l < 1 [return null-byte]
    return s/1
]

while [true] [
    c: getch
    if c = null-byte [break]
    ix: case? c
    if ix > 0 [
        c: c - ix + rot
        if c >= as byte! 26 [
            c: c - 26
        ]
        c: c + ix
    ]
    s/1: c
    print s
]
quit 0
1 reply
Guaracy
@guaracy
to compile: red -c --no-runtime rot13.reds
hiiamboris
@hiiamboris
:clap:
Gregg Irwin
@greggirwin
Nice!
Muhammad N ElNokrashy
@munael
Hi o/
Where can I find info on FFI from Red programs into C libraries? Closest thing are the full library interface impls like (https://github.com/red/code/tree/master/Library/OpenGL) but those are too much for an intro. Couldn't find anything in the docs (except about LibRed).
Chris J Gallo
@cjglo
anyone have any issue getting that simple-io-minimal.reds file (inside code/Library) to run on linux? Apparently O_CREAT is undefined, yet on windows it works fine
hiiamboris
@hiiamboris
perhaps some refactoring took that constant away? I think you should report it here: https://github.com/red/code/issues
digitalbeat
@digitalbeat
Apologies if this is a dumb question but I have been trying to read and understand or find an example of how to read command line arguments (if any) from a Red program? It appears that this would be a Red/System (function?) but then I haven't been able to find out HOW to use a Red/System function from within a Red program. Any have an example?
To elaborate this works and compiles but how do I do the equivalent in Red? : Red/System []
print ["count: " system/args-count lf]
args: system/args-list
c: 1
until [
print [c ": " args/item lf]
c: c + 1
args: args + 1
args/item = null
]
digitalbeat
@digitalbeat
This (for example) Fails:
Red []
text: "Abc is not cbA"
print text
args: system/args-list
Gregg Irwin
@greggirwin
Not a dumb question at all.
print ["system/options/args:" mold system/options/args]
print ["system/script/args:" mold system/script/args]
digitalbeat
@digitalbeat
@greggirwin THANK YOU! Maybe my Google search foo is way-off but I could not find anything like your answer (which works)! I was trying to create a tiny ham radio callsign lookup utility as a test in (relearning) REBOL/RED and was completely stumped by how to read the command line parameter(s).
Gregg Irwin
@greggirwin
The Rebol Core Guide is a great resource, though not 100% accurate for Red, in cases where our ref docs don't cover something.
That's an important one to note though. Anyone know if we have that in a readme or wiki page?
hiiamboris
@hiiamboris
@digitalbeat if you need smth more advanced: https://gitlab.com/hiiamboris/red-cli/
/args are mentioned there
Gregg Irwin
@greggirwin
I should have thought to mention your CLI @hiiamboris. :^\
François Jouen
@ldci
Hi, I'm playing with syscall under macOS, but I get error.
Compiling to native code... *** Red/System Compiler Internal Error: Script Error : Invalid path value: symbols *** Where: build *** Near: [emit-page-aligned out rejoin job/sections/symbols/2]
François Jouen
@ldci
Code tested with Linux Mint 32-bit: perfectly works. So the problem is specific to macOS, probably to 64-bit calls.
hiiamboris
@hiiamboris
create an issue
LP Olivier
@olivier_lp_twitter
I, is there a documentation for SET_RETURN, I saw it in some script examples, are there others c like operands?
LP Olivier
@olivier_lp_twitter
Is there in red/system function to read/write files?
Boleslav Březovský
@rebolek
@olivier_lp_twitter you can #include this file https://github.com/red/red/blob/master/runtime/simple-io.reds to get file IO. Or call OS functions directly.
8 replies
hiiamboris
@hiiamboris
SET_RETURN can be found in the source code (macros.reds).
2 replies
Christian Ensel
@gurzgri

When manipulating blocks in routine's Red/System code, creating blocks in blocks there and creating many boxed an unboxed red-values in these, it is — so I guess —, always a certain sign of me doing sth. wrong when I get visual signs of GC kicking in with messages like

root: 6474/107152, runs: 2, mem: 3252744 => 2651976, mark: 7.9ms, sweep: 1.0ms

right? If so, it must happen somewhere in a > 4000 LOC script (2/3 Red/System, 1/3 Red code). So far I had no luck in breaking it down in a digestable minimal example to reproduce the issue. Hence just this top-levekl question. What are the most common traps I should avoid wrt to these messages? Any advice or pointers would be much appreciated.

hiiamboris
@hiiamboris
What's wrong with GC kicking in?
Oldes Huhuman
@Oldes
You want to lower such a need as much as possible.
So problem is not GC, but that there is creating many boxed an unboxed red-values, which needs to be released.
Gregg Irwin
@greggirwin
I asked Nenad, and he said the same thing.
Christian Ensel
@gurzgri
GC kicking in of course isn't a problem - the strange GC output cited above is. Or was, as I should rather say: It never occurred to me that they go away when compiling in --release mode i/o --compile development mode. Sometimes you just have to ask to give yourself the answer ...
hiiamboris
@hiiamboris
:+1:
Christian Ensel
@gurzgri

Given I have a value bin of type red-binary! cointaing UTF-16LE string bytes, how can I treat that as a red-string! in R/S?

str: as red-string! as red-value! bin
set-type as red-value! str TYPE_STRING
series: GET_BUFFER(str)
series/flags: series/flags or flag-UTF16-cache
SET_RETURN(str)

isn't sufficient, it returns {A^@B^@C^@ä^@ö^@ü^@ß^@A^@B...}, not {ABCäöüßAB...}.

Ideally without loading it in a new string as string/load would do even I could load from the binary node's series.
Christian Ensel
@gurzgri
Giving me the answer myself:
---     series/flags: series/flags or flag-UTF16-cache
+++     series/flags: series/flags and flag-unit-mask or UCS-2