~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
de2c04cb
—
pyrossh 1 year ago
add methods
- example/fn.palm +1 -23
- example/std/math.mi +15 -10
- example/std/str.mi +91 -0
example/fn.palm
CHANGED
|
@@ -14,12 +14,9 @@ module lambda
|
|
|
14
14
|
|
|
15
15
|
alias MapCallback = fn(v: a): v
|
|
16
16
|
|
|
17
|
-
trait Comparable<a>
|
|
17
|
+
trait Comparable<a> =
|
|
18
18
|
fn compare(left: a, right: a): bool
|
|
19
19
|
|
|
20
|
-
trait Stringable:
|
|
21
|
-
fn to_str() str
|
|
22
|
-
|
|
23
20
|
enum Temperature(celsius(float) | fahrenheit(float)) =
|
|
24
21
|
fn str(self) =
|
|
25
22
|
match self
|
|
@@ -28,25 +25,6 @@ enum Temperature(celsius(float) | fahrenheit(float)) =
|
|
|
28
25
|
Temperature::fahrenheit(t) && t > 86 -> "${t}F is above 86 fahrenheit"
|
|
29
26
|
Temperature::fahrenheit(t) -> "${t}F is below 86 fahrenheit"
|
|
30
27
|
|
|
31
|
-
struct str(data: Pointer<u16>, length: int)
|
|
32
|
-
// where is Comparable, Stringable
|
|
33
|
-
fn reverse() =
|
|
34
|
-
let start = 0
|
|
35
|
-
let end = this.length - 1
|
|
36
|
-
let result = []
|
|
37
|
-
while (start < end) ||
|
|
38
|
-
const temp = this[start]
|
|
39
|
-
this[start] = this[end]
|
|
40
|
-
this[end] = temp
|
|
41
|
-
end = end - 1
|
|
42
|
-
start = start + 1
|
|
43
|
-
|
|
44
|
-
fn parse_int(): int! =
|
|
45
|
-
return 0
|
|
46
|
-
|
|
47
|
-
fn parse_float(): float! =
|
|
48
|
-
return 0.0
|
|
49
|
-
|
|
50
28
|
struct Cat(name: str, age: int) =
|
|
51
29
|
fn fullname() =
|
|
52
30
|
name + age.str()
|
example/std/math.mi
CHANGED
|
@@ -17,9 +17,15 @@ NEGATIVE_INFINITY
|
|
|
17
17
|
POSITIVE_INFINITY
|
|
18
18
|
|
|
19
19
|
// Returns the absolute value of a number
|
|
20
|
-
|
|
20
|
+
fn abs(v: float): float = a < 0 ? -a : a
|
|
21
|
+
|
|
22
|
+
fn acos(v: float) =
|
|
23
|
+
if v < 0.1
|
|
24
|
+
asin(v)
|
|
25
|
+
else
|
|
26
|
+
asin(-1v)
|
|
27
|
+
|
|
21
28
|
|
|
22
|
-
acos: fn(v: float) = 0f
|
|
23
29
|
fn acosh(v: float) = 0f
|
|
24
30
|
fn asin(v: float) = 0f
|
|
25
31
|
fn asinh(v: float) = 0f
|
|
@@ -35,13 +41,11 @@ fn exp(v: float) = 0f
|
|
|
35
41
|
fn to_int(): int = 0
|
|
36
42
|
fn to_str(): str = ""
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
fn random(): float =
|
|
39
|
-
|
|
45
|
+
pass
|
|
40
46
|
|
|
41
|
-
fn parse(s: str) =
|
|
42
|
-
0.0f
|
|
43
|
-
|
|
44
|
-
fn is_int(): bool =
|
|
47
|
+
fn is_int(): bool =
|
|
48
|
+
pass
|
|
45
49
|
|
|
46
50
|
|
|
47
51
|
// Check whether this number is finite, ie not +/-infinity and not NaN.
|
|
@@ -50,7 +54,7 @@ fn is_finite(): bool = true
|
|
|
50
54
|
// (bits() and 0x7FF0_0000_0000_0000) != 0x7FF0_0000_0000_0000
|
|
51
55
|
|
|
52
56
|
// Check whether this number is +/-infinity
|
|
53
|
-
|
|
57
|
+
is_infinite: Bool =>
|
|
54
58
|
// True if exponent is all 1s and mantissa is 0
|
|
55
59
|
((bits() and 0x7FF0_0000_0000_0000) == 0x7FF0_0000_0000_0000) and // exp
|
|
56
60
|
((bits() and 0x000F_FFFF_FFFF_FFFF) == 0) // mantissa
|
|
@@ -92,4 +96,5 @@ fun sqrt(): F64 =>
|
|
|
92
96
|
_nan()
|
|
93
97
|
else
|
|
94
98
|
@"llvm.sqrt.f64"(this)
|
|
95
|
-
end
|
|
99
|
+
end
|
|
100
|
+
|
example/std/str.mi
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module std
|
|
2
|
+
|
|
3
|
+
trait Stringable =
|
|
4
|
+
fn to_str(): str
|
|
5
|
+
|
|
6
|
+
struct str(data: Pointer<u16>, length: int) is Comparable, Stringable =
|
|
7
|
+
fn get(i: int) = data[i]
|
|
8
|
+
|
|
9
|
+
fn concat(other: str): str =
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
fn starts_with(search: str): bool =
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
fn ends_with(search: str): bool =
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
fn contains(search: str): bool =
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
fn index_of(sub: str): int =
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
fn match(pattern: Regex): []str =
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
fn match_all(pattern: Regex): []str =
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
fn pad_start(sub: str, count: int): str =
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
fn pad_end(sub: str, count: int): str =
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
fn repeat(count: int): str =
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
fn replace(pattern: Regex, sub: str): str =
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
fn replace_all(pattern: Regex, sub: str): str =
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
fn search(pattern: Regex): str =
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
fn slice(start: int, end: int): str =
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
fn split(separator: str, limit: int): []str =
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
fn sub(start: int, end: int): str =
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
fn to_lower(): str =
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
fn to_upper(): str =
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
fn to_str(self): str =
|
|
64
|
+
self
|
|
65
|
+
|
|
66
|
+
fn trim(): str =
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
fn trim_start(): str =
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
fn trim_end(): str =
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
fn reverse(): str =
|
|
76
|
+
start := 0
|
|
77
|
+
end := length - 1
|
|
78
|
+
result := []
|
|
79
|
+
while start < end
|
|
80
|
+
const temp = data[start]
|
|
81
|
+
result[start] = data[end]
|
|
82
|
+
result[end] = temp
|
|
83
|
+
end = end - 1
|
|
84
|
+
start = start + 1
|
|
85
|
+
result
|
|
86
|
+
|
|
87
|
+
fn parse_int(): int! =
|
|
88
|
+
0
|
|
89
|
+
|
|
90
|
+
fn parse_float(): float! =
|
|
91
|
+
0.0
|