Last active
June 26, 2016 18:02
-
-
Save PsichiX/c57ef2be3c320c8e39d1d4aa63ed0a6c to your computer and use it in GitHub Desktop.
Design of Jaeger - functional language based on Intuicio4 platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env jaeger | |
# directive that tells compiler | |
# what function from which native module we will use. | |
/use roar from "jaeger_std"/ | |
/use waitForMilliseconds from "jaeger_std"/ | |
#/jaegerify "file_open(path:*i8, mode:*i8):*i32" from "IO"/ | |
# directive that tells compiler which function is program entry point. | |
/start main/ | |
# structure definition. | |
{Person | |
# field name with type. | |
<age Int> | |
<weight Float> | |
<name String> | |
} | |
[Person_Constructor <this Person> <age Int> <weight Float> <name String> | |
(set this.age age) | |
(set this.weight weight) | |
(set this.name name) | |
] | |
# function implementation with assembly. | |
[add Int <a Int> <b Int> | |
/let | |
<cache Int> | |
/ | |
# compiler directive that compiles given string into assembler. | |
/asm "add void $a->value $b->value => $cache->value;"/ | |
# Jaeger is stack based functional language that operates on stack, | |
# every object is pointer-to-data type, so atomic operations | |
# performed on stack must push it's result on stack. | |
/asm "push $cache;"/ | |
# when we dealing with return value from assembly, we have to tell compiler | |
# that function already returned value, so it will not kill us with rage. | |
/return placement/ | |
] | |
[countdown | |
(roar "5") | |
# yield directive tells compiler to pass control to caller | |
# until condition is satisfied. | |
/yield (waitForMilliseconds 1000)/ | |
(roar "4") | |
/yield (waitForMilliseconds 1000)/ | |
(roar "3") | |
/yield (waitForMilliseconds 1000)/ | |
(roar "2") | |
/yield (waitForMilliseconds 1000)/ | |
(roar "1") | |
/yield (waitForMilliseconds 1000)/ | |
(roar "Fire!") | |
] | |
# main function. | |
[main Int | |
# directive that creates function local storage. | |
/let | |
<a Person> | |
<b Person> | |
/ | |
(set a (new Person 20 60.75 "John")) | |
(set b (new Person 18 51.5 "Emilly")) | |
# `&` character means that we will call again the same function | |
# but with new arguments provided after `&` character - this can help | |
# to write less code for repetitive callings. | |
(roar "Sum of " & a.name & " and " & b.name & " ages is: " & (add a.age b.age)) | |
# call function asynchronously. | |
/async (countdown)/ | |
# function returns value from the last function expression. | |
0 | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment