fpp/docs/spec/Definitions/Module-Definitions.adoc
2025-05-13 08:15:18 -07:00

74 lines
2.2 KiB
Plaintext

=== Module Definitions
A *module definition* provides a named scope that encloses and qualifies other
definitions, including other module definitions.
It is similar to a namespace in C++ or a package in Java or Scala.
==== Syntax
`module`
<<Lexical-Elements_Identifiers,_identifier_>>
`{` _module-member-sequence_ `}`
_module-member-sequence_ is an
<<Element-Sequences,element sequence>> in
which each element is a *module member*,
and the terminating punctuation is a semicolon.
A module member is one of the following:
* A <<Definitions_Component-Definitions,component definition>>
* A <<Definitions_Component-Instance-Definitions,component instance definition>>
* A <<Definitions_Constant-Definitions,constant definition>>
* A <<Definitions_Module-Definitions,module definition>>
* A <<Definitions_Port-Definitions,port definition>>
* A <<Definitions_Port-Interface-Definitions,port interface definition>>
* A <<Definitions_State-Machine-Definitions,state machine definition>>
* A <<Definitions_Struct-Definitions,struct definition>>
* A <<Definitions_Topology-Definitions,topology definition>>
* A <<Specifiers_Location-Specifiers,location specifier>>
* An <<Definitions_Abstract-Type-Definitions,abstract type definition>>
* An <<Definitions_Alias-Type-Definitions,alias type definition>>
* An <<Definitions_Array-Definitions,array definition>>
* An <<Definitions_Enum-Definitions,enum definition>>
* An <<Specifiers_Include-Specifiers,include specifier>>
==== Semantics
A module definition _D_ qualifies the names of all the definitions
inside it with its own name. Inside _D_, you can refer to definitions in
_D_ by their unqualified name (the identifier appearing in the
definition) or by their qualified name. Outside _D_, you have to use the
qualified name. We say that the *scope* of the identifiers in the
definitions in _D_ is limited to the inside of _D_.
For further information about name scoping and qualification, see the
section on
<<Scoping-of-Names,Scoping of Names>>.
==== Example
[source,fpp]
----
module M {
constant a = 0
constant b = a # Inside M, we can refer to M.a as a
constant c = M.a # We can also say M.a here
}
constant d = M.a # Outside M, we have to say M.a
constant e = a # Error: a is not in scope here
----