Skip to content

Commit 6cb085c

Browse files
committed
Added whiley programming language
1 parent 30246e6 commit 6cb085c

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed

whiley/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
.wyil

whiley/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<img src="https://raw.githubusercontent.com/rtoal/ple/main/docs/resources/whiley-logo-64.png">
2+
3+
# Whiley Explorations
4+
5+
You have a couple options to explore Whiley:
6+
7+
<details><summary><b>Install the Whiley Compiler</b></summary>
8+
9+
To install Whiley, you will need to already have installed Java before installing. In addition, you may also need to have Cargo (from Rust) installed as well to install Whiley.
10+
11+
After getting both of these dependencies stated, type in the following command:
12+
13+
```
14+
cargo install whiley
15+
```
16+
17+
Afterwards, you can start running scripts. Though a bit cumbersome, to run an example code, copy the code from the scripts folder and paste it into `main.whiley`. Another way is to duplicate one of the files from scripts folder to the src folder and then rename it to `main.whiley` (if you run into issues, delete the existing file first). Then finally, at the root folder (`ple/whiley`), perform the following commands:
18+
19+
```
20+
wy build
21+
wy run
22+
```
23+
24+
</details>
25+
26+
## About Whiley
27+
28+
TODO
29+
30+
## Whiley Resources
31+
32+
Continue your study of Whiley via:
33+
34+
- [Whiley Website](https://whiley.org/)

whiley/scripts/clockhands.whiley

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import std::io
2+
import string from std::ascii
3+
4+
function build_clock(int h, int m, int s) -> string:
5+
return ['0' + (h / 10), '0' + (h % 10), ':',
6+
'0' + (m / 10), '0' + (m % 10), ':',
7+
'0' + (s / 10), '0' + (s % 10)]
8+
9+
public export method main():
10+
int i = 0
11+
while i < 11:
12+
int t = ((43200 * i) + 21600) / 11
13+
int h = t / 3600
14+
int m = (t / 60) % 60
15+
int s = t % 60
16+
if h == 0:
17+
h = 12
18+
io::println(build_clock(h, m, s))
19+
i = i + 1

whiley/scripts/hello.whiley

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import std::io
2+
3+
public export method main():
4+
io::println("Hello, World!")

whiley/scripts/triple.whiley

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import std::io
2+
import std::ascii
3+
import std::array
4+
import string from std::ascii
5+
6+
public export method main():
7+
int c = 1
8+
while c <= 40:
9+
int b = 1
10+
while b <= c:
11+
int a = 1
12+
while a <= b:
13+
if ((a * a) + (b * b)) == (c * c):
14+
string triple = array::append(ascii::to_string(a), ", ")
15+
triple = array::append(triple, ascii::to_string(b))
16+
triple = array::append(triple, ", ")
17+
triple = array::append(triple, ascii::to_string(c))
18+
io::println(triple)
19+
a = a + 1
20+
b = b + 1
21+
c = c + 1

whiley/src/main.whiley

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Place your example code here!!

whiley/test.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Assert-MatchTests {
2+
param (
3+
[Parameter(Mandatory = $true, ValueFromPipeline)] $TestResult
4+
)
5+
6+
if ($TestResult) {
7+
Write-Error "Output does not match expected results."
8+
}
9+
}
10+
11+
# To test for individual files, we need to copy and rename them as main.whiley
12+
13+
# File from the script folder copies to the src folder as the main file.
14+
$scripts = "$PSScriptRoot\scripts"
15+
$main = "$PSScriptRoot\src\main.whiley"
16+
17+
# wy command must be used inside the whiley folder.
18+
$currentLocation = $pwd
19+
Set-Location "$PSScriptRoot"
20+
21+
$Error.clear()
22+
Copy-Item "$scripts\clockhands.whiley" -Destination "$main" && wy build && wy run |
23+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
24+
Assert-MatchTests &&
25+
Copy-Item "$scripts\hello.whiley" -Destination "$main" && wy build && wy run &&
26+
Copy-Item "$scripts\triple.whiley" -Destination "$main" && wy build && wy run |
27+
Compare-Object (Get-Content "$PSScriptRoot\..\test\triple_expected") |
28+
Assert-MatchTests &&
29+
ForEach-Object 'foo';
30+
31+
if ($Error -or !$?) {
32+
"*** WHILEY TESTS FAILED ***"
33+
}
34+
else {
35+
"WHILEY TESTS PASSED"
36+
}
37+
38+
# Returns the powershell back to its location.
39+
Set-Location "$currentLocation"

whiley/wy.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name="main"
3+
authors=["Joe Bloggs"]
4+
version="0.1.0"
5+
6+
[build]
7+
platforms=["whiley"]
8+
9+
[dependencies]
10+
std="0.3.2"

0 commit comments

Comments
 (0)