~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
fa31ba40
—
pyrossh 1 year ago
some changes
- libs/std/bool.plum +1 -10
- libs/std/float.plum +1 -1
- libs/std/http.plum +1 -1
- libs/std/int.plum +7 -5
- libs/std/list.plum +1 -1
- libs/std/map.plum +30 -42
- libs/std/option.plum +12 -0
- libs/std/result.plum +6 -0
- libs/std/str.plum +1 -1
- libs/std/{time.mi → time.plum} +0 -0
- libs/std/{uuid.mi → uuid.plum} +0 -0
- readme.md +13 -4
- src/compiler.rs +0 -0
libs/std/bool.plum
CHANGED
|
@@ -36,15 +36,6 @@ enum Bool =
|
|
|
36
36
|
else
|
|
37
37
|
Err("could not parse bool from '{s}'")
|
|
38
38
|
|
|
39
|
-
type Result =
|
|
40
|
-
| Ok(a)
|
|
41
|
-
| Err(b)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type Option =
|
|
45
|
-
| Some(a)
|
|
46
|
-
| None
|
|
47
|
-
|
|
48
39
|
readFile() -> Result(String, Err) =
|
|
49
40
|
return Err
|
|
50
41
|
|
|
@@ -59,7 +50,7 @@ match readFile()
|
|
|
59
50
|
Err(e) =>
|
|
60
51
|
printErr(e)
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
enum List =
|
|
63
54
|
| Empty
|
|
64
55
|
| Node(a)
|
|
65
56
|
|
libs/std/float.plum
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module std
|
|
1
|
+
module std
|
|
2
2
|
|
|
3
3
|
type Float =
|
|
4
4
|
E = 2.718f # Euler's number, the base of natural logarithms, e, https://oeis.org/A001113
|
libs/std/http.plum
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module std
|
|
1
|
+
module std
|
|
2
2
|
|
|
3
3
|
import std/path
|
|
4
4
|
import std/os
|
libs/std/int.plum
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
module std
|
|
1
|
+
module std
|
|
2
2
|
|
|
3
|
-
type Int
|
|
3
|
+
type Int is Comparable, Stringable =
|
|
4
4
|
MIN_VALUE = -0x8000_0000_0000_0000 # Lowest value of Int
|
|
5
5
|
MAX_VALUE = 0x7FFF_FFFF_FFFF_FFFF # Highest value of Int
|
|
6
6
|
LARGE = 1 << 28 # 2**28
|
|
7
7
|
|
|
8
|
+
`Return random number
|
|
8
|
-
::random() -> Float =
|
|
9
|
+
::random() -> Float =
|
|
9
10
|
todo
|
|
10
11
|
|
|
12
|
+
`Get int from Str
|
|
11
|
-
::
|
|
13
|
+
::fromStr() -> Result(Int, Err) =
|
|
12
14
|
0
|
|
13
15
|
|
|
14
16
|
# returns the absolute value of the Int
|
|
@@ -46,7 +48,7 @@ type Int : Comparable, ToStr =
|
|
|
46
48
|
pow(y.toFloat())
|
|
47
49
|
|
|
48
50
|
sqrt() -> Float =
|
|
49
|
-
if this < 0.0
|
|
51
|
+
if this < 0.0
|
|
50
52
|
_nan()
|
|
51
53
|
else
|
|
52
54
|
LibM.sqrt(this)
|
libs/std/list.plum
CHANGED
|
@@ -8,7 +8,7 @@ type Node =
|
|
|
8
8
|
|
|
9
9
|
`A list is a data structure describing a contiguous section of an array stored separately from the slice variable itself.
|
|
10
10
|
`It contains the pointers to the start and end nodes (head, tail) and maintains the size as well
|
|
11
|
-
|
|
11
|
+
type List is Stringable =
|
|
12
12
|
head: Option[Node]
|
|
13
13
|
tail: Option[Node]
|
|
14
14
|
size: Int
|
libs/std/map.plum
CHANGED
|
@@ -1,48 +1,36 @@
|
|
|
1
1
|
module std
|
|
2
2
|
|
|
3
|
+
`A Pair can is a grouping of a key with a value
|
|
3
|
-
Pair(a, b) =
|
|
4
|
+
type Pair(a, b) =
|
|
4
5
|
key: a
|
|
5
6
|
val: b
|
|
6
|
-
)
|
|
7
7
|
|
|
8
|
-
```
|
|
9
|
-
A Map is a data structure describing a contiguous section of an array stored separately from the slice variable itself.
|
|
8
|
+
`A Map is a data structure describing a contiguous section of an array stored separately from the slice variable itself.
|
|
10
|
-
A Map is not an array. A slice describes a piece of an array.
|
|
9
|
+
`A Map is not an array. A slice describes a piece of an array.
|
|
11
|
-
```
|
|
12
|
-
Map(a, b) =
|
|
10
|
+
type Map(a, b) =
|
|
13
11
|
items: List(Pair(a, b))
|
|
14
|
-
|
|
12
|
+
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
init(kvs: ...Pair) =
|
|
17
|
-
|
|
14
|
+
Map(a, b)().add(kvs)
|
|
18
|
-
|
|
15
|
+
|
|
19
|
-
|
|
16
|
+
`adds the specified elements to the start of the list
|
|
20
|
-
|
|
17
|
+
add(kvs: ...Pair) =
|
|
21
|
-
|
|
18
|
+
items.add(kvs)
|
|
22
|
-
|
|
19
|
+
|
|
23
|
-
|
|
20
|
+
`Get a value from the Map using key k
|
|
24
|
-
|
|
21
|
+
get(k: a) -> Option(b) =
|
|
25
|
-
|
|
22
|
+
for k, v in items do
|
|
26
|
-
|
|
23
|
+
if k == k
|
|
27
|
-
|
|
24
|
+
return Some(v)
|
|
28
|
-
Nil
|
|
29
|
-
|
|
30
|
-
# Get a value from the Map using key k
|
|
31
|
-
Map\get(k: a) -> b | Nil =
|
|
32
|
-
found : Option(b) = None
|
|
33
|
-
for k, v in items do
|
|
34
|
-
if k == k
|
|
35
|
-
found = v
|
|
36
|
-
break
|
|
37
|
-
|
|
25
|
+
None
|
|
38
|
-
|
|
26
|
+
|
|
39
|
-
|
|
27
|
+
`Put a value into the Map
|
|
40
|
-
|
|
28
|
+
set(k: a, v: b) =
|
|
41
|
-
|
|
29
|
+
items.add(pair(k, v))
|
|
42
|
-
|
|
30
|
+
|
|
43
|
-
|
|
31
|
+
`put a value into the Map if its not already present
|
|
44
|
-
|
|
32
|
+
putIfAbsent(k K, v V) =
|
|
45
|
-
|
|
33
|
+
todo
|
|
46
|
-
|
|
34
|
+
|
|
47
|
-
|
|
35
|
+
map(cb: (Pair(a, b)) -> Pair(c, d)) -> Map(c, d) =
|
|
48
|
-
|
|
36
|
+
items.map(cb)
|
libs/std/option.plum
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module std
|
|
2
|
+
|
|
3
|
+
import std.{
|
|
4
|
+
Int,
|
|
5
|
+
Str,
|
|
6
|
+
Result,
|
|
7
|
+
Option
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Option =
|
|
11
|
+
| Some(a)
|
|
12
|
+
| None
|
libs/std/result.plum
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
module std
|
|
2
|
+
|
|
3
|
+
type Result =
|
|
4
|
+
| Ok(a)
|
|
5
|
+
| Err(b)
|
|
6
|
+
|
libs/std/str.plum
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module std/str
|
|
2
2
|
|
|
3
|
-
`
|
|
3
|
+
`Any type that can be converted to a str needs to implement this trait
|
|
4
4
|
trait Stringable =
|
|
5
5
|
toStr() -> Str
|
|
6
6
|
|
libs/std/{time.mi → time.plum}
RENAMED
|
File without changes
|
libs/std/{uuid.mi → uuid.plum}
RENAMED
|
File without changes
|
readme.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
# 👾
|
|
1
|
+
# 👾 Plum Programming Language
|
|
2
2
|
|
|
3
|
-
- A statically typed, imperative programming language inspired by rust,
|
|
3
|
+
- A statically typed, imperative programming language with ADT's (Algebraic Data Types) inspired by rust, gleam
|
|
4
|
-
- The compiler
|
|
4
|
+
- The compiler is built upon the tree-sitter parser so has out of the box syntax highlighting support for helix and zed editor
|
|
5
|
+
- Plans to be compiled to amd64,arm64, and riscv64 using QBE maintaining C-ABI compatibility
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Requirements
|
|
9
|
+
```sh
|
|
10
|
+
node >= 23.1.0
|
|
11
|
+
npm >= 10.9.0
|
|
12
|
+
qbe >= 1.2
|
|
5
|
-
|
|
13
|
+
clang >= 16.0.0
|
|
14
|
+
```
|
src/compiler.rs
ADDED
|
File without changes
|