Table of Contents:
- Introduction
- Command Line
- Supported Operators
- Operator Description
- Loop Structures
- Array's
- Pragma Debug Control
- Code Examples
- Notes & Limitations
- What's New
1.0 Introduction
The syntax of RCode is quite simplistic, and in some
ways
resembles
writing assembly language. For experienced software developers,
coding
is cumbersome at best. The array extensions from AiboPet are very
useful, but anyone familar with normal programming languages miss their
concise array syntax. Lastly, the requirement to return
values
from function calls in the "Context" variable or on the stack makes
coding
awkward.
ReCode supports using C-style expressions, including
direct
array references
(using AiboPet RCodePlus) & function calls. Keywords
can
be upper or lower case. Spacing inside expressions is
optional.
ReCode also performs full syntax checking on the target RCode (just
like RCheck). DogsLife uses the
extensions, and must be compiled
with ReCode.
This program is intended for software developers already
familiar with
BASIC, C, or Pascal programming. No attempt is made to teach
programming
concepts here.
People new to programming AIBO will find AiboPet's YART
utility easier. YART offers a
graphical drag-n-drop method of creating
simple custom AIBO personalities. It's a great way to start!
2.0 Command Line:
Usage (from dos prompt) is:
|
RECODE [options] target1.r
[target2.r
...]
[-outfile outfile.r] |
|
|
The command line options are:
-OUTFILE |
Specifiy name of output file.
Default is
R-CODE.R. |
-CHECK |
Do syntax checks only (no output). Identical to
using RCheck
with expressions enabled. |
-LABELS |
Flag as error labels which differ only by case.
ie: Trying
to use similar labels names 'G_MAX', and 'G_Max' at once would be
considered
an error. RCode permits such label names, but it is poor coding
style,
and can create difficult to debug problems (when you get them mixed up). |
-VARS |
Flag as errors variables which differ only by
case.
ie:
Trying to use variable names 'AAA', 'Aaa', 'aaa' all at once would be
considered
an error. RCode permits such variable names, but it is poor
coding
style, and can create difficult to debug problems (when you get them
mixed
up). |
-DEBUG |
Insert line tracing debug information. Adds
debug
PRINT
statements of the current program location. You need a telnet
connection
(wireless LAN) for this to be of any use. |
-DEBUG2 |
Insert line & variable tracing debug
information. Adds
debug PRINT statements for the current program location, and outputs
the
value of referenced and assigned variables to aid debug. This can
be VERY verbose while Aibo is running. You need a telnet
connection
(wireless LAN) for this to be of any use. |
-DEBUG3 |
Inserts line, variable, and stack tracing debug
information.
Intended for use by Aibnet.
Adds
debug PRINT statements for the current program location, values of
referenced
and assigned variables, and call/return tracking. This can be
VERY
verbose while Aibo is running. You need a telnet connection
(wireless
LAN) for this to be of any use. |
-NOPRINT |
Filters all PRINT statements from behavior file.
Recommended
prior to distributing RCode, since PRINT statements can make Aibo's
without
wireless LAN card's unstable. |
-NOEXPR |
Support only standard RCode. Expressions are
disabled |
3.0 Supported Operators:
ReCode implements the C-style operators shown below, and
follows the
precidence (which operators are higher priority) order shown.
[ ] ( )
postfix ++
postfix -- |
Expression |
prefix ++
prefix --
& * + - ~ ! |
Unary |
* / % |
Multiplicative |
+ - |
Additive |
<< >> |
Bitwise shift (compiled into
mulitply/divide
loops). |
< > <= >= |
Relational |
= == != |
Relational |
& |
Bitwise-AND |
^ |
Bitwise-exclusive-OR |
| |
Bitwise-inclusive-OR |
&& |
Logical-AND |
|| |
Logical-OR |
? : |
Conditional-expression |
:= *= /= %=
+= -= <<= >>=
&= ^= |= |
Simple and compound assignment. |
ReCode does not implement C-language pointers, structures, or the comma
operator.
4.0 Operator Description:
arrayname[index] |
Array reference. |
() |
Parenthesis. Use to override precidence
evaluation
order. |
function()
function(args,...) |
Call function & use result. Function must
use
RETURN command
upon completion. |
variable++
array[expr]++ |
Increment variable/array after using value. |
variable--
array[expr]-- |
Decrement variable/array after using value. |
++variable
++array[expr] |
Increment variable/array before using value. |
--variable
--array[expr] |
Decrement variable/array before using value. |
~expr |
Bitwise invert (one's complement). |
!expr |
Logical Negate. If expression is zero, result
is
1. |
expr1 && expr2 |
Logical-AND. If both expressions non-zero,
result is
1. |
expr1 || expr2 |
Logical-OR. If either expression non-zero,
result is
1. |
expr1 * expr2 |
Multiply expressions. |
expr1 / expr2 |
Divide expr1 by expr2. |
expr1 % expr2 |
Modulus of expr1 by expr2.
expr1-(expr1/expr2)*expr1 |
expr1 + expr2 |
Add expr1 and expr2 |
expr1 - expr2 |
Subtract expr2 from expr1 |
expr1 << expr2 |
Bitwise shift up expr1 by expr2. Each count of
expr2
multiplies
expr1 by 2. |
expr1 >> expr2 |
Bitwise shift up expr1 by expr2. Each count of
expr2
divides
expr1 by 2. |
expr1 < expr2 |
If expr1 less than expr2, result is 1. |
expr1 <= expr2 |
If expr1 less than or equal to expr2, result is 1. |
expr1 > expr2 |
If expr1 greater than expr2, result is 1. |
expr1 >= expr2 |
If expr1 greater than or equal to expr2, result is 1 |
expr1 = expr2
expr1 == expr2 |
If expr1 equals expr2, result is 1. |
expr1 != expr2 |
If expr1 not equal to expr2, result is 1. |
expr1 & expr2 |
Bitwise-AND of expressions. ie: (12 &
4)
equals 4. |
expr1 | expr2 |
Bitwise-inclusive-OR of expressions. ie: (8 |
4)
equals 12. |
expr1 ^ expr2 |
Bitwise-exclusive-OR of expressions. ie: (12 ^
4)
equals 8. |
expr1 ? expr2 : expr3 |
Conditional-expression. If expr1 is non-zero,
expr2
is evaluated.
Otherwise, expr2 is evaluated. |
variable := expr2
array[expr1] := expr2 |
Assign result of expr2 into
variable/array. Can
be embedded
in another expression. ie:
xxx := yyy+123
SET xxx (yyy+(zzz := aaa)) |
variable *= expr2
array[expr1] *= expr2 |
Same as:
variable := variable * (expr2)
array[expr1] := array[expr1] * (expr2) |
/= %= +=
-= <<= >>=
&= ^= |= |
Similar to above, using indicated operator. ie:
variable += 5 // Add 5 to variable |
5.0 Loop Structures:
ReCode supports expressions in all loop commands (WHILE/WEND,
DO/LOOP,
REPEAT/UNTIL etc...). In the generated output, loop commands are
converted into IF/THEN blocks to support decomposing expressions.
ie:
DO:WHILE aaa>bbb
//user code...
LOOP:UNTIL eee>fff |
:reTempLbl
IF aaa > bbb THEN
//user code...
IF eee <= fff reTempLbl
ENDIF |
6.0 Arrays:
ReCode supports simple one-dimensional inline arrays -- the
syntax
is
similar to C, Pascal or BASIC. Such statements are compiled
into AiboPet's RCodePlus extensions. However, you as the
programmer
are still responsible for initializing the arrays properly.
6.1 Important Array Rules & Limitations
There can be a maximum of 20 arrays (numbered from 1
to 20).
An array can have a maximum of 32767 elements.
Array index values are zero based (an array with 500
elements has valid
index's 0 through 499).
Values stored in an array are 16-bit signed integers
(-32768 to 32767).
You -must- dimension an array with AP_DIM before
using it.
|
6.2 Initializing Arrays
The RCodePlus array commands specify arrays by number. These
numbers can be from 1 to 20. Other values cause errors or
are
reserved for special purposes by RCodePlus.
To reference an array by variable name, simply assign the
number (1
to 20) to a valid RCode variable. The numeric array
reference
business can be slightly confusing at first. Just remember
to:
- Allocate a number from 0 to 19.
- Choose a variable name, and assign it that number.
- Specify the array size using the RCodePlus AP_DIM command.
Please refer to AiboPet's RCode
extension documentation for complete details on RCodePlus
arrays.
6.3 Array Examples:
SET myarray
1
// Use variable name "myarray" for array 1
AP_DIM myarray 500
//
Initialize array 1 with 500 entries
SET otherarray
5
// Use variable name "otherarray" for array 5
AP_DIM otherarray 25 //
Initialize
array 5 with 25 entries
for i 0
499
// Initialize array 1 (myarray) with random numbers
rnd myarray[i] 1 1000
next
for j 0
24
// Show arrays used in expressions
otherarray[24-j] := (myarray[j*5] *
myarray[j*10])
/ myarray[j*15]
next
7.0 Pragma Debug Control
ReCode supports flexible debug mode
#pragma
controls. Instead of global all-or-nothing debug (from the
command line), the pragma control allows you to control debug in the
RCode source. You generate debug only on the area of
interest -- not your entire program.
In debug mode, the compiled RCode increases many times in
size. Downloading to AIBO takes longer, and AIBO takes
longer to start up. Certain large RCode programs (such as
DogsLife) simply become too large for AIBO in debug mode.
Pragma controls help avoid that problem.
The pragma commands mirror the command line options. ie:
#pragma nodebug
|
Turn off debug code generation
|
#pragma debug
|
Insert line tracing information only.
|
#pragma debug2 |
Insert line & variable tracing debug
information. |
#pragma debug3 |
Inserts line, variable, and stack tracing debug
information. |
For example:
#pragma debug3
// Generate debug info on this loop
for i 0
499
// Initialize array 1 (myarray) with random numbers
rnd myarray[i] 1 1000
next
#pragma nodebug
// No debug info on this loop
for j 0
24
// Show arrays used in expressions
otherarray[24-j] := (myarray[j*5] *
myarray[j*10])
/ myarray[j*15]
next
NOTE: Since Aibnet must be in debug mode to take advantage of
debug statements, you must override the global command line debug
options Aibnet selects. Make the first line in your RCode read "#pragma
nodebug" to enable line-level control.
|
8.0 Code Examples:
IF aaa > bbb THEN
IF ccc > ddd THEN
IF eee > fff THEN
PRINT "Hello"
ENDIF
ENDIF
ENDIF |
if (aaa>bbb)
&&
(ccc>ddd) &&
(eee>fff) then
print "Hello"
endif |
SET aaa bbb
ADD aaa ccc
MUL aaa ddd |
aaa := (bbb+ccc)*ddd |
SET tempvar bbb
MUL tempvar ccc
AP_GET aaa myarray tempvar |
aaa := myarray[bbb*ccc] |
SET tempvar bbb
ADD tempvar 123
AP_GET tempvar2 myarray tempvar
DIV tempvar2 64
AP_SET tempvar2 myarray tempvar |
div myarray[bbb+123] 64 |
SET tempvar aaa
MUL tempvar bbb
SET tempvar2 ccc
MUL tempvar2 ddd
IF tempvar > tempvar2 THEN
PRINT "Hello"
ENDIF |
if aaa*bbb > ccc*ddd then
print "Hello"
endif |
PUSH aaa
PUSH bbb
CALL myfunction 2
POP tempvar
IF tempvar > 42 THEN
PRINT "Hello"
ENDIF |
if myfunction(aaa,bbb)>42 then
print "Hello"
endif |
9.0 Notes & Limitations:
- ReCode creates temporary variables & labels to
implement expression
handling. The temporary variables are named reTempVar1,
reTempVar2,
etc... Temporary labels reTempLbl1, reTempLbl2,
etc...
Avoid using these names in your normal coding style.
|
- Expressions cannot be used with the ONCALL, CSET,
IF_1ST,
IF_AND, or
IF_OR
commands, and spaces must still be used between variables &
operators
in these.
|
- Must use RETURN comand within functions called from
expressions.
No syntax check is done to enforce this requirement, and it can create
strange debug problems.
|
- Simple assignment operator (for use within
expression) is " :=
". RCode defines both the " = " and " ==
" operators
as equality. For example, the following sets aaa through
ddd equal to eee: "aaa := bbb := ccc := ddd
:= eee"
|
10.0 What's New:
- Version 3.01 - Fixed inaccurate RCode line tracking
information in debug mode (used by Aibnet).
|
- Version 3.0 - Better code optimization &
generation of
array statements. Improved decision making regarding
stack-based vs inline code generation.
Fixed handling of BREAK command in loop statements.
Addition of #pragma controls for selective debug
generation. Fixed CASE statement to restore context if
original parameter was replaced by subroutine call.
|
- Version 2.0 - Support for Aibnet
RCode
tracing
(to aid debug efforts). Improved syntax checking &
warning
messages for common mistakes. Expressions supported in CASE
command parameters, PLAY parameters (walk distances, turn angles,
etc...),
and PRINT statements. Array elements can receive
results
of commands (ie: MUL myarray[aaa] 42). Fixed bugs
with
postfix increment/decrement (ie: aaa++), and conditional expression
operators
(ie: aaa ? bbb : ccc).
|
- Version 1.4 - Added support for expression only lines
&
AiboPet
YART
tool.
|
|