Giter VIP home page Giter VIP logo

yona-lang / yona Goto Github PK

View Code? Open in Web Editor NEW
124.0 8.0 6.0 5.49 MB

Yona is a modern take on a dynamic general-purpose programming language with advanced functional programming, minimalistic ML-like syntax, strict evaluation, for GraalVM polyglot virtual machine (VM).

Home Page: https://yona-lang.org/

License: GNU General Public License v3.0

ANTLR 3.05% Java 94.18% Shell 0.78% Dockerfile 0.13% PowerShell 0.20% Erlang 0.54% JavaScript 0.58% Python 0.53%
programming-language functional-languages asynchronous graalvm jvm-language mainstream-languages yatta-language yona

yona's People

Contributors

akovari avatar fniephaus avatar kurobako avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yona's Issues

Exceptions

  • Syntax:
try <expr>
catch
<triple pattern> -> <expr>
end

where the triple is:

  • symbol

  • message

  • stacktrace

  • Mapping of built in errors, such as match error, or bad argument error.

  • match exception

  • exceptions in promises

  • allow cattching _

Run system commands

Ability to run system commands.

Syntax

system ["ls", "-al"]

Pipes

Allow redirecting input/output

(output, err_output) = input |> system []
(output, err_output) = system [] <| input

Or directly pipe system commands without language involvement

system [] |> system []

Module imports

This feature allows importing and using modules.

Syntax

Calling a function from a module:

package.Module.function arg1 arg2

Functionality

let Module = package.Module in <expr>

Behaviour

Module call syntax locates the module from the cache or file system location, makes sure it's parsed and cached.

Module call syntax is to be extended in the future to allow reading a library manifest file (to be defined) and import module from specified library version/location.

Optimizations

  • tuples represented as arrays of objects (this wouldn't allow for specific tuple extensions such as FileTuple)
  • rewrite BinaryOperationNode using Specialization
  • see if operations with constants can be be calculated in the parser (1 +2)
  • check lambda lifting. Lift lambdas into non-closures unless necessary, so stack doesn't have to be restored when it is pure function
  • check if lambdas capture any variables, if not, avoid materializing stack
  • avoid using java collections in pattern matching
  • allow let expression to be truly concurrent
  • make sure promises are unwrapped whenever possible before calling map
  • see if TruffleBoundary can be removed from FrameSlotAliasNode and FrameSlotAliasNode and AnyValueNode
  • make module/function cache indexed by Seq, not String
  • cache resolved dependencies in the PatternLetNode

Syntax

  • make sure you can't assign a proper function in let, only lambda
  • package import uses slash, make sure division works fine too
  • single letter identifiers
  • end after case
  • end after catch
  • end after do
  • backticks
  • operators precedence

Pattern matching

  • simple types
  • tuple
  • sequence
  • let expression
  • function patterns
  • lambdas
  • guards
  • non-linear patterns
  • reverse sequence
  • multiple head / tails
  • combining head and tail in a single pattern
  • dict
  • modules

Tests

  • multiple definitions of same functions, but different number of args
  • binary operations
  • nested case
  • functions equality
  • calling dynamic modules
  • async modules
  • string escape sequences
  • unicode strings
  • identity 5+3
  • non-linear patterns in function definition + currying
  • make sure stdlib functions and modules cannot be overridden
  • pass yatta seq/dict/tuple to Java::new

Add bitwise complement operator

Bitwise Complement () –
This operator is unary operator, denoted by ‘
’. It returns the one’s compliment representation of the input value, i.e, with all bits inversed, means it makes every 0 to 1, and every 1 to 0.
For example,
a = 5 = 0101 (In Binary)

Bitwise Compliment Operation of 5

~ 0101


1010 = 10 (In decimal)
Note – Compiler will give 2’s complement of that number, i.e., 2’s compliment of 10 will be -6.

Operators

arithmetic

DONE

bitwise

DONE

  • and = a & b
  • or = a | b
  • xor = a ^ b
  • not = ~a
  • leftShift = a << b
  • signPropRightShift = a >> b
  • zeroFillRightShift = a >>> b

logical

DONE

  • and = expr && expr
  • or = expr || expr
  • not = !expr

sequence

DONE

  • el in seq
  • seq join = list ++ list
  • seq prepend = el :> list
  • seq append = list <: el

dict

DONE

  • key in dict
  • d < t | test whether every key in d is in t - proper
  • d >= t | test whether every key in t is in d
  • d < t | test whether every key in d is in t - proper
  • d >= t | test whether every key in t is in d
  • d | t | new set with elements from both s and t
  • d & t | new set with elements common to s and t
  • d ++ (k, e) | new dictionary with element e
  • d -- t | new dictionary with keys in d but not in t
  • d ^ t | new dictionary with keys in either s or t but not both

set

DONE

  • el in set
  • s < t | test whether every element in s is in t - proper
  • s >= t | test whether every element in t is in s
  • s < t | test whether every element in s is in t - proper
  • s >= t | test whether every element in t is in s
  • s | t | new set with elements from both s and t
  • s & t | new set with elements common to s and t
  • s ++ e | new set with element e
  • s -- t | new set with elements in s but not in t
  • s ^ t | new set with elements in either s or t but not both

pipeline

DONE

  • |> and <|

stdlib not bundled in yatta-component.jar

akovari@DESKTOP-G6LMGIO:/mnt/c/Users/kovar/devel/yatta$ yatta
Transducers|>println
== running on GraalVM CE:20.0.0
Module{fqn=Transducers, exports=[done], functions={done=done/0}, records={}}
Module{fqn=Transducers, exports=[done], functions={done=done/0}, records={}}

Optimize needless pattern matching

(async \->{1}) ++ (2) translates to

InvokeNode{functionNode=IdentifierNode{name='async'}, function=null, argumentNodes=[FunctionNode{name='$lambda-0', cardinality=0, expression=CaseNode{expression=TupleNode{expressions=[]}, patternNodes=[PatternNode{matchExpression=TupleMatchNode{expressions=[]}, valueExpression=SetNode{expressions=[IntegerNode{value=1}]}}]}}]}

Polyglot

  • calling Java method
  • instantiating a Java class
  • exporting Yatta modules to polyglot API
  • calling Yatta function from Java/JS
  • dealing with Java exceptions inside Yatta
  • dealing with Yatta exceptions in Java/JS

Builtin modules

Allow not only built in functions but also modules.

Tasks:

  • modules implemented in java
  • modules implemented in the language
  • modules combining both languages
  • make sure module names are included in exception stack traces

Strings

Strings are on the surface represented as lists of characters. Character is a UTF-8 character.

Character represented using java int type.

Other features

  • character represented as java int. In the language, it has a dedicated type: 'a'
  • multi-line
  "
  The quick brown fox
  jumps over the lazy dog
  "
  • interpolation
    "Hello {name}."

  • pattern matching

Solve the issue with threads not being closed after calling context.close()

Exception in thread "main" org.graalvm.polyglot.PolyglotException: java.lang.IllegalStateException: The language did not complete all polyglot threads but should have: [Thread[Polyglot-yatta-6,5,yatta-io], Thread[Polyglot-yatta-7,5,yatta-io]]
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotLanguageContext.dispose(PolyglotLanguageContext.java:351)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.disposeContext(PolyglotContextImpl.java:1153)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.closeImpl(PolyglotContextImpl.java:1072)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.close(PolyglotContextImpl.java:873)
        at org.graalvm.sdk/org.graalvm.polyglot.Context.close(Context.java:645)
        at org.graalvm.sdk/org.graalvm.polyglot.Context.close(Context.java:666)
        at yatta.Launcher.executeSource(Launcher.java:62)
        at yatta.Launcher.main(Launcher.java:37)
Original Internal Error:
java.lang.IllegalStateException: The language did not complete all polyglot threads but should have: [Thread[Polyglot-yatta-6,5,yatta-io], Thread[Polyglot-yatta-7,5,yatta-io]]
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotLanguageContext.dispose(PolyglotLanguageContext.java:351)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.disposeContext(PolyglotContextImpl.java:1153)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.closeImpl(PolyglotContextImpl.java:1072)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.close(PolyglotContextImpl.java:873)
        at org.graalvm.sdk/org.graalvm.polyglot.Context.close(Context.java:645)
        at org.graalvm.sdk/org.graalvm.polyglot.Context.close(Context.java:666)
        at yatta.Launcher.executeSource(Launcher.java:62)
        at yatta.Launcher.main(Launcher.java:37)
Caused by: Attached Guest Language Frames (0)

Records

  • Implemented using tuples, where the first element is the name of the record

  • Syntax sugar, derived from tuple syntax, that is removed during parsing

  • Records are module scoped

  • Declaration syntax:

record Person = (first_name, last_name)

  • New record syntax:

let person = Person(first_name = "Adam") # at least one field is required, although it can technically be ()

  • Field access syntax:

person.first_name

  • Pattern matching syntax:

fun Person(first_name=f, last_name=l) # where f and l are bound to the values of first/last name from that record

fun p@Person # way to access the whole record in pattern matching, similar to sequences for example

  • Update record field:

let new_record = old_record(field = value)

String patterns

Allow pattern matching on strings, such as:

"hello {who}"

Context managers

Introduce a new type of with expression. This expression will allow accessing and manipulating local context variables within the expression in the body of the with expression.

Standard library module will be necessary to allow reading/writing context variables.

Syntax

with <expr1> (as <identifier>)?
<expr2>
end

Usecases

  • transaction context
  • dict/set hasher, seed

Further considerations

  • the context needs to be thread-safe and work across threads whenever necessary (such as calling async)
  • the distinction between builtin functions context and user library context (so that for example STM TX id cannot be overridden by the user code - either intentionally or by mistake)

Generators

  • Seq comprehension:
    [a * 2 | a <- [1, 2]]

  • Seq comprehension with a filter:
    [a * 2 | a <- [1, 2] if a > 2]

  • Dict comprehension:
    {a = 2 | a <- [1, 2]}

  • Dict comprehension with a filter:
    {key = val * 2 | key = val <- {1: 2, 3: 4} if val > 2}

  • Set comprehension:
    {a * 2 | a <- [1, 2]}

  • Set comprehension with a filter:
    {a * 2 | a <- [1, 2] if a + b > 3}

File module

  • open
  • close
  • read file: binary / text
  • read line: binary / text
  • write file: binary / text
  • seek
  • create temp file
  • delete file

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.