Skip to content

Commit

Permalink
Merge pull request #56 from Robotnik08/development
Browse files Browse the repository at this point in the history
Classes
  • Loading branch information
Robotnik08 authored Nov 14, 2024
2 parents 874cf54 + ca43a5b commit cbe3529
Show file tree
Hide file tree
Showing 18 changed files with 379 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="assets/dosato_logo_wide.png">
</p>

# CDosato version 0.5
# CDosato version 0.5.1

CDosato is the official implementation of the DOSATO programming language.<br>

Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ All versions in the release section are supported

| Version | Supported |
| ------- | ------------------ |
| 0.5 | :white_check_mark: |
| < 0.5 | :x: |
| 0.5.1 | :white_check_mark: |
| < 0.5.1 | :x: |

## Reporting a Vulnerability

Expand Down
32 changes: 21 additions & 11 deletions demo/oop.to
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
define object playerMaker (string name, string position, int number) {
const player = {
name, position, number
}
class Person (name, age) {
set self->name = name
set self->age = age

set player->greet = void () => {
do sayln(`Hello, I'm {player->name} and I play as {player->position} ({player->number})`)
implement greet () {
do sayln(`Hello, my name is {self->name}. I am {self->age} years old`)
}
}

class Student (name, age, grade) {
set self += Person(name, age)
set self->grade = grade

return player
implement sayGrade () {
do sayln(`My grade is {self->grade}`)
}
}

make object player1 = playerMaker("Bib", "Attacker", 10)
make object player2 = playerMaker("Bob", "Defender", 5)
make student1 = Student("Bob", 20, "A")

do student1->greet()
do student1->sayGrade()

make student2 = Student("Bib", 21, "B")

do player1->greet()
do player2->greet()
do student2->greet()
do student2->sayGrade()
1 change: 1 addition & 0 deletions dosato_libraries/dosato.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef enum {
E_EXPECTED_NUMBER,
E_CANNOT_ASSIGN_TO_CONSTANT,
E_INVALID_AMOUNT_SET_EXPRESSION,
E_INVALID_IDENTIFIER,

// standard library errors
E_FILE_NOT_FOUND,
Expand Down
2 changes: 1 addition & 1 deletion include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <unistd.h>
#endif

#define DOSATO_VERSION "0.5"
#define DOSATO_VERSION "0.5.1"
#ifndef DOSATO_DATE
#define DOSATO_DATE "Unknown date"
#endif
Expand Down
1 change: 1 addition & 0 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct {
size_t locals_count;
size_t locals_capacity;
DataType return_type;
bool is_class;
} ScopeData;

void compile(VirtualMachine* vm, AST* ast);
Expand Down
1 change: 1 addition & 0 deletions include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef enum {
E_EXPECTED_NUMBER,
E_CANNOT_ASSIGN_TO_CONSTANT,
E_INVALID_AMOUNT_SET_EXPRESSION,
E_INVALID_IDENTIFIER,

// standard library errors
E_FILE_NOT_FOUND,
Expand Down
4 changes: 4 additions & 0 deletions include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ typedef enum {
NODE_MASTER_CONTINUE,
NODE_MASTER_SWITCH,
NODE_MASTER_CONST,
NODE_MASTER_CLASS,
NODE_MASTER_METHOD,

NODE_MASTER_DO_BODY,
NODE_MASTER_MAKE_BODY,
Expand All @@ -30,6 +32,8 @@ typedef enum {
NODE_MASTER_CONTINUE_BODY,
NODE_MASTER_SWITCH_BODY,
NODE_MASTER_CONST_BODY,
NODE_MASTER_CLASS_BODY,
NODE_MASTER_METHOD_BODY,


NODE_WHEN_BODY,
Expand Down
4 changes: 3 additions & 1 deletion include/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "common.h"

#define MASTER_KEYWORDS {"DO", "MAKE", "SET", "DEFINE", "INCLUDE", "IMPORT", "RETURN", "BREAK", "CONTINUE", "SWITCH", "CONST"}
#define MASTER_KEYWORDS {"DO", "MAKE", "SET", "DEFINE", "INCLUDE", "IMPORT", "RETURN", "BREAK", "CONTINUE", "SWITCH", "CONST", "CLASS", "IMPLEMENT"}
#define EXTENSION_KEYWORDS {"WHEN", "WHILE", "ELSE", "CATCH", "THEN", "FOR", "IF"}
#define VAR_TYPES {"INT", "BOOL", "STRING", "FLOAT", "DOUBLE", "CHAR", "SHORT", "LONG", "BYTE", "VOID", "ARRAY", "UINT", "USHORT", "ULONG", "UBYTE", "OBJECT", "VAR", "FUNCTION"}
#define BOOLEAN_KEYWORDS {"FALSE", "TRUE"}
Expand Down Expand Up @@ -132,6 +132,8 @@ typedef enum {
MASTER_CONTINUE,
MASTER_SWITCH,
MASTER_CONST,
MASTER_CLASS,
MASTER_METHOD,

M_NULL = -1
} MasterKeywordType;
Expand Down
2 changes: 2 additions & 0 deletions include/virtual-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef struct {
size_t* captured_indices;
size_t captured_count;

bool is_class;

bool is_compiled; // compiled or imported by external library
void* func_ptr;
} Function;
Expand Down
Loading

0 comments on commit cbe3529

Please sign in to comment.