The Freya Programming Language

Projects and source files

See also

You have two ways to develop a Freya application or class library: you can use independent files, when the code is short enough, and you can create a Freya project, grouping several source code files in a single logical entity.

Projects and the Freya Compiler

All Freya code is compiled by the Freya Command Line Compiler, which is located in a file called frc.exe, in the Freya instalation directory. Though it looks like an ordinary executable file, it can also be referenced by any other .NET assembly, and that's how Sharp Blade communicates with the compiler.

Freya's compiler, actually, has no predefined notion for projects. However, it can compile several source files in a single operation. It's Sharp Blade who takes advantage of this feature to define and implement projects.

NoteNote
Freya's compiler is, technically speaking, a "managed application". It has been developed using C# and it has been designed to run on the .NET framework. This design decision allows SharpBlade to communicate with frc.exe very easily. Actually, frc.exe classes are loaded in process memory as a regular Sharp Blade's component.

Freya projects

Freya projects are stored in a file with frp extension. These files contain XML code specifying which source files belongs to the project, which assemblies are referenced from these files and several compiling options.

<?xml version="1.0" encoding="utf-8"?>
<Project>
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <StartupObject />
        <Preconditions>0</Preconditions>
        <Postconditions>0</Postconditions>
        <Debug>0</Debug>
        <DefineConstants />
    </PropertyGroup>
    <ItemGroup>
        <Compile Include="shapes.fre" />
        <Compile Include="engine.fre" />
        <Compile Include="geometry.fre" />
        <Compile Include="materials.fre" />
        <Compile Include="pixels.fre" />
        <Compile Include="program.fre" />
        <Compile Include="lights.fre" />
    </ItemGroup>
    <ItemGroup>
        <Reference Include="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <Reference Include="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </ItemGroup>
</Project>

All file references are relative to the location of the frp file. In the above example, all source files are stored in the same folder as the project, but that's not a requirement, but a convenience. The only restriction is that source files and project files must all be stored in the same logical storage unit.

Source files

Freya's source files are identified by the fre extension. They all have the same high level structure and they are conceptually merged in a single virtual source file each time the project is compiled.

A typical Freya source file starts with an optional using clause, with global scope, followed by one or more namespace declarations. Each namespace acts as a container for type declarations and type implementations, and they may have their own using clasue.

// This clause affects all the file.
using System, System.Text;

namespace Freya.Trees

    // This clause only affects this namespace section.
    using Freya.Stacks, System.Collections.Generic;
    // ...

namespace Freya.Stacks
    // ...

namespace Program
    // ...

end.

The order of declaration doesn't matter at all. In the previous example, there is a reference to the Freya.Stacks namespace from a using clause inside the Freya.Trees namespace, despite the fact that Freya.Stacks is being defined below.

Project target

When a Freya project is successfully compiled, a single target file is created, containing a .NET assembly. There are two kinds of assemblies in .NET:

Only EXE assemblies can be executed by the operating system. In .NET v1.x, only DLL assemblies could be used as class libraries. Starting with .NET v2.0, you can also use an EXE assembly as a class library. EXE files are further divided in two categories:

Which kind of assembly is generated in each case is determined by the project's options.

See also

The Freya Programming Language
Program and file structure
Lexical structure
Namespaces
Implementation sections
using clauses
The entry point
Type declarations
Type members
Statements