Tasmota/lib/libesp32/Berry/tools/grammar/berry.bytecode

93 lines
2.7 KiB
Plaintext
Executable File

-------------------------------------------------------------------------------
-- the Berry's bytecode file structure (version 1)
--
-- description
--
-- a double dash ('--') start a line comment.
-- a: b means that the entity 'a' is realized by the 'b' structure.
-- a: b c 'b' and 'c' are arranged in a compact order (one byte alignment).
-- [a] means that structure 'a' can be repeated 0 to any times.
-- [a](b) means that structure 'a' can be repeated 'b' times.
-- a | b means that the entity can be implemented by structure 'a' or 'b'.
-- N a number indicates the byte count of the field (eg. 'a: 1').
-- .N means the number of bits in the field (eg. 'a: .1').
-- only the first entity is a file entity (the root).
-------------------------------------------------------------------------------
bytecode_file: -- little endian
header
global_desc
main_function
header: 8
magic_number: 3 -- 0xbecdfe (berry code file)
version: 2 -- update with file structure definition
integer_size: .1
float_size: .1
-- reserved space
main_function -> function
global_desc:
builtin_count: 4
global_count: 4 -- excluding builtins
global_name -> [
string
](global_count)
function:
information:
function_name:
string
source:
string
argc: 1 -- arguments count
nstack: 1 -- number of stack size by this function
varg: 1
extra: 1 -- extra data
bytecode:
code_size: 4
code_array -> [ -- bytecode array
instruction: 4
](code_size)
constant_table:
constant_count: 4
[constant_value](constant_count)
proto_table:
proto_count: 4
[function](proto_count)
upval_table:
upval_count: 1
upvals: [
instack: 1
index: 1
](upval_count)
debug_info:
-- reserved
constant_value:
type: 1 -- type of value
integer | float | string | class
string:
string_size: 2
byte_array: string_size
class:
class_name:
string
member_count: 4 -- number of member variables
method_count: 4 -- number of method
method_table: [
string -- method name
function | nil -- method function body or nil (static member) if the first byte is null (which would be an empty func name)
](method_count)
member_index_table -> [
string -- member name
](member_count)
nil: 1
boolean: 1
integer: 4 | 8
float: 4 | 8