Skip to content

Commit

Permalink
Merge pull request #1 from hrszpuk/dev
Browse files Browse the repository at this point in the history
Setting up project + basic scanning
  • Loading branch information
hrszpuk authored Dec 30, 2024
2 parents 78a4a4a + 2a5520b commit 5639c7c
Show file tree
Hide file tree
Showing 65 changed files with 1,211 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Mkfile.old
dkms.conf

# Local files/paths
build/
build/
.vscode/
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
cmake_minimum_required(VERSION 3.15)
project(MyLanguage C CXX)
project(Dragon C CXX)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 23)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(include)

set(SOURCES
src/lexer.c
src/token.c
src/parser.c
src/vm.c
src/codegen.c
src/semantics.c
src/lexer.cpp
src/token.cpp
src/parser.cpp
src/vm.cpp
src/codegen.cpp
src/semantics.cpp
)

add_executable(pebble src/main.c ${SOURCES})
add_executable(dragon src/main.cpp ${SOURCES})

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/heads/main.zip
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(googletest)

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Pebble
Yet another simple, easy to use, high-level scripting language.
# Dragon
A high-level multi-paradigm programming language.

```
func add_one(x int) int {
return x + 1
}
var number = 10
let number = 10
println(add_one(number))
```

### Key features
- Simple, easy to understand
- Easy to install and run on all major platforms (Windows, MacOS, Linux)
- Procedural, Object Oriented, and Functional language features
- Portable and optimised using LLVM 20
- Batteries included standard library
- Project and package management built-in
7 changes: 7 additions & 0 deletions examples/Common Programming Concepts/Comments.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This is a single line comment
/*
This is a multi-line comment
*/

// Comments can go in between shit:
let /* look! */ x = /* neat! */ 10
22 changes: 22 additions & 0 deletions examples/Common Programming Concepts/Control Flow.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// If statements
if false {
// Won't execute
} else if true {
// Will execute
} else {
// Will only execute if all previous ifs are false
}

// Match statement
let x = 10

match x {
0: println("Zero")
1..5: println("NUMBER")
5: println("5")
>5: println("More than 5")
_: println("Negative!")
}

// Ternary operator
let y = true ? 10 : 20
10 changes: 10 additions & 0 deletions examples/Common Programming Concepts/Data Types.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
int <-- Platform dependent, I'd recommend :)
uint <-- Platform dependent, I'd recommend :)
i8 i16 i32 i64 i128 <-- Signed integer types
u8 u16 u32 u64 u128 <-- Unsigned integer types
float <-- Platform dependent, I'd recommend :)
f32 f64 <-- Floating Point Types
string <-- List of characters
bool <-- True or False
*/
15 changes: 15 additions & 0 deletions examples/Common Programming Concepts/Functions.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Functions are pretty normal
fn add(a int, b int) -> int { return a + b }
add(10, 20)

fn hello_world() {
println("Hello, World!")
}

// Lambda functions
let add_one = (a int) -> int => a + 1
add_one(10, add_one(10))

// Lambda type
let add_two (int) -> int
add_two = (a) => a + 2
13 changes: 13 additions & 0 deletions examples/Common Programming Concepts/Operators.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Here are all the operators i guess

=
+ - / * %
&& != ! || ==
+= -= *= /= %
..
& | ^
> >= <= <=
>> <<
~
? :
*/
21 changes: 21 additions & 0 deletions examples/Common Programming Concepts/References and Copying.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// By default everything is passed around the program through copying.
let x = 10
let y = x // The value of x is copied to y.

// This is true even for more complex types.

// However, we can reference any type of information, which allows it to be passed around the program
// without having to copy each time, which can get expensive.

let a = 10
let b = &a

println(b) // 10

// References are immutable by default, you can use &m for a mutable reference
let c = &m a
c += 1 // a and b are both now 11

// References to constant cannot be modified.
const pi = 3.14
let pi_ref = &m pi // error
27 changes: 27 additions & 0 deletions examples/Common Programming Concepts/Variables.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

/* Variable Declaration

Variables:
`let <identifier <type>`
`let <identifier> <type> = <expr>`
`let <identifier> = <expr>` <-- type inference

Constants:
`const <identifier> <type>`
`const <identifier> <type> = <expr>`
`const <identifier> = <expr>` <-- type inference
*/

const username string
const age int = 100 + 100
const id = 1034

let inventory [string]
let count int = 0
let greeting = "!dlrow olleH"

// Variable Assignment
username = "alice" // This is allowed only once as the constant has not be assigned anything prior
inventory = ["Sword", "Shield", "Potion"]
count += 1
greeting = greeting.reverse()
14 changes: 14 additions & 0 deletions examples/Error Handling/Option and Result types.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

// The prelude includes Option and Result types

func add<T>(a T, b T) -> Result<T>

// Pattern matching the result
let added = match add(10, 10) {
Result::success(s): s
Result::error(s): {
println(s)
exit(1)
}
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/Generics/Generics for functions.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

fn add<T>(a T, b T) -> T { return a + b }

// We can ensure a trait is implemented for a given type
fn sub<T: Numeric>(a T, b T) -> T { return a - b }

// We can have multiple generic types
fn mul<T: Numeric, K: Numeric, Y: Numeric>(a T, b K) -> Y { return a + b }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dragon Examples
This folder contains numerous examples for the Dragon programming language.

## Example Collections
- [Common Programming Concepts](./Common%20Programming%20Concepts/)
- [Strings, Lists, Tuples, and Sets](./Strings,%20Lists,%20Tuples,%20and%20Sets/)
- [User-defined Types](./User-defined%20Types/)
- [Generics](./Generics/)
- [Modules and Packages](./Modules%20and%20Packages/)
- [Error Handling](./Error%20Handling/)
- [Object Oriented Programming Features](./Object%20Oriented%20Programming%20Features/)
- [Functional Programming Features](./Functional%20Programming%20Features/)
- [Standard Library](./Standard%20Library/) [Coming soon!]

There's also [demo.drg](./demo.drg) which is a showcase of all the features.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions examples/Strings, Lists, Tuples, and Sets/Lists.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

// Lists
// Type signature: [<type>]
let names [string]
names = ["Jerry", "Barry", "Caesar"]

// List methods
names.clear()
names.count()
names.find()
names.pop()
names.push()
names.extend()
names.insert()
names.reverse()
names.remove()

// Looping
for name in names {}
for name, index in names {}

// Indexing
names[0]

// Slicing [start:stop:step]
names[0:2:-1] = ["Barry", "Jerry"]
17 changes: 17 additions & 0 deletions examples/Strings, Lists, Tuples, and Sets/Sets.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


let names {string}
names = {"Jerry", "Barry", "Caesar"}

// List methods
names.clear()
names.pop()
names.push()

// Looping
for name in names {}
for name, index in names {}

// Indexing
names[0] // "Jerry"

33 changes: 33 additions & 0 deletions examples/Strings, Lists, Tuples, and Sets/Strings.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

// Strings
let msg string
msg = "Hello, World!"

// String methods (prelude)
msg.reverse()
msg.replace("!", "?")
msg.lowercase()
msg.uppercase()
msg.is_lowercase()
msg.is_uppercase()
msg.count()
msg.trim()
msg.find()
msg.split()

// String methods can also be applied to string literals
"Test".reverse().find("T") // return 3

// Looping over a string
for c in "hello" {}
for c, index in "hello" {}

// Indexing a string
"hello"[2] // "l"

// Concatenation
"hello" + " world"
"hello" += " world"

// Slicing [start:stop:step]
"hello world"[5:11] // "world"
16 changes: 16 additions & 0 deletions examples/Strings, Lists, Tuples, and Sets/Tuples.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

let position2d (x int, y int)
position2d = (10, 10)

position2d[0]
position2d[1]

position2d.x
position2d.y

position2d.count()
position2d.find()

for p in position2d {}
for p, index in position2d {}

15 changes: 15 additions & 0 deletions examples/User-defined Types/Enumerations.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

type Colour enum {
Red,
Green,
Blue
}

let blue = Colour.Blue

type Direction enum {
Up = "^",
Right = "->",
Down = "v",
Left = "<-"
}
18 changes: 18 additions & 0 deletions examples/User-defined Types/Structures.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

type User struct {
name string,
pass string,
favourite_colour Colour
}

let barry = User{
"Barry", "123", Colour.Blue,
}

println(barry.name)

const jerry = User{
name: "Jerry",
pass: "321",
favourite_colour: .Blue
}
17 changes: 17 additions & 0 deletions examples/User-defined Types/Trait.drg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

trait Animal {
fn new(name string) -> self
fn name(&self) -> string
}

type Sheep struct { name string }

impl Animal for Sheep {
fn new(name string) -> Sheep {
return Sheep { name }
}

fn name(&self) -> string {
return self.name
}
}
Loading

0 comments on commit 5639c7c

Please sign in to comment.