OOP

Source code with basic use case of classes and methods:

CLASS retrieve()
$$
  METHOD val()
  $$
    self = 'abc';
  $$;
$$;

FUNCTION test()
$$
  obj = NEW ret();
  RETURN obj.val();
$$;

Run the following queries:

SELECT test()
;
test
====
'abc'

-- following is also true:
SELECT retrieve.val()
;
retrieve.val
============
'abc'

Commands needed to run the code:

COMMAND_HEX | DESCRIPTION
==============================
         00 | 'root'
         7A | 'class'
         7B | 'method'
         7C | 'function'
         7D | 'instance'
         7E | 'self keyword'
         7F | 'return keyword'

The source code is parsed and loaded into the database. When select test() is executed Sprout retrieves program call stack in the following format:

# COMMAND_HEX ASCENDANT_ID ENTITY_ID REFERENCE_ID LEVEL ORDER
=============================================================
1          7A            0         1            1     0     1
2          7B            1         2            2     1     1
3          7E            2         3            3     2     1
4          7C            0         4            4     1     1
5          7D            4         5            1     2     1
6          7F            4         6            6     2     2
7          7D            6         7            7     3     1
8          7B            7         8            2     4     1

Columns level and order are used by the translator to manage the call stack.

Condition ENTITY_ID <> REFERENCE_ID in a call stack entry is signal to the interpreter that the entry is an object reference.

# Description Value
1 class ‘retrieve’
2 method ‘val’
3 keyword self ‘abc’
4 function ‘test’
5 object instance ‘O’
6 keyword return
7 nested into return object instance ‘O’
8 nested into the object instance reference to method val()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s