I recently got asked some pretty deep questions about Espruino by e-mail - I'm copying here as they're probably useful to anyone hacking on Espruino...
For this structure of JsVarData, I do not understand the effect of “native“ and “ref”.
'Native' is information for functions that are implemented as native code rather than JavaScript (so basically compiled C code). 'Ref' contains references to other children/siblings in the linked list/tree structure.
And why does it use union structure. What is the advantage of the union structure?
Basically unions overlap in memory, so all the elements of JsVarData share the same bytes. There is some documentation under the definition that describes how bytes are used for different types of variable:
What do the “nextSibling”, ”prevSibling”, ”refs”, ”firstChild” and “lastChild” mean? Could you give me an example for understanding every part of the JsVar structure wil be assigned?
“nextSibling”, ”prevSibling” are when the JsVar is used in a linked list
refs is for reference counting - it's the number of references to the JsVar - if that is 0 and there are no locks then the variable can be freed.
”firstChild” and “lastChild” point to the beginning and end of a linked list of children.
The best way to get an idea of how they're all used is to type trace() in Espruino. This will dump out the datastructure in a human readable form (to see how, look at jsvTrace).
And what is the whole structure between variable and another variable? A Binary tree or a list? Please give me an example.
It's a linked list. But a JsVar can have children, in which case it is a linked list of children too.
If I upload the code digitalWrite([A5,A6],0x11) to the board in the terminal, I do not know how the every part of JsVar Structure will be assigned for the array [A5,A6].
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I recently got asked some pretty deep questions about Espruino by e-mail - I'm copying here as they're probably useful to anyone hacking on Espruino...
'Native' is information for functions that are implemented as native code rather than JavaScript (so basically compiled C code). 'Ref' contains references to other children/siblings in the linked list/tree structure.
See http://en.wikipedia.org/wiki/Union_type#C.2FC.2B.2B
Basically unions overlap in memory, so all the elements of JsVarData share the same bytes. There is some documentation under the definition that describes how bytes are used for different types of variable:
https://github.com/espruino/Espruino/blob/master/src/jsvar.h#L144
Also:
http://www.espruino.com/Internals
“nextSibling”, ”prevSibling” are when the JsVar is used in a linked list
refs is for reference counting - it's the number of references to the JsVar - if that is 0 and there are no locks then the variable can be freed.
”firstChild” and “lastChild” point to the beginning and end of a linked list of children.
The best way to get an idea of how they're all used is to type
trace()
in Espruino. This will dump out the datastructure in a human readable form (to see how, look at jsvTrace).It's a linked list. But a JsVar can have children, in which case it is a linked list of children too.
[A5,A6]
goes toJsVar(Array, JsVar(Name_int, 0, JsVar(Pin,A5)), JsVar(Name_int, 1, JsVar(Pin, A6)))
(Note: the use of JsVar() is just pseudo-code to denote a tree structure)
But arrays can be 'packed' - if you used a simple number like
[4,5]
you'd get:JsVar(Array, JsVar(Name_int_int, 0, 4), JsVar(Name_int_int, 1, 5))
It actually doesn't go into JsExecIfo->root as it isn't a global variable, but it's stored as a linked list while executing the function
digitalWrite