Coder Social home page Coder Social logo

leek-wars / leekscript-next Goto Github PK

View Code? Open in Web Editor NEW
50.0 8.0 8.0 6.22 MB

A dynamically typed, compiled just-in-time programming language used in Leek Wars' AIs

Home Page: https://leekscript.com

License: GNU General Public License v3.0

C++ 98.54% Makefile 0.62% C 0.20% Java 0.11% Python 0.10% LiveScript 0.39% JavaScript 0.02% Dockerfile 0.01% HTML 0.01%
leek-wars jit langage cpp llvm programming-language leekwars compiler

leekscript-next's Introduction

Leek Wars

Codacy Badge CI

The Leek Wars website frontend, in Vue.js + TypeScript. This is the frontend repository, altough it also contains all the information about the whole Leek Wars projet.

Related projects: LeekScript and Leek Wars fight generator.

Banner

Deployment

The project is very easy to install and deploy in 10s:

git clone https://github.com/leek-wars/leek-wars.git
cd leek-wars
npm i
npm start

Then go to localhost:8080 in your browser.

Be careful, this project is only the front end of Leek Wars, so it's connected to the production server. When you log into this local version, you will use your real account!

Architecture

Banner

Hacking

I gladly accept pull requests to Leek Wars. Before starting work on a feature, see the contribution guidelines.

Libraries used

Social media

License

Distributed under the GPL3 license. Copyright (c) 2016-2023, Pilow

leekscript-next's People

Contributors

5pilow avatar hazurl avatar lbaali avatar mariogeiger avatar meucaa 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leekscript-next's Issues

References

Pass a reference in an array, functions etc.

let x = 12
let a = [@x]
a[0]++
// x = 13

Include gmp

https://gmplib.org/

Il faudra peut être avoir une syntaxe pour déclarer des grands nombres, sinon il faut checker en permanence si ça dépasse

let big = 4343876987654332287876543 // détecté automatiquement comme grand nombre
let big = 0l // suffixe l qui force

"l" comme large ou long

For loop : previously defined variable initialisations are ignored

The following LS code :
let a = 0
for (a = 100 ; a < 5; a++) do print(a) end
print("test " + a)

Produces the following :
>>> 0
>>> 1
>>> 2
>>> 3
>>> 4
>>> 'test 5'

The same sort of problem appears in foreach loop :
let b = 1
for (b in [1,2,3,4]) { print(b) }

>>> 1
>>> 1
>>> 1
>>> 1

Classic function syntax

function squareRoot(x) {
     return x ** 2
}

instead of just

let squareRoot = function(x) {
     return x ** 2
}

push

let y = [1,2];
y.push(4);
y

expecting [1,2,4]
but returns [1, 2, 32804560, 0]

Class reflexion

(class).attrs
(class).methods
(class).staticAttrs
(class).staticMethods
(class).keys

User modules

module mylib {
    class Super {}
    const VALUE = 12
}
let mylib = import('mylib')
ou ?
import('mylib')
ou ?
import mylib
var s = new mylib.Super()
var a = mylib.VALUE

Recursive functions

function fact(n) {
    return if n == 1 then 1 else n × fact(n - 1) end
}
// or
let fact = n -> if n == 1 then 1 else n × fact(n - 1) end
// or
let fact = n -> n == 1 ? 1 : n × fact(n - 1)

fact(12)

Closures

let a = 2
let f = x -> x + a

and

let add = x -> y -> x + y
let add5 = add(5)
add5(12) // 17

Rotation bitwise operators

^>   Right rotation
^<   Left rotation
^>=  Right rotation with assignment
^<=  Left rotation with assignment

Pattern matching

Syntaxe des switches

Switch conventionnels :

switch(variable) {
case 1 :
 /* do something */
break; // optionnel. Si non présent, continue l’exécution des autres blocs de switch jusqu'à la fin ou un break
case 2 : 
/* do something */
break;
default :
/* cas par défaut */
}

Switch inversés :

switch(variable) {
case 1 :
/* do something */
// break est le comportement par défaut
case 2 :
/* do something */
continue; // pour obtenir le comportement des switch conventionnels, on utilise le mot clé continue
default :
/* cas par défaut */
}

L'avantage de cette version et sa plus grande facilité lorsqu'on débute. On n'a pas le cas complexe (et les erreurs bizarres que ça entraine) du break oublié, mais le mot clé permet d'autoriser l'ancien comportement

Switch à syntaxe allégée :

switch(variable) {
1 : 
/* do something */
// fonctionnent en conventionnel ou inversé */
2 : 
/* do something */
default :
/* cas par défaut */
}

Plus léger à écrire, pas de perte d'infos pour autant, le mot clé case est juste enlevé

Pattern matching
Évolution du switch. Permet de matcher des patterns dans les nombres :
Possibilité de l'intégrer aux switch, ou utiliser un nouveau mot clé pour bien signifier la différence (et remplacer switch par çà, vu que c'en est une évolution)

match(variable) {
1: debug('La variable vaut 1 !');
2..10 : debug('la variable est comprise entre 2 et 10 inclus');
1 | 2 | 3 | 5 | 8 | 13 : debug('Appartient à la suite de Fibonacci !!');
'string' : debug('Est une chaine de caractère valant "string"'); // plus support des divers types possibles, comme un switch normal
[1, 2] : debug('Est un tableau valant [1, 2]);
}

Command line parameters rework

Top-level

leekscript
~~ LeekScript v1.0 ~~
>>

File execution

leekscript -f file.ls

Snippet / Script execution

leekscript -s "[1,2,3] ~~ x -> x ^ 2"
[1,4,9]

Pass a context (as json)

leekscript [...] -c "{a: 12, b: true}"

Get the result as json

leekscript [...] -j
{result: 12, ctx: {...}, time: 2321312, ops: 21211}

Get the version

leekscript -v
1.0

Launch tests

leekscript -test

Examples

leekscript -j -s "a + b" -c "{a: 12, b: 5}"
{result: 17, ctx: {a: 12, b: 5}, time: 124, ops: 1}

String.number()

Convert the string to a number if possible
String.number("12") // 12
"-12.5".number() // -12.5

Implement switch instruction

Syntax example (same behavior as C switch)

let res = switch value {
   case 1:
   case 2:
       print("two")
   case 3:
       "hello" 
       break
   case 4:
       "goodbye" 
       break
   default:
       "error"
}

Destructuring

var [a,b,c] = [1,2,3]; // a = 1, b = 2, c = 3
var [d,,f] = [1, 2, 3]; // d = 1, f = 3

// si étalement :
var [g, h, ...i] = [1, 2, 3, 4]; // g = 1, h = 2, i = [3,4]

Peut s'ajouter aux switch le pattern matching est utilisé

switch([1, 2]) {
   [x, y]: debug('Valeurs : ' + x + ', ' + y);
   [x,] : debug('La première valeur est un ' + x);
   [x, 2] : debug('Valeurs : ' + x + ', 2');
   _ : debug('default'); // syntaxe de rust, un mot clé à la default est aussi envisageable
}

Array spreading

var a = [4, 5, 6];
var b = [1, 2, 3, ...a, 7]; // [1, 2, 3, 4, 5, 6, 7]

Array.chunk(size = 1)

let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
array.chunk(4) // [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]
array.chunk(1) // [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]

Cascade notation

querySelector('#button') // Get an object.
  ..text = 'Confirm'   // Use its members.
  ..classes.add('important')
  ..onClick.listen((e) => window.alert('Confirmed!'));

Array.unique()

Remove duplicated values from the array and return a new one

[1, 1, 2, 2, 2, 3, 4, 5, 5].unique() // [1, 2, 3, 4, 5]
["hello", "world", "hello"].unique() // ["hello", "world"]

Constants

let height = 12
const name = "mike"

to decide

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.