Special codes of sron_cmd()

Special codes help you to perform operations on internal components of SRON's interpreter and also get internal information about interpreter when used with sron_cmd() function.

These are the following codes which SRON provides:

  1. SRON_CMD_OBUFFER_CLEAR:

It clears all the content in OBUFFER without flushing them on the terminal/command line.

{
    name : Main 

    OBUFFER += "Hello there! Sron"

    sron_cmd(SRON_CMD_OBUFFER_CLEAR)

    console : ( '>' , OBUFFER , '<')  @ Output:  ><
}

  1. SRON_CMD_IS_OBUFFER_EMPTY:

It clears all the content in OBUFFER without flushing them on the terminal/command line.

{
    name : Main

    Bool is_obuffer_empty = sron_cmd( SRON_CMD_IS_OBUFFER_EMPTY )

    println( is_obuffer_empty )  @ Output: true

    OBUFFER += 27062003

    is_obuffer_empty = sron_cmd( SRON_CMD_IS_OBUFFER_EMPTY )

    println( is_obuffer_empty )   @ Output: false
}

  1. SRON_CMD_SIZEOF_OBUFFER:

It returns the number of characters OBUFFER contains. In other words, it returns the length of content of OBUFFER.

{
    name : Main

    OBUFFER += 2003      @ four characters only

    Int len = sron_cmd( SRON_CMD_SIZEOF_OBUFFER )

    println( len )   @ Output: 4
}

  1. SRON_CMD_IS_FILE_AVAILABLE:

It searches for the file in the current directory and if the file is found, returns true otherwise false.

{
    name : Main 

    Bool is_file_available = sron_cmd( SRON_CMD_IS_FILE_AVAILABLE , "hello.txt" )

    println( is_file_available )  @Output: false
}

  1. SRON_CMD_GC_STACK_LEN:

It returns the length of stack of Garbage Collector.

{
    name : Fnc1

    Int len_of_gc_stack = sron_cmd( SRON_CMD_GC_STACK_LEN )

    println(len_of_gc_stack)  @ Output: 3
}

{
    name : Fnc2

    Fnc1()
}

{
    name : Main

    Fnc2()
}

  1. SRON_CMD_IS_BYTECODE_CACHED:

It returns true if the bytecode is cached otherwise returns false. If a function is called before, then it automatically cached by the SRON's interpreter.

{
    name : Fnc

    println("> Fnc called")
}
{
    name : Main

    Bool is_bytecode_cached = sron_cmd( SRON_CMD_IS_BYTECODE_CACHED , "Fnc.srb") 

    println( is_bytecode_cached )

    Fnc()

    is_bytecode_cached = sron_cmd( SRON_CMD_IS_BYTECODE_CACHED , "Fnc.srb")

    println( is_bytecode_cached )
}

  1. SRON_CMD_NO_OF_BYTECODE_CACHED:

It returns the number of all the cached bytecode files.

{
    name : Fnc 

    println("\n > Fnc Called")
}

{
    name : Main  @ Main function never get cached

    Int no_of_bytecode_cached = sron_cmd(SRON_CMD_NO_OF_BYTECODE_CACHED)

    Fnc()
    Fnc()     @ a function is cached only once

    no_of_bytecode_cached = sron_cmd(SRON_CMD_NO_OF_BYTECODE_CACHED)

    println(" Total cached bytecodes= ", no_of_bytecode_cached)  @ Output: 1
}

Last updated