Skip to content

Commit

Permalink
fix mdlint
Browse files Browse the repository at this point in the history
  • Loading branch information
DawnMagnet committed Jun 27, 2024
1 parent cb08a85 commit b03760f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions course14/lec14_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ enum Instruction {
Add; Sub; Modulo; Equal // Add, Subtract, Modulo, Equal
Call(String) // Function call
Local_Get(String); Local_Set(String) // Get value, Set value
If(Int, List[Instruction], List[Instruction]) // Conditional statement
If(Int, @immut/list.List[Instruction], @immut/list.List[Instruction]) // Conditional statement
}
```

Expand All @@ -113,16 +113,16 @@ enum Instruction {
struct Function {
name : String
// Only considering one data type, so omit the type of each data, only keep the name and quantity
params : List[String]; result : Int; locals : List[String]
instructions : List[Instruction]
params : @immut/list.List[String]; result : Int; locals : @immut/list.List[String]
instructions : @immut/list.List[Instruction]
}
```

- Programs

```moonbit
struct Program {
functions : List[Function]
functions : @immut/list.List[Function]
start : Option[String]
}
```
Expand All @@ -132,7 +132,7 @@ struct Program {
- Example: `1 + 2`

```moonbit no-check
List::[ Const(1), Const(2), Add ]
@immut/list.List::[ Const(1), Const(2), Add ]
```

![](../pics/add.drawio.svg)
Expand All @@ -142,7 +142,7 @@ struct Program {
- Example: Function `add(a : Int, b : Int) { a + b }`

```moonbit no-check
List::[ Local_Get("a"), Local_Get("b"), Add ]
@immut/list.List::[ Local_Get("a"), Local_Get("b"), Add ]
```

- Function parameters and local variables can be accessed and modified via `Local_Get` and `Local_Set`.
Expand Down Expand Up @@ -175,9 +175,9 @@ struct Program {
- Example: `if 1 == 0 { 1 } else { 0 }`

```moonbit no-check
List::[
@immut/list.List::[
Const(1), Const(0), Equal,
If(1, List::[Const(1)], List::[Const(0)])
If(1, @immut/list.List::[Const(1)], @immut/list.List::[Const(0)])
]
```

Expand All @@ -195,17 +195,17 @@ let program = Program::{
start: Some("test_add"), // Program entry point
functions: List::[
functions: @immut/list.List::[
Function::{
name: "add", // Addition function
params: List::["a", "b"], result: 1, locals: List::[],
instructions: List::[Local_Get("a"), Local_Get("b"), Add],
params: @immut/list.List::["a", "b"], result: 1, locals: @immut/list.List::[],
instructions: @immut/list.List::[Local_Get("a"), Local_Get("b"), Add],
},
Function::{
name: "test_add", // calculate add and output
params: List::[], result: 0, locals: List::[], // entry function with no input or output
params: @immut/list.List::[], result: 0, locals: @immut/list.List::[], // entry function with no input or output
// “print_int" is a special function
instructions: List::[Const(0), Const(1), Call("add"), Call("print_int")],
instructions: @immut/list.List::[Const(0), Const(1), Call("add"), Call("print_int")],
},
],
}
Expand Down Expand Up @@ -254,7 +254,7 @@ let program = Program::{
| `Local_Get("a")` | `local.get $a` |
| `Local_Set("a")` | `local.set $a` |
| `Call("add")` | `call $add` |
| `If(1, List::[Const(0)], List::[Const(1)])` | `if (result i32) i32.const 0 else i32.const 1 end` |
| `If(1, @immut/list.List::[Const(0)], @immut/list.List::[Const(1)])` | `if (result i32) i32.const 0 else i32.const 1 end` |

# Compile Program

Expand Down Expand Up @@ -310,12 +310,12 @@ let program = Program::{
- String → Token Stream → (Abstract Syntax Tree) → WASM IR → Compile/Run

```moonbit no-check
fn compile_expression(expression : Expression) -> List[Instruction] {
fn compile_expression(expression : Expression) -> @immut/list.List[Instruction] {
match expression {
Number(i) => List::[Const(I32(i))]
Plus(a, b) => compile_expression(a) + compile_expression(b) + List::[Add]
Minus(a, b) => compile_expression(a) + compile_expression(b) + List::[Sub]
_ => List::[]
Number(i) => @immut/list.List::[Const(I32(i))]
Plus(a, b) => compile_expression(a) + compile_expression(b) + @immut/list.List::[Add]
Minus(a, b) => compile_expression(a) + compile_expression(b) + @immut/list.List::[Sub]
_ => @immut/list.List::[]
}
}
```
Expand Down Expand Up @@ -345,9 +345,9 @@ enum AdministrativeInstruction {

struct State {
program : Program
stack : List[StackValue]
stack : @immut/list.List[StackValue]
locals : @map.Map[String, Value]
instructions : List[AdministrativeInstruction]
instructions : @immut/list.List[AdministrativeInstruction]
}
```
Expand Down

0 comments on commit b03760f

Please sign in to comment.