REBOL
Downloads Products Documents Community

RebCode - Opcode Reference

Make-time ("assembled") operations

Branch targets are only implemented for outer blocks. Eventually we will need to do the branch compuations on all subblocks. Note also that branches cannot jump outside blocks.

Note that disassembly of BRA target words (which become relative integers after the assemble) can be reconstructed by the fact that LABEL is embedded in the code and holds the target word.

I've found branches not to be very useful. The sub-block method is just as fast and is truly recursive within the VM.

IMPORTANT! target labels are modified when the code is assembled; they become numeric offsets from the branch to the target location. Look at this example:

system/internal/assemble [[] [
[           set a 0
[           bra keep-0
[           set a 1
[           label keep-0
[           ?? a
[          ]]
== [
    set a 0
    bra 4       ; keep-0 was replaced by 4
    set a 1
    label keep-0
    ?? a
]

This holds true for all branching opcodes that take a label as a target. You can see how it works by reading the source code for system/internal/assemble.

bra

(Branch, unconditional) Jump to computed target (word modified!)

Arg

Type

Description

target

[word!]

         

Notes and Examples

fn: rebcode [] [
    set a 0
    bra keep-0
    set a 1
    label keep-0
    ?? a
]

brab

Branch block table

Arg

Type

Description

targets

[block! word! integer!]

         

index

[word!]

         

Notes and Examples

braf

Branch to target if the T flag is not set.

Arg

Type

Description

target

[word! integer!]

Must be a word! for the assembler

         

Notes and Examples

fn: rebcode [] [
    set  a 0
    eq.i a 1
    braf keep-0
    set  a 1
    label keep-0
    ?? a
]

brat

Branch to target if the T flag is set.

Arg

Type

Description

target

[word! integer!]

Must be a word! for the assembler

         

Notes and Examples

fn: rebcode [] [
    set  a 0
    eq.i a 0
    brat keep-0
    set  a 1
    label keep-0
    ?? a
]

comment

Includes a comment in the code

Arg

Type

Description

value

[any-type!]

         

Notes and Examples

The COMMENT opcode allows all datatypes. Its main intentions are both:

comment "This is a code comment"

comment [    ; commenting out code sections, but not removal of those sections.
    add.i n 1
    eq.i  n 10
]

COMMENTs are embedded - they remain within the code, even on molding.

label

Define target label; used as literal (symbolic no-op)

Arg

Type

Description

target

[word!]

         

Notes and Examples

count: rebcode [counter] [
    set i 0
label work-loop
    add.i  i 1
    sub.i  counter 1
    eq.i   counter 0
    brat   all-done
    bra    work-loop
label all-done
    return i        
]

Here is a simple factorial function that uses labels and branches:

!: factorial: rebcode [
    n [decimal!] "Decimal, not integer, for increased range." 
    /local res
] [
    set   res 1.0
    eq.d  n 0.0
    brat  done  ; if n is zero, return 1
label iter
    mul.d res n
    sub.d n 1.0
    eq.d  n 0.0 ; loop while n is not zero
    brat  done
    bra   iter  
label done
    return res
]

This factorial function is a good example of something that really isn't a good candidate for rebcod'ing. True, it's about 10 times faster than plain REBOL, but if you really need speed for a function like this, you may be better off with a memoization approach, if that can be done.

Evaluation and Assignment

apply

Apply a function to arg block. Set result.

Arg

Type

Description

result

[word!]

         

func

[word!]

         

args

[block! word!]

         

Notes and Examples

It should work for rebcode funcs, normal funcs, natives, and datatypes actions. But, needs a lot more testing.

Format: apply result func [???arg1] in docs/rebcode-ops.txt

The block is not reduced, but the args can be words or values. If func needs more args than have been provided, remaining formal args are set to NONE. Refinements, if required. must appear in proper position in the arg block.

Examples:

apply data read [http://www.rebol.com]
apply time now []
apply year now [true] ; /year refinement
apply year now [none true] ; /month refinement
apply year now [none none true] ; /day refinement

Note: Recursion needs testing. Also possible GC problems may come up. Keep watch on it.

do

Escape to normal evaluation. Result modified.

Arg

Type

Description

result

[word!]

         

input

[block!]

         

Notes and Examples

do img [load %nyc.jpg]

Even if you don't need the result of do, if you are just using it for side effects, you still need to supply a result target.

do dummy [a: 10  b: 20]

getw

Get the value of a word (indirect). Result modified.

Arg

Type

Description

result

[word!]

         

word

[word!]

         

Notes and Examples

fn: rebcode [] [
    do    r [a: 10 b: 'a]
    getw  i b
    print i
    set   i b
    print i
]

gett

Get the T flag and store in a variable. Operand modified.

Arg

Type

Description

operand

[word!]

         

Notes and Examples

fn: rebcode [] [
    set    val 1
    eq.i   val 0
    gett   flag
    return flag
]

set

Set a variable to any value. Operand modified.

Arg

Type

Description

operand

[word!]

         

value

[any-type!]

         

Notes and Examples

set i 100
set d 123.45
set s "Testing..."

Set is slower than set.i and set.d because it has to handle all data types. Use it to set initial values, then use the type specific opcodes for maximum optimization.

set.d

Set decimal variable only. Operand modified.

Arg

Type

Description

operand

[word!]

         

value

[decimal! word!]

         

Notes and Examples

set   d 0.0
set.d d 123.45

The operand must already refer to a decimal value. Use set to set in initial values and set.d where the optimization will help.

set.i

Set integer variable only. Operand modified.

Arg

Type

Description

operand

[word!]

         

value

[integer! word!]

         

Notes and Examples

set   i 0
set.i i 100

The operand must already refer to a decimal value. Use set to set in initial values and set.i where the optimization will help.

sett

Set the T flag from contents of a variable

Arg

Type

Description

value

[word!]

         

Notes and Examples

fn: rebcode [] [
    set    val 1
    sett   val
    gett   flag
    return flag
]

setw

Set the value of a word (indirect). Word modified.

Arg

Type

Description

word

[word!]

         

value

[any-type!]

         

Notes and Examples

fn: rebcode [/local a b i] [
    do    r [a: 10  b: 'a]
    print [a b i]
    setw  b 25
    getw  i b
    print [a b i]
    getw  i a
    print [a b i]
]

Run-time control

breakf

If the T flag is not set, break out of the currently executing block

Arg

Type

Description

Notes and Examples

breakf-test: rebcode [n [integer!]] [
    set i 0
    while [lt.i i 1000] [
        add.i i 1
        neq.i i n
        breakf
    ]
    return i
]

Note that breakf (and breakt) cause the rebcode fuction to return an unset value if used at the top level, i.e. not in a block. This is the same result you get when no return opcode is used in a rebcode function.

breakf-no-block: rebcode [] [
    breakf
    return 2
]

breakt

If the T flag is set, break out of the currently executing block

Arg

Type

Description

Notes and Examples

See breakf for examples.

return

Exits a rebcode function, reurning the value.

Arg

Type

Description

result

[any-type!]

         

Notes and Examples

If you don't use the return opcode, a rebcode function will return an unset! value. This is different not the same behavior as a REBOL function, where the last expression evaluated is returned automatically.

return*: rebcode [/local i] [
    set    i 100
    return i
]

exit

Exits a rebcode function, returning no value.

Arg

Type

Description

Notes and Examples

The exit opcode works just like the REBOL exit function.

iff

If-false; if the T flag is not set, evaluate the block.

Arg

Type

Description

then-block

[block!]

         

Notes and Examples

lt.i n 100
iff  [add n 100]

The difference between iff in rebcode and if in REBOL is that, in rebcode, the condition (the T flag) is implicit, and no value is returned.

ift

If-true; if the T flag is set, evaluate the block.

Arg

Type

Description

then-block

[block!]

         

Notes and Examples

gt.i n 100
iff  [sub n 100]

The difference between ift in rebcode and if in REBOL is that, in rebcode, the condition (the T flag) is implicit, and no value is returned.

either

If the T flag is set, evaluate the first block; otherwise evaluate the second block.

Arg

Type

Description

true-block

[block!]

         

false-block

[block!]

         

Notes and Examples

The difference between EITHER in rebcode and EITHER in REBOL is that the condition is the T flag in rebcode, and no value is returned.

my-min*: rebcode [m [integer!] n [integer!] /local res] [
    lteq.i m n
    either [set res m] [set res n]  ; can't do "set res either..."
    return res
]

loop

Evaluates the block a specified number of times.

Arg

Type

Description

count

[word! integer!]

         

block

[block!]

         

Notes and Examples

count-to-10: rebcode [] [
    set   a 0
    loop  10 [add.i a 1]
    print ["loop 10:" a]
]
factorial: rebcode [
    n [integer!] 
    /local res d
] [
    set res 1.0
    set d   0.0
    loop n [
        add.d d 1.0
        mul.d res d
    ]
    return res
]

repeat

Evaluates a block a number of times or over a series.

Arg

Type

Description

word

[word!]

Word to set each time

         

value

[word! integer!]

Number of of times to repeat

         

body

[block!]

Block to evaluate each time

         

Notes and Examples

fn: rebcode [n] [repeat i n [print i]]
fn 4

sum-decimals: rebcode [
    block [block!] "All values must be decimals"
    /local result len val
][
    set  result 0.0
    length? len block
    eq.i len 0
    either [return result] [
        repeat i len [
            pick   val block i
            to-dec val val
            add.d  result val
        ]
    ]
    return result
]

See also: repeatz

repeatz

Zero-based repeat (0 to n-1)

Arg

Type

Description

word

[word!]

Word to set each time

         

value

[word! integer!]

Number of of times to repeat

         

body

[block!]

Block to evaluate each time

         

Notes and Examples

fn: rebcode [n [integer!]] [repeatz i n [print i]]
fn 4

See also: repeat

until

Evaluate a block until the T flag is set

Arg

Type

Description

block

[block!]

         

Notes and Examples

do rebcode [] [
    set a 0
    until [
        add.i  a 1
        gteq.i a 10
    ]
    print ["until:" a]
]

while

While the condition block sets the T flag, evaluate the body block.

Arg

Type

Description

cond-block

[block!]

         

body-block

[block!]

         

Notes and Examples

do rebcode [] [
    set a 0
    while [lt.i a 10] [
        add.i a 1
    ]
    print ["while:" a]
]

Datatype

to-dec

Convert integer to decimal. Operand modified.

Arg

Type

Description

operand

[word!]

Must refer to an integer or decimal

         

Notes and Examples

to-dec: rebcode [n [number!]] [
    to-dec n  
    return n
]

to-int

Convert decimal to integer. Operand modified.

Arg

Type

Description

operand

[word!]

Must refer to an integer or decimal

         

Notes and Examples

to-int: rebcode [n [number!]] [
    to-int n  
    return n
]

type?

Sets the operand to the value's datatype.

Arg

Type

Description

operand

[word!]

         

value

[word!]

         

Notes and Examples

type?*: rebcode [word] [
    type?  res word
    return res
]

type?* "test"
string!
type? type?* "test"
datatype!
type?* <124>
tag!

value?

Set T flag if the variable has a value.

Arg

Type

Description

value

[word!]

         

Notes and Examples

value?*: rebcode [word] [
    value? res word
    return res
]

Bitwise operations

These opcodes modify the operand

and

Bitwise AND of two integers; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

         

Notes and Examples

and*: rebcode [operand [integer!] value [integer!]] [
    and    operand value
    return operand
]
and* 170 15
10

bswap

Byte swap. Converts integer endian-ness.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

Notes and Examples

bswap: rebcode [value [integer!]] [
    bswap  value 
    return value
]
bswap 1
bswap -2134897137

Note that the sign is not preserved.

bswap -32768
8388608
bswap 32767
-8454144

compl

Bitwise complement.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

Notes and Examples

compl*: rebcode [operand [integer!]] [
    compl  operand
    return operand
]

compl* 0
-1
compl* -1
0
compl* 1
-2
compl* 32767
-32768

See Also: NOT

ext8

Sign extend; 8-bits to integer

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

Notes and Examples

Expands an 8-bit value to 32-bits, filling new bits with the same value as the sign bit in the original 8-bit value.

ext8: rebcode [n [integer!]] [
    ext8   n
    return n
]
ext8 255
-1
ext8 127
127
ext8 128
-128
ext8 144
-112

ext16

Sign extend; 8-bits to integer

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

Notes and Examples

Expands an 16-bit value to 32-bits, filling new bits with the same value as the sign bit in the original 16-bit value.

ext16: rebcode [n [integer!]] [
    ext16  n
    return n
]
ext16 32768
-32768
ext16 32767
32767
ext16 65536
0
ext16 65535
-1

lsl

Logical Shift left; toward MSB.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

Number of bits to shift, mod 32

         

Notes and Examples

A left shift is the same as multiplying by two for each bit shifted.

Integers are signed values in REBOL, and the sign bit is just another bit as far as lsl is concerned, shifting a bit into the sign bit will make the result a negative value. Conversely, you can shift the sign bit out of a value and it will become positive (as far as REBOL is concerned).

lsl: rebcode [operand [integer!] value [integer!]] [
    lsl    operand value
    return operand
]
lsl 32 5
1024
lsl 65'535 24
-16777216
lsl -2147483648 1
0

See also: lsr, rotl, rotr

lsr

Logical Shift right; toward LSB.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

Number of bits to shift, mod 32

         

Notes and Examples

A right shift is the same as dividing by two for each bit shifted.

lsr: rebcode [operand [integer!] value [integer!]] [
    lsr    operand value
    return operand
]
lsr 1024 5
32
lsr 65'535 8
255

See also: lsl, rotl, rotr

not

Logic datatype complement

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

Notes and Examples

not*: rebcode [operand [integer!]] [
    not    operand
    return operand
]
not* 0
1
not* -1
0
not* 1
0

See Also: COMPL

or

Bitwise OR of two integers; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

         

Notes and Examples

or*: rebcode [operand [integer!] value [integer!]] [
    or     operand value
    return operand
]
or* 170 15
175

rotl

Rotate left; toward MSB.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

Number of places to rotate, mod 32

         

Notes and Examples

A rotate is a shift that wraps around.

rotl: rebcode [operand [integer!] value [integer!]] [
    rotl   operand value
    return operand
]
rotl 65'535 24

rotr

Rotate right; toward LSB.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

Number of places to rotate, mod 32

         

Notes and Examples

A rotate is a shift that wraps around.

rotr: rebcode [operand [integer!] value [integer!]] [
    rotr   operand value
    return operand
]
rotr 65'535 8

xor

Bitwise XOR of two integers; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer

         

value

[word! integer!]

         

Notes and Examples

xor*: rebcode [operand [integer!] value [integer!]] [
    xor    operand value
    return operand
]
xor* 170 15
165

Integer and Decimal Math

These opcodes modify the operand

abs.i

Changes the operand to its absolute value.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

Notes and Examples

abs.i: rebcode [operand [integer!]] [
    abs.i  operand
    return operand
]
abs.i -10
10

abs.d

Changes the operand to its absolute value.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

abs.d: rebcode [operand [decimal!]] [
    abs.d  operand
    return operand
]
abs.d -10.0
10.0

add.i

Integer add; adds operand and value; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word! integer!]

         

Notes and Examples

add.i: rebcode [operand [integer!] value [integer!]] [
    add.i  operand value
    return operand
]
add.i 10 20
30

If either value is not an integer, the results are undefined.

add.d

Decimal add; adds operand and value; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value

[word! decimal!]

         

Notes and Examples

add.d: rebcode [operand [decimal!] value [decimal!]] [
    add.d  operand value
    return operand
]
add.d 10.5 20.5
31.0

If either value is not a decimal, the results are undefined.

div.i

Divides operand by value; the integral result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word! integer!]

         

Notes and Examples

div.i: rebcode [operand [integer!] value [integer!]] [
    div.i  operand value
    return operand
]
div.i 34 3
11
div.i 34 7
4

div.d

Divides operand by value; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value

[word! decimal!]

         

Notes and Examples

div.d: rebcode [operand [decimal!] value [decimal!]] [
    div.d  operand value
    return operand
]
div.d 34.0 3.0
11.3333333333333
div.d 34.0 7.0
4.85714285714286

max.i

Sets the operand to the greater of the two values.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word integer!]

         

Notes and Examples

max.i: rebcode [m [integer!] n [integer!]] [
    max.i  m n 
    return m
]
max.i 10 30
30
max.i 50 30
50

max.d

Sets the operand to the greater of the two values.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value

[word! decimal!]

         

Notes and Examples

max.d: rebcode [m [decimal!] n [decimal!]] [
    max.d  m n 
    return m
]
max.d 10.0 30.0
30.0
max.d 50.0 30.0
50

min.i

Sets the operand to the lesser of the two values.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word! integer!]

         

Notes and Examples

min.i: rebcode [m [integer!] n [integer!]] [
    min.i  m n 
    return m
]
min.i 50 30
30
min.i 10 30
10

min.d

Sets the operand to the lesser of the two values.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value

[word! decimal!]

         

Notes and Examples

min.d: rebcode [m [decimal!] n [decimal!]] [
    min.d  m n  
    return m
]
min.d 50.0 30.0
30.0
min.d 10.0 30.0
10.0

mul.i

Multiplies operand by value; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word! integer!]

         

Notes and Examples

mul.i: rebcode [operand [integer!] value [integer!]] [
    mul.i  operand value
    return operand
]
mul.i 10 20
200

mul.d

Multiplies operand by value; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value

[word! decimal!]

         

Notes and Examples

mul.d: rebcode [operand [decimal!] value [decimal!]] [
    mul.d  operand value
    return operand
]
mul.d 10.0 20.0
200.0

neg.i

Negate. Changes the sign of the operand

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

Notes and Examples

neg.i: rebcode [operand [integer!]] [
    neg.i  operand 
    return operand
]
neg.i 100
-100
neg.i -100
100

neg.d

Negate. Changes the sign of the operand

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

neg.d: rebcode [operand [decimal!]] [
    neg.d  operand 
    return operand
]
neg.i 100.0
-100.0
neg.i -100.0
100.0

randz

Zero-based random number generator; sets operand to value from 0 to (value - 1).

Arg

Type

Description

value

[word!]

Must refer to an integer value

         

Notes and Examples

randz*: rebcode [value [integer!]] [
    randz  value
    return value
]
loop 20 [prin [randz* 5 " "]]
print ""

rem.i

Remainder. Divides operand by value; the integer remainder goes in the operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word! integer!]

         

Notes and Examples

rem.i: rebcode [operand [integer!] value [integer!]] [
    rem.i  operand value
    return operand
]
rem.i 34 3
1
rem.i 34 7
6

There is no decimal equivalent for rem.

sub.i

Subtracts value from operand; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value

[word! integer!]

         

Notes and Examples

sub.i: rebcode [operand [integer!] value [integer!]] [
    sub.i  operand value
    return operand
]
sub.i 100 5
95

sub.d

Subtracts value from operand; result goes in operand.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value

[word! decimal!]

         

Notes and Examples

sub.d: rebcode [operand [decimal!] value [decimal!]] [
    sub.d  operand value
    return operand
]
sub.d 100.0 5.5
94.5

Decimal Math Functions; no integer equivalents.

Many of these functions have REBOL equivalents. The difference is that the operand is modified by these functions, where the REBOL versions return a result.

sqrt

Square-root

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

exp

Exp

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

log-10

Log-10

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

log-e

Log-e

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

cos

Cosine

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

sin

Sine

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

tan

Tangent

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

acos

Arccosine

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

asin

Arcsine

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

atan

Arctangent

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

Notes and Examples

Logical Comparisons

These functions set the T flag; the operand is not modified.

eq.i

Sets the T flag if the values are equal.

Arg

Type

Description

value1

[word!]

Must refer to an integer value

         

value2

[word! integer!]

         

Notes and Examples

eq.i?: rebcode [value1 value2] [
    eq.i   value1 value2
    gett   res
    return res
]

eq.d

Sets the T flag if the values are equal.

Arg

Type

Description

value1

[word!]

Must refer to a decimal value

         

value2

[word! decimal!]

         

Notes and Examples

See eq.i

glt.i

Sets the T flag if: value1 < operand < value2.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value1

[word! integer!]

         

value2

[word! integer!]

         

Notes and Examples

between-exclusive?: rebcode [value lower upper /local res] [
    glt.i  value lower upper
    gett   res
    return res
]
between-exclusive? 5 1 10
true
between-exclusive? 1 1 10
false

glt.d

Sets the T flag if: value1 < operand < value2.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value1

[word! decimal!]

         

value2

[word! decimal!]

         

Notes and Examples

See glt.i

glte.i

Sets the T flag if: value1 <= operand <= value2.

Arg

Type

Description

operand

[word!]

Must refer to an integer value

         

value1

[word! integer!]

         

value2

[word! integer!]

         

Notes and Examples

between-inclusive?: rebcode [value lower upper /local res] [
    glte.i value lower upper
    gett   res
    return res
]
between-inclusive? 5 1 10
true
between-inclusive? 1 1 10
true
between-inclusive? 11 1 10
false

glte.d

Sets the T flag if: value1 <= operand <= value2.

Arg

Type

Description

operand

[word!]

Must refer to a decimal value

         

value1

[word! decimal!]

         

value2

[word! decimal!]

         

Notes and Examples

See glte.i

gt.i

Sets the T flag if the first value is greater than the second value.

Arg

Type

Description

value1

[word!]

Must refer to an integer value

         

value2

[word! integer!]

         

Notes and Examples

gt.i?: rebcode [value1 value2] [
    gt.i   value1 value2
    gett   res
    return res
]

gt.d

Sets the T flag if the first value is greater than the second value.

Arg

Type

Description

value1

[word!]

Must refer to a decimal value

         

value2

[word! decimal!]

         

Notes and Examples

See gt.i

gteq.i

Sets the T flag if the first value is greater than or equal to the second value.

Arg

Type

Description

value1

[word!]

Must refer to an integer value

         

value2

[word! integer!]

         

Notes and Examples

gteq.i?: rebcode [value1 value2] [
    gteq.i value1 value2
    gett   res
    return res
]

gteq.d

Sets the T flag if the first value is greater than or equal to the second value.

Arg

Type

Description

value1

[word!]

Must refer to a decimal value

         

value2

[word! decimal!]

         

Notes and Examples

See gteq.i

lt.i

Sets the T flag if the first value is less than the second value.

Arg

Type

Description

value1

[word!]

Must refer to an integer value

         

value2

[word! integer!]

         

Notes and Examples

lt.i?: rebcode [value1 value2] [
    lt.i   value1 value2
    gett   res
    return res
]

lt.d

Sets the T flag if the first value is less than the second value.

Arg

Type

Description

value1

[word!]

Must refer to a decimal value

         

value2

[word! decimal!]

         

Notes and Examples

See lt.i

lteq.i

Sets the T flag if the first value is less than or equal to the second value.

Arg

Type

Description

value1

[word!]

Must refer to an integer value

         

value2

[word! integer!]

         

Notes and Examples

lteq.i?: rebcode [value1 value2] [
    lteq.i value1 value2
    gett   res
    return res
]

lteq.d

Sets the T flag if the first value is less than or equal to the second value.

Arg

Type

Description

value1

[word!]

Must refer to a decimal value

         

value2

[word! decimal!]

         

Notes and Examples

See lteq.i

neq.i

Sets the T flag if the values are not equal.

Arg

Type

Description

value1

[word!]

Must refer to an integer value

         

value2

[word! integer!]

         

Notes and Examples

neq.i?: rebcode [value1 value2] [
    neq.i  value1 value2
    gett   res
    return res
]

neq.d

Sets the T flag if the values are not equal.

Arg

Type

Description

value1

[word!]

Must refer to a decimal value

         

value2

[word! decimal!]

         

Notes and Examples

See neq.i

Series Operations

change

Changes count values at the specified position in a series.

Arg

Type

Description

series

[word!]

Must refer to a series

         

value

[any-type!]

         

count

[integer! word!]

Use -1 to copy entire value if it is a series

         

Notes and Examples

If series is a block, and value is block, the contents of value are inserted; use poke to insert the block itself, not its contents.

Change will not auto-expand the target series, it will clip. To expand a series, use insert.

clear

Removes all values from current index to tail. Leaves reference at tail.

Arg

Type

Description

series

[word!]

         

Notes and Examples

clear*: rebcode [series] [
    clear series
]

copy

Copies count items from series. Operand modified.

Arg

Type

Description

operand

[word!]

         

series

[series! word!]

         

count

[integer! word!]

Use -1 to copy entire series

         

Notes and Examples

copy*: rebcode [series count] [
    copy res series count
    return res
]

index?

Sets the operand to the index number of the current position in the series.

Arg

Type

Description

operand

[word!]

         

series

[word!]

         

Notes and Examples

index?*: rebcode [series] [
    index? res series
    return res
]

insert

Inserts one series into another and sets the operand to the series at the insert point.

Arg

Type

Description

series

[word!]

Must refer to a series

         

value

[any-type!]

         

length

[integer! word!]

Use -1 to copy entire value, if it is a series

         

Notes and Examples

insert*: rebcode [dest] [
    insert dest "123"
    return dest
]

If series is a block, and value is block, the contents of value are inserted; use poke to insert the block itself, not its contents.

Insert will auto-expand the target series. If you don't want to expand the series, use change.

length?

Sets the operand to the length of the series from the current position.

Arg

Type

Description

operand

[word!]

         

series

[word!]

         

Notes and Examples

length?*: rebcode [series] [
    length? res series
    return res
]

pick

Sets the operand to refer to the value at the specified position in a series.

Arg

Type

Description

operand

[word!]

Will be set to picked value

         

series

[word!]

Must refer to a series, pair, or tuple

         

index

[integer! word!]

         

Notes and Examples

pick may modify the datatype of the operand. It is not a datatype optimized operation.

pick*: rebcode [series index /local result] [
    pick result series index
    return result
]
print to char! pick* "ABCDE" 1
print to char! pick* "ABCDE" 3
print to char! pick* "ABCDE" 5

See also: pickz

pickz

Zero-based pick. Operand modified.

Arg

Type

Description

operand

[word!]

Will be set to picked value

         

series

[word!]

Must refer to a series, pair, or tuple

         

index

[integer! word!]

0 to series length - 1

         

Notes and Examples

pickz*: rebcode [series index /local result] [
    pickz result series index
    return result
]
print to char! pickz* "ABCDE" 0 
print to char! pickz* "ABCDE" 2
print to char! pickz* "ABCDE" 4

See also: pick

poke

Changes the value at the specified position in a series.

Arg

Type

Description

series

[word!]

Must refer to a series, pair, or tuple

         

index

[integer! word!]

1 to series length

         

value

[any-type!]

         

Notes and Examples

poke*: rebcode [series index value] [
    poke series index value
    return series
]
print mold poke* "ABCDE" 1 #"X"
print mold poke* "ABCDE" 3 #"Y"
print mold poke* "ABCDE" 5 #"Z"

Note that we can't pass a string as the value. Rebcode will convert the value to an integer, so we have to use a char! or an integer! directly. Using a string will produce undefined results. This is why it's important to use datatype constraints on the arguments you pass to rebcode functions.

print mold poke* "ABCDE" 1 "X"

print mold poke* "ABCDE" 1 88

pokez

Zero-based poke.

Arg

Type

Description

series

[word!]

Must refer to a series, pair, or tuple

         

index

[integer!]

0 to series length - 1

         

value

[any-type!]

         

Notes and Examples

pokez*: rebcode [series index value] [
    pokez series index value
    return series
]
print mold pokez* "ABCDE" 0 #"X"
print mold pokez* "ABCDE" 2 #"Y"
print mold pokez* "ABCDE" 4 #"Z"

Note that we can't pass a string as the value. Rebcode will convert the value to an integer, so we have to use a char! or an integer! directly. Using a string will produce undefined results. This is why it's important to use datatype constraints on the arguments you pass to rebcode functions.

print mold pokez* "ABCDE" 0 "X"

print mold pokez* "ABCDE" 0 88

remove

Remove count items from the series, at the current position.

Arg

Type

Description

series

[word!]

         

count

[integer! word!]

The number of items to remove

         

Notes and Examples

remove*: rebcode [series index] [
    remove series index
]

Series Traversal

Notes and Examples

head?, tail?, and past? set or clear the T flag, all other series traversal opcodes modify the operand.

back

Moves the current position of the series backward by one.

Arg

Type

Description

series

[word!]

         

Notes and Examples

You should not use back in rebcode and return the value directly to REBOL (in most cases). The recode back opcode can return a result that will produce an Out of range or past end error in REBOL.

back*: rebcode [series [series!]] [
    back   series
    return series
]

See also: past?

head

Changes the current position of the series to its head.

Arg

Type

Description

series

[word!]

         

Notes and Examples

head*: rebcode [series [series!]] [
    head   series
    return series
]

head?

Sets the T flag if a series is at its head.

Arg

Type

Description

series

[word!]

         

Notes and Examples

head?*: rebcode [series [series!] /local res] [
    head?  series
    gett   res
    return res
]

next

Moves the current position of the series forward by one.

Arg

Type

Description

series

[word!]

         

Notes and Examples

You should not use next in rebcode and return the value directly to REBOL (in most cases). The recode next opcode can return a result that will produce an Out of range or past end error in REBOL.

next*: rebcode [series [series!]] [
    next   series
    return series
]

See also: past?

past?

Sets the T flag if the series is past its end.

Arg

Type

Description

series

[word!]

         

Notes and Examples

This is really only useful in rebcode, because REBOL protects you from accessing indexes outside the bounds of a series. Rebcode offers no such protection, so past? is valuable in rebcode functions.

The only time past? would be useful in REBOL is if you have rebcode functions that return a result from rebcode operators that modify a series offset (next, back, etc.). In those cases, you could use past? to check whether the series is at a valid offset, to prevent an Out of range or past end error.

past?: rebcode [series [series!] /local res] [
    past?  series
    gett   res
    return res
]

See also: next, back, skip

skip

Changes the current position of the series forward or backward.

Arg

Type

Description

series

[word!]

         

offset

[word! integer!]

         

Notes and Examples

You should not use skip in rebcode and return the value directly to REBOL (in most cases). The recode skip opcode can return a result that will produce an Out of range or past end error in REBOL.

skip*: rebcode [series [series!] offset [integer!]] [
    skip   series offset
    return series
]

See also: past?

tail

Changes the current position of the series to its tail.

Arg

Type

Description

series

[word!]

         

Notes and Examples

tail*: rebcode [series [series!]] [
    tail   series
    return series
]

tail?

Sets the T flag if a series is at its tail.

Arg

Type

Description

series

[word!]

         

Notes and Examples

tail?*: rebcode [series [series!] /local res] [
    tail?  series
    gett   res
    return res
]

Debugging

??

Arg

Type

Description

name

[word!]

         

Notes and Examples

Works like ?? in REBOL.

debug

Assembler verbose command

Arg

Type

Description

Notes and Examples

escape?

currently throws to console

Arg

Type

Description

Notes and Examples

fn: rebcode [] [
    repeat i 1000 [
        print i
        escape?     ; throws Invalid Operator
    ]
]

Note: use escape? sparingly at upper levels of your loops; it costs about the same as 25 add.i opcodes to check the console port in the current implementation.

print

Arg

Type

Description

value

[any-type!]

         

Notes and Examples

Works like print in REBOL.

probe

Arg

Type

Description

value

[any-type!]

         

Notes and Examples

Works like probe in REBOL.

trace

Arg

Type

Description

mode

[word! logic!]

         

Notes and Examples

About | Contact | Support | Privacy | LicenseREBOL Technologies 2017