User Tools

Site Tools


multi-component-program

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
multi-component-program [2015/12/17 04:03]
barryfp
multi-component-program [2017/04/13 03:32]
barryfp
Line 9: Line 9:
 <code dana> <code dana>
 data Token{ data Token{
- copy char string[]+ char string[]
  }  }
  
Line 17: Line 17:
 </​code>​ </​code>​
  
-An interface in Dana may only contain function prototypes (it cannot contain data fields). Interfaces may, however, have constructor functions. These are defined by declaring a function in the interface whose name is the same as the type name of that interface. +An interface in Dana may only contain function prototypes (it cannot contain data fields). Interfaces may, however, have constructor functions. These are defined by declaring a function in the interface whose name is the same as the type name of that interface. We've also defined in this file a new data type which represents one token.
- +
-We've also defined in this file a new data type which represents one token. The modifier ''​copy''​ on a data type field means that this field will be "deep copied"​ when an instance of this data type is itself copied using the ''​clone''​ operator. Another way to think of this is that the field is "owned by" or "part of" the given data type, rather than being something that the data type simply refers to. We return to this topic in more detail in the tutorial on data types.+
  
 Next we'll write a component that provides (i.e. implements) this interface. Create a new text file in the ''​myproject''​ directory called ''​Tokeniser.dn''​. Open this file and add the contents: Next we'll write a component that provides (i.e. implements) this interface. Create a new text file in the ''​myproject''​ directory called ''​Tokeniser.dn''​. Open this file and add the contents:
Line 70: Line 68:
 Some of this syntax should be familiar from earlier tutorials. The component provides a single interface - the Tokeniser - and requires no interfaces (it has no dependencies). The function implementation has a simple "​for"​ loop and builds a list of tokens by adding data elements to an array, the contents of which are returned at the end of the function. Some of this syntax should be familiar from earlier tutorials. The component provides a single interface - the Tokeniser - and requires no interfaces (it has no dependencies). The function implementation has a simple "​for"​ loop and builds a list of tokens by adding data elements to an array, the contents of which are returned at the end of the function.
  
-Data types are constructed by using the ''​new''​ operator followed by the data type's name and an opening and closing bracket. Between these brackets we can optionally supply a list of parameters, separated by commas, which map to the fields of that data type in the order that they appear in the type definition. Note that it is not necessary to provide all fields of a data type that is constructed in this way (e.g. it's possible to provide only the first two out of five fields).+Data types are constructed by using the ''​new''​ operator followed by the data type's name and an opening and closing bracket. Between these brackets we can optionally supply a list of parameters, separated by commas, which map to the fields of that data type in the order that they appear in the type definition. Note that it is not necessary to provide all fields of a data type that is constructed in this way (e.g.it's possible to provide only the first two out of five fields).
  
 Next we write the component which will use the tokeniser, and is very similar to our previous tutorial. Create a new text file in the ''​myproject''​ directory called ''​Main.dn''​ and add the contents: Next we write the component which will use the tokeniser, and is very similar to our previous tutorial. Create a new text file in the ''​myproject''​ directory called ''​Main.dn''​ and add the contents:
Line 112: Line 110:
 At runtime, Dana automatically loads and links components together by searching for a //default// implementation of a given interface type. This search is based on simple name equivalence between the interface type name and the compiled component'​s ​ file name (so in this case the interface type ''​Tokeniser''​ maps to the compiled component ''​Tokeniser.o''​). Note that Dana **does not** automatically compile components. More information on how Dana searches for default implementation components is provided in the next section. At runtime, Dana automatically loads and links components together by searching for a //default// implementation of a given interface type. This search is based on simple name equivalence between the interface type name and the compiled component'​s ​ file name (so in this case the interface type ''​Tokeniser''​ maps to the compiled component ''​Tokeniser.o''​). Note that Dana **does not** automatically compile components. More information on how Dana searches for default implementation components is provided in the next section.
  
-In Dana we generally use interfaces to represent behaviour and we use data types to represent data. There'​s nothing to stop you using interfaces to represent data except for the excessive use of "​getter"​ and "​setter"​ functions that this may entail (though sometimes the use of an interface may actually be appropriate to represent complex data such as an XML document).+In Dana we generally use interfaces to represent behaviour and we use data types to represent datathough sometimes the use of an interface may actually be appropriate to represent complex data such as an XML document.
multi-component-program.txt · Last modified: 2017/06/23 09:34 by barryfp