1. Pierre Surply
  2. Mara

Source

Mara /

Filename Size Date modified Message
compiler
m4
samples
stdlib
utils
121 B
34.3 KB
532 B
22.1 KB
3.1 KB
27.5 KB
137.9 KB
785 B
13.7 KB
10.1 KB

Mara Programming Language

What is Mara ?

Mara is a programming language dedicated to 8bit ATMEL AVR microcontrollers with a focus on simplicity and productivity.

The goal of this project is to simplify the programming of these microcontrollers for all those who do not wish to use (or learn) the C or assembly language.

Mara is also compatible with Arduino boards based on AVR.

The core language is still under development. Although stable version is not available, Mara can be used experimentally.

Examples

Basic

begin setup
        PORTD.set_mode(0xFF)
        PORTB.set_pin_in(1)
end

begin loop
        waitfor PORTB.read_pin(1)
        PORTD.write(42)
        waitfor not PORTB.read_pin(1)
        PORTD.write(0)
end

Factorial

# fact.mr

static

func fact(n)
        return n = 0 ? 1 : \
               (n * fact(n - 1))
end

# main.mr

using fact

begin setup
        PORTD.set_mode(0xFF)
        PORTD.write(fact(3)) # print 6
end

begin loop
end

List

begin setup
        PORTD.set_mode(0xFF)

        var l <- [1; 1337; 21; 4]
        l.insert(1, 42)
        l.push(0)

        PORTD.write(l[2]) # print 42

        del l
end

begin loop
end

String

begin setup
        var s <- new string(32)

        s.write("Hello")
        s.cat(" World !")

        PORTD.write(s[6]) # print 'W' : 0b01010111

        del s
end

begin loop
end

Classes

# point.mr

integer x
integer y

func init(nx, ny)
        self.x <- nx
        self.y <- ny
        return self
end

func squared_dist()
        return (self.x * self.x) + \
               (self.y * self.y)
end

# main.mr

begin setup
        PORTD.set_mode(0xFF)

        var p <- new point(2, 3)

        PORTD.write(p.squared_dist()) # print 13

        del p
end

begin loop
end

Dependencies

  • avrdude (driver program for AVR programmer)

Edit Mara code with Emacs

First, copy the file utils/mara-mode.el in your ~/.emacs.d/ directory.

Then, add the following lines to your ~/.emacs file :

(autoload 'mara-mode "~/.emacs.d/mara-mode.el" "" t)
(setq auto-mode-alist (cons '("\\.mr\\w?" . mara-mode) auto-mode-alist))

Installation

$ ./configure
$ make
# make install

Usage

marac FILE [OPTIONS]...

The compiler support the following flags :

  • -mmcu MCU name
  • -I Include folder
  • -v Verbose
  • -clean Remove build directory and .hex files
  • -help Display this list of options
  • --help Display this list of options

Contact

  • Pierre Surply (pierre.surply@gmail.com)