From 9f302cc6407f76615c9eb5d7465685dc5dff6cca Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 11 Apr 2019 21:41:46 +0200 Subject: [PATCH] docs about '&' operator --- docs/source/syntaxreference.rst | 17 ++++++----------- docs/source/todo.rst | 12 ------------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index eed976921..ab011e8b2 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -226,7 +226,7 @@ Various examples:: byte age = 2018 - 1974 float wallet = 55.25 str name = "my name is Irmen" - word address = #counter + uword address = &counter byte[5] values = [11, 22, 33, 44, 55] byte[5] values = 255 ; initialize with five 255 bytes @@ -360,15 +360,6 @@ Syntax is familiar with brackets: ``arrayvar[x]`` :: Operators --------- -.. todo:: - address-of: ``#`` or ``&`` (to stay close to C) - Takes the address of the symbol following it: ``word address = &somevar`` - Perhaps requires an explicit pointer type as well instead of just word? - - This can replace the ``memory`` var decl prefix as well, instead of - ``memory uword var = $c000`` we could write ``&uword var = $c000`` - - arithmetic: ``+`` ``-`` ``*`` ``/`` ``**`` ``%`` ``+``, ``-``, ``*``, ``/`` are the familiar arithmetic operations. ``/`` is division (will result in integer division when using on integer operands, and a floating point division when at least one of the operands is a float) @@ -376,7 +367,6 @@ arithmetic: ``+`` ``-`` ``*`` ``/`` ``**`` ``%`` ``%`` is the remainder operator: ``25 % 7`` is 4. Be careful: without a space, %10 will be parsed as the binary number 2 Remainder is only supported on integer operands (not floats). - bitwise arithmetic: ``&`` ``|`` ``^`` ``~`` ``<<`` ``>>`` ``&`` is bitwise and, ``|`` is bitwise or, ``^`` is bitwise xor, ``~`` is bitwise invert (this one is an unary operator) ``<<`` is bitwise left shift and ``>>`` is bitwise right shift (both will not change the datatype of the value) @@ -417,6 +407,11 @@ range creation: ``to`` ; i loops 0, 1, 2, ... 127 } +address of: ``&`` + This is a prefix operator that can be applied to a string or array variable or literal value. + It results in the memory address (UWORD) of that string or array in memory: ``uword a = &stringvar`` + Sometimes the compiler silently inserts this operator to make it easier for instance + to pass strings or arrays as subroutine call arguments. precedence grouping in expressions, or subroutine parameter list: ``(`` *expression* ``)`` Parentheses are used to group parts of an expression to change the order of evaluation. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 72b81ba55..3f73f5d80 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -52,18 +52,6 @@ Allocate a fixed word in ZP that is the TOS so we can operate on TOS directly without having to to index into the stack? - -More flexible (non-const) arrays? -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Currently, array literals can only be constants -Allow for non-const arrays? Such as:: - - ubyte[16] block1 - ubyte[16] block2 - ubyte[16] block3 - ubyte[3] blocks = [block1, block2, block3] - - structs? ^^^^^^^^