Runtime

After the pseudocode is parsed, runtime object (pseudo.runtime.RunTime) is initialized. All operations are evaluated in runtime context. In runtime there is also virtual memory (dict 😉), which contains variables and their values.

This module contains RunTime class, which is a representation of runtime resources.

class pseudo.runtime.MemoryObject(key: str, value: object, const: bool = False)

This class is a representation of object in runtime memory.

- value

object, Stored object.

- const

bool, If true object is constant and cannot be changed.

getter()

This function returns value.

setter(value: object, r)

This function updates value.

class pseudo.runtime.RunTime

This class is a representation of computer resources like memory or processor. It is used to run instructions parsed by pseudo.lexer.Lexer.

- var

dict, In this object all variables will be stored.

Variable names:

Variable names consist of alphanumeric characters, starting with alphabetical char. Arrays are stored as independent keys i.e.:

{
    "T[1]": 1,
    "T[2]": 2,
}
Usage::
>>> instructions = [Statement("pisz", Int(42))]
>>> r = RunTime()
>>> r.run(instructions)
42
delete(key: str)

This function removes variable from memory.

eval(instruction)

Evaluate instruction.

get(key: str)

This function returns value of stored variable.

Parameters:key (-) – str, Key under which value is stored.
run(instructions: list)

Run pseudocode instructions

save(key: str, value: object, object_class=<class 'pseudo.runtime.MemoryObject'>)

This functions is used to save variable’s value in memory

Parameters:
  • key (-) – str, Unique key under which value will be stored. T[1][10] is also a key
  • value (-) – object, Value to store.
  • object_class (-) – class, Class of value.
static save_crash(error_message: str)

Save crash message to file and return path to it.

stdin(key: str)

This function reads value from standard input and stores it in given variable.

stdout(value: object)

This function writes value to standard output.

throw(error_message: str, line_causing_error: str = '')

This function is used to tell user that a runtime error has occurred.