Skip to content

Commit

Permalink
docs(programming book):fix book
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Apr 20, 2024
1 parent df45862 commit 21a9016
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ codegen-units = 1
strip = true

[workspace]
members = ["derive", ".", "stdlib", "libcore"]
members = ["derive", ".", "stdlib", "libcore", "trclsp"]

[package.metadata.i18n]
# The available locales for your application, default: ["en"].
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Trc is a easy-learn programming language. It can be fast,safe and effective.

|Platform|Status|
|:---|:---|
|Linux|![Linux Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_linux.yml)|
|Winodows|![Windows Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_windows.yml)|
|Macos|![Macos Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_macos.yml)|
| Platform | Status |
| :------- | :---------------------------------------------------------------------------------------------------- |
| Linux | ![Linux Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_linux.yml) |
| Winodows | ![Windows Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_windows.yml) |
| Macos | ![Macos Test](https://img.shields.io/github/actions/workflow/status/limuy2022/trc/rust_macos.yml) |

![Total Lines](https://tokei.rs/b1/github/limuy2022/trc)

Expand All @@ -31,7 +31,9 @@ But in order to read test data file,please run in the root dir.

## How to use

[Trc user Guide](docs/usage.md)
[Trc Programming Book](docs/usage.md)

[Trc Programming Book中文版](docs/usage-zh.md)

## Provide translation for this project

Expand Down
1 change: 1 addition & 0 deletions docs/usage-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Trc Programming Book
90 changes: 66 additions & 24 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# The usage of Rust version Trc
# The Trc Programming Book

This is a simple tutorial for Trc.Maybe it is not always catch up with the latest version of Trc.

## Hello world

Writing a hello world is the beginning of learning Trc.

```rust
```
println("Hello World!")
```

Expand Down Expand Up @@ -89,10 +91,10 @@ But,something should be noticed is that you cannot use logical operators for `in

So,code like this cannot be compiled successfully:

```rust
```
a := 1
if a {
println(a)
println("{}", a)
}
```

Expand All @@ -101,7 +103,7 @@ you cannot use the different types of values to calaulate

For example:

```go
```
a:=9
b:=7.8
a+b
Expand All @@ -115,7 +117,7 @@ First,you can use `if ... else if ... else` statements

An example:

```python
```
if 1 == 1 {
} else if 2 != 1 {
Expand All @@ -129,22 +131,66 @@ if 1 == 1 {

First:

```cpp
```
for i := 0; i < 10; i++ {
println(i)
}
```

Second:

```python
```
for i in xxx {
println(i)
}
```

`xxx` should be a iterable var

`match` is also supported:

different types are supported

if you want to match more than one values you should use `|`

example:

```
a:=9
match a {
1 -> {
println("1")
}
2 | 3 -> {
println("2 or 3")
}
_ -> {
println("other")
}
}
```

String is supported,too.

example:

```
a:="hello"
match a {
"hello" -> {
println("hello")
}
"world" -> {
println("world")
}
_ -> {
println("other")
}
}
```

Ok. It is very like rust programming.I like the rules of `match` in rust.

## the comments of Trc

Trc support two kinds of comments
Expand All @@ -153,7 +199,7 @@ the first is use `#`,from `#` to the end of the line belongs to the comment

the second is use `/**/`,this kind can cross the line,like:

```cpp
```
/*
hello world!
*/
Expand All @@ -163,16 +209,16 @@ hello world!

First,we support the UTF-8 with your var name.So you can define your var like this:

```go
```
你好:=90
```

the compiler will regard this var as a int var.

Sometimes maybe you want to define the type.Do it like this:

```go
int a:=90
```
a:int:=90
```

## Data structures for Trc
Expand All @@ -193,30 +239,26 @@ Std lib provide many kinds of data structures for Trc.Here is the list:

Define a function like this:

```go
func add(int a, int b) -> int {
return a + b;
```
func add(a:int, b:int) int {
return a + b
}
```

Or define a template function:

```go
func add<T>(T a, T b) -> T {
return a + b;
```
func add<T>(a:T, b:T) T {
return a + b
}
```

## module

You can import by the following ways:

```go
```
import "a.b.c"
```

Or:

```go
import "a/b/c"
```
`c` can be a function or a struct or a module
4 changes: 2 additions & 2 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ impl ModuleUnit {
// "{} {} {} {} {}",
// cache.intty_id, cache.floatty_id, cache.charty_id, cache.strty_id, cache.boolty_id
// );
drop(val_pool_ref);
let name_str = stdlib_dll_name.to_str().unwrap().to_owned();
ModuleUnit {
token_lexer,
Expand Down Expand Up @@ -878,6 +877,7 @@ impl ModuleUnit {
let mut path_with_dot = self.token_lexer.borrow_mut().const_pool.id_str[tok].clone();
// 具体文件的路径
let mut import_file_path = String::new();
// 是不是dll
let mut is_dll = false;
if path_with_dot.starts_with("std") {
// std特殊对待
Expand All @@ -890,7 +890,7 @@ impl ModuleUnit {
match tmp.option.inputsource.clone() {
InputSource::File(now_module_path) => {
let path = PathBuf::from(path_with_dot.replace('.', "/"));
let mut now_module_path = PathBuf::from(now_module_path);
let mut now_module_path = now_module_path;
now_module_path.pop();
now_module_path = now_module_path.join(path.clone());
let tmp = now_module_path.clone();
Expand Down
1 change: 1 addition & 0 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod build;
pub mod dis;
pub mod new;
pub mod run;
pub mod style;
pub mod tshell;

pub use build::build;
Expand Down
1 change: 1 addition & 0 deletions src/tools/style.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions trclsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "trclsp"
version = "0.1.0"
edition = "2021"

[dependencies]
3 changes: 3 additions & 0 deletions trclsp/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit 21a9016

Please sign in to comment.