Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .trae/rules/project_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,54 @@ Common Options:
--dry-run Do not actually run the command
--build-graph Generate build graph

# Project Agents.md Guide

This is a [MoonBit](https://docs.moonbitlang.com) project.

## Project Structure

- MoonBit packages are organized per directory, for each directory, there is a
`package.json` file listing its dependencies. Each package has its files and
blackbox test files (common, ending in `_test.mbt`) and whitebox test files
(ending in `_wbtest.mbt`).

- In the toplevel directory, this is a `moon.mod.json` file listing about the
module and some meta information.

## Coding convention

- MoonBit code is organized in block style, each block is separated by `///|`,
the order of each block is irrelevant. In some refactorings, you can process
block by block independently.

- Try to keep deprecated blocks in file called `deprecated.mbt` in each
directory.

## Tooling

- `moon fmt` is used to format your code properly.

- `moon info` is used to update the generated interface of the package, each
package has a generated interface file `.mbti`, it is a brief formal
description of the package. If nothing in `.mbti` changes, this means your
change does not bring the visible changes to the external package users, it is
typically a safe refactoring.

- In the last step, run `moon info && moon fmt` to update the interface and
format the code. Check the diffs of `.mbti` file to see if the changes are
expected.

- Run `moon test` to check the test is passed. MoonBit supports snapshot
testing, so when your changes indeed change the behavior of the code, you
should run `moon test --update` to update the snapshot.

- You can run `moon check` to check the code is linted correctly.

- When writing tests, you are encouraged to use `inspect` and run
`moon test --update` to update the snapshots, only use assertions like
`assert_eq` when you are in some loops where each snapshot may vary. You can
use `moon coverage analyze > uncovered.log` to see which parts of your code
are not covered by tests.

- agent-todo.md has some small tasks that are easy for AI to pick up, agent is
welcome to finish the tasks and check the box when you are done
3 changes: 1 addition & 2 deletions moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "oboard/moonbit-eval",
"version": "0.8.11",
"version": "0.8.13",
"deps": {
"moonbitlang/parser": "0.1.11",
"oboard/mio": "0.4.3",
"bobzhang/zip": "0.1.0"
},
"readme": "README.md",
Expand Down
5 changes: 5 additions & 0 deletions src/example/main.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
///|
fn main {
let result = @eval.MoonBitVM::new().eval("1 + 2")
println(result)
}
9 changes: 9 additions & 0 deletions src/example/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"is-main": true,
"import": [
{
"path": "oboard/moonbit-eval",
"alias": "eval"
}
]
}
13 changes: 13 additions & 0 deletions src/example/pkg.generated.mbti
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "oboard/moonbit-eval/example"

// Values

// Errors

// Types and methods

// Type aliases

// Traits

8 changes: 8 additions & 0 deletions src/export.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ pub fn eval_result_to_string(result : EvalResult) -> String {
}
}

///|
pub fn code_to_ast(code : String) -> String {
match @interpreter.parse_code_to_impl(code) {
Ok(i) => i.to_json().stringify()
Err(msg) => msg
}
}

///|
pub fn add_extern_fn(
vm : MoonBitVM,
Expand Down
1 change: 1 addition & 0 deletions src/moon.pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"create",
"eval",
"eval_result_to_string",
"code_to_ast",
"add_extern_fn",
"add_embedded_fn",
"add_embedded_method",
Expand Down
189 changes: 0 additions & 189 deletions src/mooncakes/loader.mbt

This file was deleted.

10 changes: 0 additions & 10 deletions src/mooncakes/moon.pkg.json

This file was deleted.

24 changes: 0 additions & 24 deletions src/mooncakes/pkg.generated.mbti

This file was deleted.

2 changes: 2 additions & 0 deletions src/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fn add_embedded_method(MoonBitVM, String, String, (@interpreter.RuntimeFunctionC

fn add_extern_fn(MoonBitVM, String, (@interpreter.RuntimeFunctionContext) -> @interpreter.RuntimeValue raise @interpreter.ControlFlow) -> Unit

fn code_to_ast(String) -> String

fn eval_result_to_string(EvalResult) -> String

fn expr_to_string(@syntax.Expr) -> String
Expand Down
4 changes: 1 addition & 3 deletions src/test/moon.pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"path": "oboard/moonbit-eval",
"alias": "eval"
},
"oboard/moonbit-eval/interpreter",
"oboard/mio",
"oboard/moonbit-eval/mooncakes"
"oboard/moonbit-eval/interpreter"
]
}
Loading