Program

The main program: the entry point of an executable.

Declaration

Syntax

Program(symbol_table symtab, identifier name, identifier* dependencies,
    stmt* body, location start_name, location end_name)

Arguments

Argument

Description

symtab

the symbol table of the program. It owns the local variables of the program and the ExternalSymbol entries for the module symbols the program uses.

name

the name of the program.

dependencies

the names of the modules and procedures the body of the program refers to. The backends use it to order code generation.

body

the statements of the program, in order.

start_name

the source span of the name in program name.

end_name

the source span of the name in end program name, or an empty span when the end statement does not repeat it.

Return values

None.

Description

A translation unit that is linked into an executable must contain exactly one Program. It is always owned by the global symbol table.

A program has no arguments and no return value, so it needs no function_signature: unlike Function it can never be called from ASR.

Statements typed directly into the REPL, or written outside of any program unit, first appear in TranslationUnit.items. The global_stmts ASR pass wraps them in a Program so that the rest of the compiler only has to deal with program units.

Examples

An ASR text document that uses it:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "x" (Variable
              :parent_symtab 1
              :name "x"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "x")
            )
            :value (IntegerBinOp
              :left (IntegerConstant
                :n 2
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :op :Add
              :right (IntegerConstant
                :n 3
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Integer
                :kind 4
              )
              :value (IntegerConstant
                :n 5
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

See Also

TranslationUnit, Module, Function, Variable