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

Commit

Permalink
Update standard module and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
uanhi committed Apr 18, 2021
1 parent 77bc914 commit ee3f2ae
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 22 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

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

<center><img src="./misc/DRIFT.svg"></center>
<p align="center"><img src="./misc/DRIFT.svg"/></p>

- Fourteen keywords
- Twelve object types
- Written in C++
- Minimalist grammar, 14 keywords, 40 bytecode
- Frame and Stack structure interpreter
- Bytecode virtual machine

For documentation and project architecuture,
visit the official website https://drift-lang.fun/
Basic grammatical format of drift, please check the instance code `awesome.ft`

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

## Build

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

```
make
Expand Down Expand Up @@ -45,13 +50,6 @@ make install
- 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.
Expand Down
2 changes: 1 addition & 1 deletion misc/DRIFT.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 17 additions & 4 deletions src/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,54 @@

#include <iostream>

// Type stack structure
template <class T> class Stack {
private:
int capacity = 4, count = 0;
int capacity = 4, count = 0; /* Capacity and count */

// Elements with generic T
T *elements;

public:
// First, alloc memory to default capacity 4
explicit Stack() { this->elements = new T[capacity]; }

// After program out to free elements
~Stack() { delete[] elements; }

// Push a element
void push(T t) {
if (count + 1 > capacity) {
this->capacity = capacity * 2;
this->elements = (T *)realloc(this->elements, sizeof(T) * capacity);
this->capacity = capacity * 2; /* Renew capacity */
this->elements =
(T *)realloc(this->elements, sizeof(T) * capacity); /* Realloc */
}
this->elements[count++] = t;
this->elements[count++] = t; /* Push */
}

// Return the element of position
T at(int pos) { return this->elements[pos]; }

// Pop element
T pop() { return this->elements[--count]; }

// Top element
T top() { return this->elements[count - 1]; }

// Return length of elements
int len() { return count; }

// Return is empty of elements
bool empty() { return count == 0; }

// Clear all
void clear() {
while (len()) {
this->pop();
}
}

// Stringer
std::string stringer() {
return "<Stack count = " + std::to_string(count) + ">";
}
Expand Down
9 changes: 8 additions & 1 deletion src/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,31 @@

#include "object.h"

// Symbol table structure
struct Table {
std::map<std::string, object::Object *> symbols;
std::map<std::string, object::Object *> symbols; /* Elements */

// Remove a name
void remove(std::string n) { symbols.erase(n); }

// Clear all elements
void clear() { symbols.clear(); }

// Return is empty of elements
bool empty() { return symbols.empty(); }

// Lookup a name
object::Object *lookUp(std::string n) {
for (auto i : symbols)
if (i.first == n)
return i.second;
return nullptr;
}

// To emit a name with its object
void emit(std::string n, object::Object *o) { symbols[n] = o; }

// Dissemble symbols in table
void dissemble() {
printf("SYMBOL: \n");
for (auto i : symbols) {
Expand Down
3 changes: 3 additions & 0 deletions std/fmt.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: fmt
*/
mod fmt
4 changes: 4 additions & 0 deletions std/fun.ft
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/*
* Standard module: fun
*/
mod fun

// Have fun
def Fun
// MY LOVE!!
def () show
Expand Down
3 changes: 3 additions & 0 deletions std/http.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: http
*/
mod http
3 changes: 3 additions & 0 deletions std/io.ft
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Standard module: io
*/
mod io

// return the parameter value plus one
Expand Down
3 changes: 3 additions & 0 deletions std/lang.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: lang
*/
mod lang
3 changes: 3 additions & 0 deletions std/list.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: list
*/
mod list
3 changes: 3 additions & 0 deletions std/math.ft
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Standard module: math
*/
mod math

// Return the max of two numbers.
Expand Down
7 changes: 4 additions & 3 deletions std/os.ft
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* Standard module: os
*/
mod os

/*
* desc: 提示
* deep: 睡觉
* op: 结束
* If desc is empty to print random str.
*/
def (desc: str, deep + op: int) loop
def i: int = 0
Expand Down
3 changes: 3 additions & 0 deletions std/pl.ft
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Standard module: pl
*/
mod pl

use math /* MATH MOD */
Expand Down
3 changes: 3 additions & 0 deletions std/sort.ft
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Standard module: sort
*/
mod sort

// Return the index of target number
Expand Down
3 changes: 3 additions & 0 deletions std/sql.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: sql
*/
mod sql
3 changes: 3 additions & 0 deletions std/stack.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: stack
*/
mod stack
5 changes: 4 additions & 1 deletion std/str.ft
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Standard module: str
*/
mod str

// Return the count of character in string
Expand Down Expand Up @@ -28,7 +31,7 @@ def (lp: int) random_str -> []str
ret []
nf
def res: [20]str

for def i: int = 0; lp > 0; lp -= 1
res[i] = randomStr(20, T)
i += 1
Expand Down
3 changes: 3 additions & 0 deletions std/sys.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: sys
*/
mod sys
3 changes: 3 additions & 0 deletions std/time.ft
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/*
* Standard module: time
*/
mod time

0 comments on commit ee3f2ae

Please sign in to comment.