~repos /plum

#treesitter#compiler#wasm

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 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
- type List =
53
+ enum List =
63
54
  | Empty
64
55
  | Node(a)
65
56
 
libs/std/float.plum CHANGED
@@ -1,4 +1,4 @@
1
- module std/float
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/http
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/int
1
+ module std
2
2
 
3
- type Int : Comparable, ToStr =
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 = # Return random number
9
+ ::random() -> Float =
9
10
  todo
10
11
 
12
+ `Get int from Str
11
- ::parseInt() -> Result(Int, Err) =
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 then
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
- class List
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
- mapOf(kvs: ...Pair) -> Map =
13
+ init(kvs: ...Pair) =
17
- Map(a, b)().add(kvs)
14
+ Map(a, b)().add(kvs)
18
-
15
+
19
- # adds the specified elements to the start of the list
16
+ `adds the specified elements to the start of the list
20
- Map\add(kvs: ...Pair) =
17
+ add(kvs: ...Pair) =
21
- items.add(kvs)
18
+ items.add(kvs)
22
-
19
+
23
- # Get a value from the Map using key k
20
+ `Get a value from the Map using key k
24
- Map\get(k: a) -> b | Nil =
21
+ get(k: a) -> Option(b) =
25
- for k, v in items do
22
+ for k, v in items do
26
- if k == k
23
+ if k == k
27
- return v
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
- found
25
+ None
38
-
26
+
39
- # Put a value into the Map
27
+ `Put a value into the Map
40
- Map\set(k: a, v: b) =
28
+ set(k: a, v: b) =
41
- items.add(pair(k, v))
29
+ items.add(pair(k, v))
42
-
30
+
43
- # `put a value into the Map if its not already present
31
+ `put a value into the Map if its not already present
44
- Map\putIfAbsent(k K, v V) =
32
+ putIfAbsent(k K, v V) =
45
- todo
33
+ todo
46
-
34
+
47
- Map\map(cb: (Pair(a, b)) -> Pair(c, d)) -> Map(c, d) =
35
+ map(cb: (Pair(a, b)) -> Pair(c, d)) -> Map(c, d) =
48
- items.map(cb)
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
- `ToStr defines any data that can be converted to a str
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
- # 👾 Kestrel Programming Language
1
+ # 👾 Plum Programming Language
2
2
 
3
- - A statically typed, imperative programming language inspired by rust, kotlin
3
+ - A statically typed, imperative programming language with ADT's (Algebraic Data Types) inspired by rust, gleam
4
- - The compiler users the tree-sitter parser so has out of the box syntax highlighting support for helix and zed editor
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
- - Plans to be compiled to WASM
13
+ clang >= 16.0.0
14
+ ```
src/compiler.rs ADDED
File without changes