Eve Scripts

Eve is designed to quickly build a data processing app that can have jobs to be executed in order on a precise schedule. You can write one aspect, or divide a project into many scripts that run together: aspects and modules. This page shows the project, the two kinds of script and what every script has in common. The next pages explain each kind: Aspects, Macros (several aspects in one file) and Modules.

Keywords of this phase

The keywords that phase 2, Eve Code Topology, adds to the core language (the core keywords are in Syntax). Each one is explained on the page in the last column.

KeywordMeaningExplained in
aspectheader of a script that runs: aspect name is; the kind word exclusive, concurrent or primary may come before itAspects
moduleheader of a library script; end name; closes itModules
fromstarts an import: from lib use (a, b);Modules
uselists the imported names of an importModules
exportlists the members a module makes public: export (Point, square);Modules
initializeinitialization region of a moduleModules
finalizefinal region of a process: runs when the process ends normally, by exit or by abortScripts
proceduredeclares a procedure: a subprogram outside a class that does work and returns no result; it is called as a statementSubprograms
applyruns an aspect and waits for it: apply report(10, @sum);Aspects

Projects

A project is a folder with a specific structure. It contains one or more applications that can run independent of each other on the same computer or a group of computers.

project structure

Next project contains two applications: server/agent and show folders where you should put your code (src+lib) and documentation (doc). This is a recommendation but not a hard rule.

$pro_home
project
  |-- agent
  |   |-- aspect1.eve
  |   |-- aspect2.eve
  |   ...
  |-- server
  |   |--  aspect1.eve
  |   |--- aspect2.eve
  |   ...
  |-- library
  |   |-- module1
  |   |     |-- module_script1.eve
  |   |     |-- module_script2.eve
  |   |     ...
  |   |-- module2
  |   ... 
  |       
  |-- documents
  |   |-- readme.md
  |   |-- index.html
  |   ...
  |-- agent.eve
  |-- server.eve

Running an aspect

Every program is an aspect. There is no separate kind of script for a small tool: a file with one primary aspect and its process main is the shortest program, and eve total.eve runs it. A primary aspect is designed to be run first, by a command; no aspect applies or starts it. A file does not start with #!: line 1 is a # title or a ## subtitle, or the code itself, because Eve is a language for projects and not a shell language.


# total: the shortest program
aspect total is
  process main is
    new total = 0 :Integer;

    for i in (1..10) do
      let total += i;
    done;

    print "total: {total}";
  return;
end total;

Statements are written only in a process, a function, a procedure or a method. A statement directly under the header, or before it, is an error. When the program grows, the aspect keeps its shape: write functions, classes and private processes beside main, move work to other aspects in asp/, or keep several aspects in one file, an Eve macro.

Which kind of script?

ScriptStarts withHas a processCan be runDefines globals
aspectprimary aspect, exclusive aspect (or aspect) or concurrent aspectyes: main, the entry point, and private processesa primary aspect: yes, eve name.eve; the others are called by nameits own state, created at each call
Eve macrodeclarations, then several aspects, exactly one of them primary aspectyes, main of each aspectyes, eve macro.eve runs the primary aspectshared declarations, seen by all its aspects
modulemodule name isno, initialize and finalizeimportedno, one private state

Scripts

Eve defines two kinds of scripts that together make a "project suite". Some scripts are reusable but some are specific to a single project. Here are all the possible scripts:

  • Aspect, created with the keyword "aspect" (also "exclusive aspect", "concurrent aspect" and "primary aspect"),
  • Module, created with the keyword "module".

Notes: One project can contain one or many primary aspects: each one is run by a command and is the entry point of its own run. An aspect has one public process, main, and may have private processes. An aspect is encapsulated: other aspects call it by its name and give it parameters. An aspect can "import" modules and can use classes or functions defined in these modules.

Features:

  • An aspect can import one or more modules;
  • An aspect applies or starts other aspects, at most three levels deep, never in a cycle;
  • An aspect has one public process, main; its other processes are private;
  • The primary aspect has the global scope of the run; every other aspect has its own state, created at each call;
  • An aspect has no public members; a module lists its public members in export (…), and they are used with the dot operator.

Regions

An aspect or a module has a single scope. There are no import, alias, constant or global regions: imports (from … use), aliases (def), constants (set), variables (new), classes, functions, methods and processes are declarations in the same scope, in any order. Indentation is mandatory: everything between the header and end name; is indented by exactly 2 spaces, and the compiler reports an error when the indentation is wrong. Only the header, the closing end and the comments before the header start at column 0. A process has its own regions, recover and finalize, aligned with the process keyword. The canonical skeleton of an aspect is below, of an aspect in Aspects and of a module in Modules.

Aspect skeleton:

An Eve script begins with one of these keywords: {"aspect", "exclusive", "concurrent", "primary", "module"}. Script name is the same as the file name without the extension. An aspect has no parameter list in its header: the parameters belong to its process, process main(parameters) is. The process is indented inside the aspect. A module has no process and no parameters.


** purpose of the aspect
aspect aspect_name is

  ** system variables and constants
  set $sys_con = value;
  set LIMIT = 10 :Integer;

  ** import modules
  from $path/library_name use (*);

  ** alias: qualifier suppression
  def AliasName = library_name.MemberName;

  ** constants
  set NAME = Value :Type;

  ** classes, functions and global variables
  class Person = {name:String, age:Integer} <: Object;
  set expression_name = (params) => (expression);
  new shared = value1 :user_type;

  ** main process
  process main is
    new my_var = value :Type;  ** private to the process
    ** executable region
    ...
  recover
    ** error handling area: retry, resume or abort
    ...
  finalize
    ** release locked resources, consume the job report
    ...
  return;
end aspect_name;

Members

  • a script can define members, visible in process;
  • a script can import public members from modules;
  • the primary aspect can "set" system variables and constants using "$" sigil;

Note: All declarations sit directly under the script header, indented by 2 spaces. They belong to the global scope, which is bound to the process scope.

Note: Only the primary aspect defines global states for the run. In its scope you can set constants and system variables, and define variables, classes, functions and methods. The other aspects have their own state, created at each call, and modules define public and private members instead (see Module Import).

The keyword "set" creates a constant; the keyword "new" creates a variable. Global constants and variables are static: they are created on the heap and have a permanent nature.

System Variables

System variables use prefix "$". These are defined and maintained by EVE virtual engine. Values for these variables can be read automatically by EVE engine at startup. Can be loaded from a configuration file (*.cfg). New variables can be defined by user for each script.

New system variables can be defined with the keyword set directly after the script header (or after the title comment), with 2-space indentation. These are constants that belong to the global scope, the same scope used by the primary aspect of the run.

Note:

  • System variables can be defined in a configuration file,
  • OS environment variables are visible as system variables: the variable NAME is read as $NAME,
  • System variables are usually defined in core EVE modules,
  • System variables can be defined or overwritten in program modules,

The system variables that Eve provides, with their types, are listed in one table: System Variables in the Syntax page.

Global Constants

The name of a constant is not enforced by the compiler; the tutorial only recommends it. By convention, constants use capital letters, and the next symbols in a constant name can be numbers or underscore but no special or Unicode character.

Example


** define global scope
  set PI  = 3.14 :Real;       ** global constant
  ...
  new var = 0    :Integer;    ** global variable
  ...

Notes:

  • You can create new global constants and variables;
  • Prefix "$" for system constants to avoid scope qualifier;
  • OS environment variables are visible as $NAME;
  • System constants are capitalized and also begin with "$";

Example


primary aspect test is

** constant of the aspect that is run
  set E = 2.718281828 :Real;    ** Euler's number

** the aspect that is run: class and variable
  class Person = {name:String, age:Integer} <: Object;
  new x = 0 :Integer;           ** global state
  ...

Notes:

  • Global constants are created using keyword "set", global variables using keyword "new",
  • All global states are bound to the process scope,
  • We are using operator "=" for initialization,
  • Operator ":=" executes an expression and can be used in the global scope, for example a string concatenation,
  • Constants are by convention using uppercase letters, the compiler does not check it,
  • $user_path is a shared variable defined by the user;
  • spaces in script-names are not supported you must use: "_";
  • aliases are created with "def" from public members of other modules;
  • a path is a string, built with the smart concatenation operator /

Importing Modules

The import is used to include public members from modules:

Syntax:


primary aspect script_name is
  ** define global system variable
  set $user_path := root_path/relative_path;

  from $user_path use (module_name,...);  ** specific modules
  from $user_path use (*);                ** find all modules
  ...
  ** create alias for some of the hidden members
  def new_name = module_name.member_name;
  process main is
    ...
  return;
end script_name;

Notes:

  • A path is a string. The operator / is a "smart concatenation": between strings it joins path segments and it becomes \ on Windows;
  • An alias is created with "def Name = library_name.MemberName;". An alias of a parameterized class, like ClassName[parameters], is not supported;

Process

A process is the executable region of a script, mandatory for aspects. An aspect has declarations, then one or more processes, process main is … return;, and the script closes with end script_name;. main is the entry point and the only public process; the other processes are private and are called by the processes of the same aspect, by their bare names. An aspect is run with apply aspect_name(args);: the caller waits.

A process can receive parameters, input and output (process name(n: Integer, @total: Integer) is). A process returns no result: its outputs are the parameters marked with "@". It can end with an error instead: the exit code of panic, raise, expect or assert is captured by the primary aspect. The arguments are passed in a list, apply reports(10, @sum);. The caller waits, so the outputs are ready on the next statement. The aspect that is run defines the global scope of the run: its processes read and change its declarations. An aspect that another aspect calls has its own state and no access to the caller: it receives data by parameters. The scope of an imported module is bound to the scope of the aspect that imports it.

While modules don't use the 'process' keyword, they have an initialization region that serves a similar purpose. This initialization region is executed first when a process starts. The initialization of a module runs within the process of the aspect that imports it, at each call of that aspect.

Process context

Every process has a local context. In this context you can define variables, and instantiate objects but you can't define classes, methods or functions. Process local members can't be shared but can be send as input/output parameters to subprograms or aspects.

Process Termination

Process can be early terminated using: "over" or "panic". This is a way to release all locked resources and terminate the process. The statement "over" ends the process it is in with code 0. The statement "panic" is an unhandled exception: it ends the whole application with code 1, not only the process; "panic 0" is not allowed and there is no "panic N". A failed "expect" always ends with code 2, and "raise" ends with an error code greater than 0.

Example:

Next code sequence is terminated after 11 iterations:


# terminate a program with: over
primary aspect test_over is

  process main is
    loop
      new i = 0 :Integer;
    do
      write "."; wait  10;
      over if i > 10;
      let i += 1;
    repeat;
  return;
end test_over;

Read next: Aspects