Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Update README and implementation some futures.
Browse files Browse the repository at this point in the history
  • Loading branch information
uanhi committed Apr 15, 2021
1 parent 28afcda commit 918ce53
Show file tree
Hide file tree
Showing 15 changed files with 466 additions and 91 deletions.
32 changes: 0 additions & 32 deletions README

This file was deleted.

65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# The Drift Programming Language

<p align="center" style="font-weight: bold;">Refined, minimalist, modern, beautiful</p>

- Fourteen keywords
- Twelve object types
- Bytecode virtual machine

Basic grammatical format of drift, please check the instance code `awesome.ft`

## Build

- switch CC field in Makefile and specify your g++ compiler path
- my gcc version is 10.2.0

```
make
make install
```

### To install:

export PATH=$PWD:$PATH

### To run:

drift # REPL MODE
drift <ft file> # FILE MODE

drift -d # REPL AND DEBUG MODE
drift <ft file> -d # FILE AND DEBUG MODE

drift -b # REPL AND DIS BYTECODE
drift <ft file> -b # FILE AND DIS BYTECODE

### To clean:

make clean

## Collaborative development

- Lack of FFI support
- Syntax highlighting support for Virtual Studio Code, `tool` directory
- Standard library and bug testing, etc

## More

For documentation and project architecuture,
visit the official website https://drift-lang.fun/

**It's a toy language, Have Fun!!**

## License
```
Copyright (c) 2021 bingxio(丙杺,黄菁). All rights reserved.
GNU General Public License, more to see file: LICENSE
https://www.gnu.org/licenses
THE DRIFT PROGRAMMING LANGUAGE
https://github.com/bingxio/drift
https://www.drift-lang.fun/
```
74 changes: 46 additions & 28 deletions test/awesome.ft → awesome.ft
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
9.enum
10.function
11.whole
12.module
*/

/*
Expand Down Expand Up @@ -151,26 +152,28 @@ end
def (x: |int, int| -> int, a + b: int) sum -> int
ret x(a, b) + x(a, b)
end
/*

def () set -> |int|
ret def (x: int)
ret x * 2
ret def (x: int) _ /* ANONYMOUSE */
puts(x * 2)
end
end
*/

set()(8)

def (x: int) bar -> |int, int| -> []int
putl("x = ", x)

ret def (a + b: int) -> []int
ret [
a,
b,
a + b,
a - b,
a * b,
a / b
]
end
putl("x = ", x)

ret def (a + b: int) -> []int /* ANONYMOUSE */
ret [
a,
b,
a + b,
a - b,
a * b,
a / b
]
end
end

put(
Expand Down Expand Up @@ -202,25 +205,40 @@ def Foo
end
end

def Go
def () *test
putl(new Foo.max(34, 12), new Foo.x, new Foo.y)

def Kop
def () *more
end

def Bar <- Foo + Go
def () test
putl("TEST!!")
end
def Oop <- Foo + Kop /* INHERIT */
def () more end

def () bar
test()
def () bar
putl(max(99, 98)) /* CALL INHERIT */
end

def (x: bool) what -> bool
ret !x
ret T
end
end

def f: Foo = new Foo{x: 43}
putl(f.x, f.y, f.max(2, 4))
putl(new Oop.bar())

/*
Others:
*/

def x: int = 30
def y: []int = [1, 2, 3]
def z: [3]float

putl("x = $x y = $y z = $z")

aop ->
putl("x: $x ") /* STRING TEMPLATE */
out x == 20
x -= 1
end

def b: Bar = new Bar
putl() // END
15 changes: 15 additions & 0 deletions src/ffi.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) 2021 bingxio(丙杺,黄菁). All rights reserved.
//

// GNU General Public License, more to see file: LICENSE
// https://www.gnu.org/licenses

// THE DRIFT PROGRAMMING LANGUAGE
//
// https://github.com/bingxio/drift
//
// https://www.drift-lang.fun/
//

#include "ffi.h"
18 changes: 18 additions & 0 deletions src/ffi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright (c) 2021 bingxio(丙杺,黄菁). All rights reserved.
//

// GNU General Public License, more to see file: LICENSE
// https://www.gnu.org/licenses

// THE DRIFT PROGRAMMING LANGUAGE
//
// https://github.com/bingxio/drift
//
// https://www.drift-lang.fun/
//

#ifndef DRIFT_FFI_H
#define DRIFT_FFI_H

#endif
4 changes: 4 additions & 0 deletions src/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ void Lexer::lexIdent() {
tok.literal = literal.str();
tok.line = this->line;

if (tok.kind == token::IDENT && tok.literal == "_") {
tok.kind = token::UNDERLINE; // single symbol
}

this->tokens.push_back(tok);
}

Expand Down
23 changes: 13 additions & 10 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,18 @@ ast::Stmt *Parser::stmt() {
}
}

// anonymouse function
if (look(token::R_ARROW) || look(token::UNDERLINE)) {
return new ast::FuncStmt(
funcArgs, // argument
token::Token{.kind = token::EFF, .literal = "anonymouse"}, // name
previous().kind == token::R_ARROW ? this->type()
: nullptr, // return
this->block(token::END) // block
);
}
// function
if (look(token::IDENT)) {
else if (look(token::IDENT)) {
name = previous();
}
// interface
Expand All @@ -475,12 +485,6 @@ ast::Stmt *Parser::stmt() {
// current parsing interface statement
interfaceStmt = true;
}
// anonymouse function
else if (look(token::R_ARROW)) {
return new ast::FuncStmt(
funcArgs, token::Token{.kind = token::EFF, .literal = "anonymouse"},
this->type(), this->block(token::END));
}
// error
else {
error(exp::UNEXPECTED,
Expand Down Expand Up @@ -772,9 +776,8 @@ Type *Parser::type(bool previous) {
continue;
}
}
if (look(token::R_ARROW)) {
ret = this->type();
}

if (look(token::R_ARROW)) ret = this->type(); // return
return new Func(arguments, ret);
}
error(exp::INVALID_SYNTAX, "invalid type");
Expand Down
Loading

0 comments on commit 918ce53

Please sign in to comment.