GithubHelp home page GithubHelp logo

caotic123 / magenta-languange Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.73 MB

A experimental language that compiles to Clang LLVM

C++ 68.40% LLVM 26.77% C 4.83%
llvm llvm-ir clang compiler magenta language-compiler

magenta-languange's Introduction

MAGENTA-LANGUAGE

function main() func print("Hello World")

Magenta is a untyped compiled language that compiles for LLVM ASSEMBLY to JIT CLANG. Magenta has a simple syntax and a basic imperative structures, however can supports redefition complex syntactics.

SYNTAX

The syntax of magenta is very simple every values is defined through of "()" (except strings) and most of reserverd words are inspired in imperatives languages c-like and a bit of lisp family of functional languanges.

function do()
#x = (3)
#limit = (36)
if ((x) <= (limit))
func print_n((x))
#x = ((x+3)*(x-2))
while

TYPES

Magenta don't have complete system of types but the compiler doesn't check all possibilities of errors this means that you don't need declare types of variables.

Consider this code:

#int = (23)
#string = "ola"

Other detail is that all variable are references, so if you defines:

#var = (func())

The variable var recevied the value of andress of function returned of func this else means that the compiler don't know what type of this variable then Magenta consider this var as unknow type. Operations as unknow type are treated as number(double). To fix this just cast the variable.

POINTERS

If in Magenta everything is referenced then it is possible to allocate memory and do not give anything special treatment for this variable.

#string = (new_str(23))
//return char with 23 spaces of memory allocated
#string = "ola"
#x = (number())
#x = (232) #x = (0.2322)

new_str() and number() mag_alloc() can be used to a space of memory that isn't temporary and local

COMPILING

Just add the file .mag in folder mag_files with the code and run compiler.

METAPROGRAMMING

Like C language Magenta supports textual macros, however magenta macros are hygienic and can descrive the new syntax.

#var = (func()+2)
//this is not possible

But with macro is possibility magenta compiles run this expression. First should defines a new macro syntax#define macro-syntax (anything) and the syntax. I will consider [(value)] to recevied function so... [(function())]

#define macro-syntax [(var y)]

#end macro

This macro captures (var y) as function (but can be a variable or anything in "()") Now, just add code generation.

#macro
#define macro-syntax [(var y)]
vars {($x)}
top {#($x) = (($y))}
return {($x)}
#end macro
#macro

function main() #var = ([(func())]+2)

Variables defined in (vars {}) are hygienic and (top, down, return) generates codes in relative position of macro syntax found. Magenta macros works like a grammatic free of context then we can translate this

where [([(x)])] in magenta is [([(#var y)])]
[ = [
([(x)]) = (var y)
] = ]
[ = [
(x) = (var y)
] = ]
A -> [BCD
B -> (free
C -> ) | A)
D -> ]
free -> anything
 
[BCD (<- A)
[(freeCD (<- B)
[(CD (<- free)
[(A)D (<- C)
[([BCD)D (<- B)
[([(xCD)D (<- C)
[([(x)D)D (<- D)
[([(x)])D (<- D)
[([(x)])]

Simple examples: https://github.com/caotic123/Magenta-Languange/tree/master/mag_files

BULDING

You don't need any lib for compilation, but magenta requires CLANG for run. Clang(uses Pre-Built Binaries) is available in:

In linux just extract magenta source and in terminal:

sudo apt install clang
g++ -o Magenta -std=c++11 compiler.cpp macro.cpp magenta_.cpp magenta_headers.cpp magenta_lex.cpp main.cpp module.cpp

In windows install binares in (http://releases.llvm.org/download.html) and add path variable environment in O.S and compile magenta in mingw or clang.

magenta-languange's People

Contributors

caotic123 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.