Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Aleo and Leo language support #6551

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a7f7202
Adds Aleo & Leo to languages.yml, samples, and grammar
Sep 19, 2023
34b3d5e
adds Leo and Aleo to languages.yml, their samples, and their grammar
Sep 19, 2023
3af2c58
Update languages.yml to include new color
Sep 25, 2023
1f58d8c
Update languages.yml change color hex to uppercase for Leo and Aleo
Sep 25, 2023
e68b00c
removing basic_bank examples, updating grammars, and adding credits.a…
Sep 27, 2023
4d41fd5
Update .gitmodules to remove ABNF grammars.
Sep 27, 2023
74ab427
Delete samples/Aleo/credits.aleo
Sep 27, 2023
e4f21de
update submodules to sync with grammars post test completion
Sep 28, 2023
a30877e
removing old samples and adding new ones that are more aligned
Sep 28, 2023
507eb6f
fixing submodules problem and the languages.yml location for Aleo re …
Sep 28, 2023
2179a88
adding grammars
Sep 28, 2023
9214578
fixing samples for *.aleo files
Sep 28, 2023
2318faf
Update mapping_operations.aleo
Sep 28, 2023
043e029
Update mapping_operations.aleo
Sep 28, 2023
5060f6e
fix licenses
Sep 28, 2023
b82b48d
removing submodules so that I can re-add them with the new licenses a…
Sep 29, 2023
0af1471
readding submodules with updated licenses
Sep 29, 2023
6513642
removing all submodule files because the new license is being added
Sep 29, 2023
cb549b6
removing all submodule files because the new license is being added
Sep 29, 2023
df4400f
fixed deatched head for submodule to master which update submodules a…
Sep 29, 2023
255adaf
Merge branch 'master' into Add-Aleo-and-Leo-Language-Support
Dec 6, 2023
74575f9
Merge branch 'master' into Add-Aleo-and-Leo-Language-Support
lildude Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1380,3 +1380,6 @@
[submodule "vendor/grammars/zephir-sublime"]
path = vendor/grammars/zephir-sublime
url = https://github.com/phalcon/zephir-sublime
[submodule "vendor/grammars/linguist-grammars"]
path = vendor/grammars/linguist-grammars
url = https://github.com/AleoHQ/linguist-grammars.git
3 changes: 3 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@ vendor/grammars/latex.tmbundle:
- text.tex.latex
- text.tex.latex.beamer
- text.tex.latex.memoir
vendor/grammars/linguist-grammars:
- source.aleo
- source.leo
vendor/grammars/linter-lilypond:
- source.lilypond
vendor/grammars/liquid-tm-grammar:
Expand Down
17 changes: 17 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ Agda:
tm_scope: source.agda
ace_mode: text
language_id: 12
Aleo:
type: programming
color: "#154BF9"
extensions:
- ".aleo"
tm_scope: source.aleo
ace_mode: text
language_id: 566431048
Alloy:
type: programming
color: "#64C800"
Expand Down Expand Up @@ -3742,6 +3750,15 @@ Lean 4:
tm_scope: source.lean4
ace_mode: text
language_id: 455147478
Leo:
type: programming
color: "#6814EC"
extensions:
- ".leo"
tm_scope: source.leo
ace_mode: text
wrap: true
language_id: 916034822
Less:
type: markup
color: "#1d365d"
Expand Down
38 changes: 38 additions & 0 deletions samples/Aleo/arrays_in_finalize.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* This program follows the license outlined, here: https://github.com/AleoHQ/snarkVM/blob/testnet3/LICENSE.md */

program arrays_in_finalize.aleo;

struct tree:
left as [[boolean; 4u32]; 1u32];
right as [[boolean; 4u32]; 1u32];

function test_arrays:
input r0 as [[boolean; 4u32]; 1u32].public;
input r1 as [[boolean; 4u32]; 1u32].public;
cast r0 r1 into r2 as tree;
and r2.left[0u32][0u32] r2.right[0u32][0u32] into r3;
and r2.left[0u32][1u32] r2.right[0u32][1u32] into r4;
and r2.left[0u32][2u32] r2.right[0u32][2u32] into r5;
and r2.left[0u32][3u32] r2.right[0u32][3u32] into r6;
cast r3 r4 r5 r6 into r7 as [boolean; 4u32];
cast r7 into r8 as [[boolean; 4u32]; 1u32];
async test_arrays r0 r1 into r9;
output r0 as [[boolean; 4u32]; 1u32].public;
output r1 as [[boolean; 4u32]; 1u32].public;
output r8 as [[boolean; 4u32]; 1u32].public;
output r2 as tree.private;
output r9 as arrays_in_finalize.aleo/test_arrays.future;

finalize test_arrays:
input r0 as [[boolean; 4u32]; 1u32].public;
input r1 as [[boolean; 4u32]; 1u32].public;
and r0[0u32][0u32] r1[0u32][0u32] into r2;
and r0[0u32][1u32] r1[0u32][1u32] into r3;
and r0[0u32][2u32] r1[0u32][2u32] into r4;
and r0[0u32][3u32] r1[0u32][3u32] into r5;
cast r2 r3 r4 r5 into r6 as [boolean; 4u32];
cast r6 into r7 as [[boolean; 4u32]; 1u32];
assert.eq r7[0u32][0u32] false;
assert.eq r7[0u32][1u32] false;
assert.eq r7[0u32][2u32] false;
assert.eq r7[0u32][3u32] false;
34 changes: 34 additions & 0 deletions samples/Aleo/mapping_operations.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* This program follows the license outlined, here: https://github.com/AleoHQ/snarkVM/blob/testnet3/LICENSE.md */

program mapping_operations.aleo;

mapping data:
key as u8.public;
value as u8.public;

function insert_contains_remove:
input r0 as u8.public;
input r1 as u8.public;
async insert_contains_remove r0 r1 into r2;
output r2 as mapping_operations.aleo/insert_contains_remove.future;

finalize insert_contains_remove:
input r0 as u8.public;
input r1 as u8.public;
contains data[r0] into r2;
assert.eq r2 false;
set r1 into data[r0];
contains data[r0] into r3;
assert.eq r3 true;
remove data[r0];
contains data[r0] into r4;
assert.eq r4 false;

function empty_remove:
input r0 as u8.public;
async empty_remove r0 into r1;
output r1 as mapping_operations.aleo/empty_remove.future;

finalize empty_remove:
input r0 as u8.public;
remove data[r0];
29 changes: 29 additions & 0 deletions samples/Aleo/sign_verify.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* This program follows the license outlined, here: https://github.com/AleoHQ/snarkVM/blob/testnet3/LICENSE.md */

program sign_verify.aleo;

function verify:
input r0 as signature.private;
input r1 as address.private;
input r2 as field.private;
sign.verify r0 r1 r2 into r3;
output r3 as boolean.private;

function verify_constant_signature:
input r0 as address.private;
input r1 as field.private;
sign.verify sign169ju4e8s66unu25celqycvsv3k9chdyz4n4sy62tx6wxj0u25vqp58hgu9hwyqc63qzxvjwesf2wz0krcvvw9kd9x0rsk4lwqn2acqhp9v0pdkhx6gvkanuuwratqmxa3du7l43c05253hhed9eg6ppzzfnjt06fpzp6msekdjxd36smjltndmxjndvv9x2uecsgngcwsc2qkns4afd r0 r1 into r2;
output r2 as boolean.private;

function literal_ops_on_signatures:
input r0 as boolean.private;
input r1 as signature.private;
input r2 as signature.private;
assert.eq r1 r1;
assert.eq r2 r2;
is.eq r1 r2 into r3;
is.neq r1 r2 into r4;
ternary r0 r1 r2 into r5;
output r3 as boolean.private;
output r4 as boolean.private;
output r5 as signature.private;
50 changes: 50 additions & 0 deletions samples/Leo/fibonacci.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This program follows the license outlined, here: https://github.com/AleoHQ/leo/blob/testnet3/LICENSE.md

program fibonacci.aleo {
// This calculates the n-th fibonacci number (up to 64th)
transition fibonacci(public n: u8) -> u128 {
assert(n <= 64u8);

let f0: u128 = 0u128;
let f1: u128 = 1u128;
let c: u8 = 0u8;

let z: u8 = reverse_bits(n);

for i:u8 in 0u8..8u8 {
if n > 0u8 {
let f2i1: u128 = f1 * f1 + f0 * f0;
let f2i: u128 = f0 * (2u128 * f1 - f0);
if z & 1u8.shl(c) == 0u8 {
f0 = f2i;
f1 = f2i1;
} else {
f0 = f2i1;
f1 = f2i + f2i1;
}
c = c + 1u8;
n = n >> 1u8;
}
}

return f0;
}

function reverse_bits(n: u8) -> u8 {
let reverse: u8 = 0u8;

for i:u8 in 0u8..8u8 {
if n > 0u8 {
reverse = reverse << 1u8;

if n & 1u8 == 1u8 {
reverse ^= 1u8;
}

n = n >> 1u8;
}
}

return reverse;
}
}
20 changes: 20 additions & 0 deletions samples/Leo/groups.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This program follows the license outlined, here: https://github.com/AleoHQ/leo/blob/testnet3/LICENSE.md

program groups.aleo {
// This function takes a group coordinate as input `a` and performs several operations which should output the `0group`.
// Note that the operations can be called as associated functions on the `a` variable.

transition main(a: group) -> group {
// unary
let b: group = a.double(); // 2a
let c: group = b.neg(); // -2a

// binary
let d: group = (a * 2scalar).add(c);

// generator
let e: group = group::GEN;

return d + e;
}
}
30 changes: 30 additions & 0 deletions samples/Leo/twoadicity.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This program follows the license outlined, here: https://github.com/AleoHQ/leo/blob/testnet3/LICENSE.md

program twoadicity.aleo {
// This function calculates the number of powers of two ("twoadicity")
// in the prime factorization of the input number `n`.
transition main(public n: field) -> u8 {
let remaining_n: field = n;
let powers_of_two: u8 = 0u8;
// Since field ints are 253 bits or fewer, any number in the field
// will have at most 252 powers of two in its prime factoring.
for i:u8 in 0u8..252u8 {
if is_even_and_nonzero(remaining_n) {
remaining_n = remaining_n / 2field;
powers_of_two = powers_of_two + 1u8;
}
}
return powers_of_two;
}

/* We define the is_even predicate on fields as follows.
If n is even and nonzero, clearly n/2 < n.
If n is odd, n-p is a field-equivalent negative number that is even, and
(n-p)/2 is a field-equivalent negative number closer to 0, greater than n-p.
If we add p to both of these negative numbers, we have
n/2 = (n-p)/2 + p = (n+p)/2 is greater than n and still less than p.
*/
function is_even_and_nonzero (n: field) -> bool {
return n / 2field < n;
}
}
2 changes: 2 additions & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Adblock Filter List:** [AdguardTeam/VscodeAdblockSyntax](https://github.com/AdguardTeam/VscodeAdblockSyntax)
- **Adobe Font Metrics:** [Alhadis/language-fontforge](https://github.com/Alhadis/language-fontforge)
- **Agda:** [agda/agda-github-syntax-highlighting](https://github.com/agda/agda-github-syntax-highlighting)
- **Aleo:** [AleoHQ/linguist-grammars](https://github.com/AleoHQ/linguist-grammars)
- **Alloy:** [macekond/Alloy.tmbundle](https://github.com/macekond/Alloy.tmbundle)
- **Alpine Abuild:** [atom/language-shellscript](https://github.com/atom/language-shellscript)
- **Altium Designer:** [textmate/ini.tmbundle](https://github.com/textmate/ini.tmbundle)
Expand Down Expand Up @@ -306,6 +307,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Latte:** [textmate/php-smarty.tmbundle](https://github.com/textmate/php-smarty.tmbundle)
- **Lean:** [leanprover/vscode-lean](https://github.com/leanprover/vscode-lean)
- **Lean 4:** [leanprover/vscode-lean4](https://github.com/leanprover/vscode-lean4)
- **Leo:** [AleoHQ/linguist-grammars](https://github.com/AleoHQ/linguist-grammars)
- **Less:** [atom/language-less](https://github.com/atom/language-less)
- **Lex:** [Alhadis/language-grammars](https://github.com/Alhadis/language-grammars)
- **LigoLANG:** [pewulfman/Ligo-grammar](https://github.com/pewulfman/Ligo-grammar)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/linguist-grammars
Submodule linguist-grammars added at d45530
Loading