Luna (programming language)

from Wikipedia, the free encyclopedia
Luna
Luna logo
Luna logo
Basic data
Paradigms : Multiparadigms ( imperative , object-oriented , procedural , structured , functional )
Publishing year: 2011
Developer: Richard Gordon Faika
Current  version : 2018.r1   (February 13, 2018)
Current preliminary version: none   ()
Typing : Static typing (static typing)
Influenced by: Xojo , Pascal , C ++ , GFA-Basic
avr.myluna.de

Luna ( Latin for moon ) is an imperative, functional and object-based programming language with a visual development environment for Linux , Mac OS X and Windows . It supports imperative , structured , functional and object-based programming.

Implementations

There is an implementation for microcontrollers of the AVR architecture . An implementation for x86-64 has been announced.

properties

Language design

The Luna language consists of relatively few key words (“language core”); It receives its actual functionality - similar to the C / C ++ languages ​​- from the standard libraries and, depending on the area of ​​application, additional libraries and frameworks. Luna focuses on the language tools used to develop libraries.

One of the strengths of Luna is the ability to combine efficient, machine-level programming with powerful language resources that summarize simple to complex implementation details and largely hide them behind abstract command sequences. The template metaprogramming as in C ++ comes into play , a technique that allows an almost uncompromising combination of efficiency and abstraction.

Resource management

It is planned to manage memory manually and to access memory areas directly with regard to machine-level programming. However, Luna also has an integrated, automatic, generational garbage collection designed for high efficiency . In practice, the lifespan of objects is usually very different. On the one hand, there are objects that survive the entire runtime of the application. On the other hand, there are a large number of objects that are only needed temporarily to carry out a single task. Every time the release algorithm is used, long-lived objects are moved to a higher generation. The advantage is that garbage collection can be performed more frequently and faster for lower generations, since only some of the objects need to be moved and their pointers changed. There is a high probability that higher generations contain only living (or very few dead) objects and therefore need to be cleaned up less often. The specialty of the algorithm implemented in Luna is that it does not need any counters for the lifetime of the individual objects and that all objects have backward references. The backward references allow “dead” memory objects and faulty object variables to be identified.

Development environment

The entire Luna development environment "Luna Studio" consists of an integrated development environment (IDE), a preprocessor (macro processor) , compiler and assembler . Programs can either be written in the IDE or in a normal text editor. In addition to the generally desirable functions such as syntax coloring, automatic indentation, code structuring and auto-complete, the IDE offers direct support for the individual Atmel AVR controllers. In addition, there is a powerful library editor, directory of the controller defines, a GUI for AvrDude and numerous other useful tools.

Target architecture

The cross-compiler / assembler and the development environment support the microcontrollers of the AVR architecture from Atmel . This includes the Attiny, Atmega and Atxmega controller families.

Language features in detail

The syntax is essentially based on the programming languages Xojo (formerly RealBasic) and Pascal , which makes it easier for beginners to get started with Luna. Luna is also influenced by C ++ and implements numerous operators and directives.

Definitions / aliases

With definitions, commands, command combinations or expressions can be linked to an identifier in the sense of an alias. The identifier can then be used in the source code as if it were the assigned expression. Instead of the placeholder, the compiler automatically uses the expression assigned to the name during the compilation process. This also includes the so-called define functions (macro functions) known from C / C ++. I.e. a virtual function name can be used instead of an expression. The parameters are then inserted by text replacement in the expression on the right.

Associated commands:

  • #define name as expression
  • #undef name

Structures

Structures combine data types and / or data objects statically under one name. Structures can be used nested.

// Struktur deklarieren
struct point
  byte x
  byte y
endstruct

dim a(3) as point  // Array mit 4 Elementen des Typs "point" dimensionieren

a(0).x = 1
a(0).y = 20
a(1).x = 23
a(1).y = 42

amounts

Quantities are special expressions that summarize a collection of constant values ​​and make it easier to manage or assign collections of data (e.g. a list of numbers and text). There is a lot in the source code within curly brackets {…}. If a structure declaration is the basis, further subsets can be embedded within a set.

struct mystruct
  byte   myarray(2)
  word   level
  string text[14]
endstruct
 
data table
  mystruct{ { 1, 2 ,3 }, 4, "hallo" } 'Text wird auf die in der Strukturdeklaration 
  mystruct{ { 5, 6 ,7 }, 8, "ballo" } 'definierten Länge von "text" mit Leerzeichen aufgefüllt.
enddata

Numeric data types

Byte, Uint8, Integer, Int16, Word, Uint16, Long, Uint32, LongInt, Int32, Single, Float

Object data types

String, MemoryBlock, Graphics, sPtr, dPtr, ePtr

It is also possible to program your own objects (classes) that behave like object data types.

Methods

Methods can be generated with the keywords procedureand function. In contrast to procedures, functions provide a return value. The following are also supported:

 function probe(zahl1 as integer, zahl2 as integer) as longint
   dim zahl3 as longint
   zahl3 = zahl1 * zahl2 + 10
   if zahl3 > 128000 then
     zahl3 /= 64
   end if
   return zahl3
 endfunc

Classes

In Luna, classes can be defined with which functions can be retrofitted in the sense of a module or a self-contained library. They are implemented similar to the units in Pascal.

// Deklaration
Class test
  const Version = "1.0"
  dim a as byte
  Procedure Init()
    print "Initialisierung"
    print "a = "+str(a)
  EndProc
  Function GetData(x as byte, y as byte) as single
    mul y,4
    y=y+x
    return tabelle.SingleValue(y)
  EndFunc
  data tabelle
    .dw &h1234,&h5678,&h9aab
    .dw &h1234,&h5678,&h9aab
    .dw &h1234,&h5678,&h9aab
    .dw &h1234,&h5678,&h9aab
  enddata
EndClass

The call in the program text would look like this:

 print test.Version       // Ausgabe
 test.Init()              // Procedure aufrufen
 var = test.GetData(0,2)  // Funktion aufrufen
 test.a=123               // Wert zuweisen
 print str(test.a)        // Wert lesen und ausgeben

Inline assembler

Assembler code can be embedded in the program text , with which runtime-critical areas can be optimized.

asm
  ldi  _HA0,0x2a
  ldi  _HB0,0x09
  call _MathMul8u
endasm

Sample code

The classic hello world program looks like this:

 avr.device = atmega168
 avr.clock  = 8000000
 avr.stack = 32

 uart.baud = 19200
 uart.rxd.enable
 uart.txd.enable

 print "Hallo Welt!"

 do
 loop

Example of a recursion :

 function factorial(n as longint) as longint
   if n = 0 then
     return 1
   else
     return n * factorial(n - 1)
   end if
 endfunc
Luna-AVR-IDE

Web links

Individual evidence

  1. Luna x64 teaser. October 2, 2016, accessed October 2, 2016 .