moon check --target native
moon fmtmoon test --target native# Run a single test file
moon test --target native -p moonbit-community/moonpython -f parser_line_test.mbt
# Run a subset by name (glob)
moon test --target native -F 'generated/expr/1454'
# Update snapshots when behavior intentionally changes
moon test --target native --updatemoon run cmd/main -- --parse-only path/to/file.pymoon run cmd/main -- path/to/program.pymoon run cmd/main -- examples/tasks.pymoon run cmd/main -- --stdlib Lib -m test.test_rangemoon run cmd/main -- --stdlib Lib examples/stdlib_imports.pypython3 scripts/run_libtests.py --target native --target-dir _buildmoon run cmd/main --target native -- --stdlib Lib -m unittest test.test_unittest.test_casepython3 scripts/run_libtests.py --target native --target-dir _build \
--pattern '^test\\.test_unittest($|\\.)' --timeout 120printf 'print("hello")\n' | moon run cmd/repllet source = "print(\"hi\")\n"
let result = @mpython.Interpreter::new().exec_source(source)
match result {
Ok(run) => {
// run.value / run.stdout / run.stderr
}
Err(err) => {
let msg = @mpython.format_runtime_error(err)
}
}pub(all) enum BcOp {
Nop
PopTop
DupTop
RotTwo
RotThree
LoadConst(Int)
LoadName(Int)
StoreName(Int)
DeleteName(Int)
LoadAttr(Int)
StoreAttr(Int)
DeleteAttr(Int)
LoadSubscr
StoreSubscr
DeleteSubscr
BuildTuple(Int)
BuildList(Int)
BuildMap(Int)
BuildSet(Int)
BuildSlice
ListAppend
ListExtend
SetAdd
SetUpdate
DictSetItem
DictUpdate
KwListExtendFromDict
ListToTuple
EvalFString
UnpackSequence(Int)
UnpackEx(Int, Int)
GetIter
ForIter(Int)
Unary(UnaryOp)
Binary(BinaryOp)
Compare(CompareOp)
Jump(Int)
JumpIfFalse(Int)
JumpIfTrue(Int)
JumpIfFalseOrPop(Int)
JumpIfTrueOrPop(Int)
UnwindJump(Int, Int)
SetupExcept(Int)
SetupFinally(Int)
PopExcept
EnterFinally(Int)
EndExcept
EndFinally
CheckExceptionMatch
LoadException
LoadExceptionType
LoadExceptionTypeName
LoadExceptionTraceback
HasPendingException
ClearPendingException
EnsureExceptionGroup
ExceptStarInit
ExceptStarMatch
ExceptStarEndHandler
ExceptStarRaiseRemaining
Raise
RaiseFrom
Reraise
AssertFail
AssertFailNone
Await
MatchPattern(Int)
MatchBind
MatchRestore
GenExpNew(Int, Int, Int)
AsyncGenExpNew(Int, Int, Int)
CallFunction(Int)
CallFunctionKw(Int)
CallFunctionVar
MakeFunction(Int, Int, Int)
MakeClass(Int, Int, Int)
MakeTypeAlias(Int)
StoreAnnotation(Int)
AugAssignName(Int, BinaryOp)
AugAssignAttr(Int, BinaryOp)
AugAssignSubscr(BinaryOp)
ImportName(Int, Int)
FromImport(Int, Int, Int)
CheckInFunctionScope(String)
CheckInCoroutineScope(String)
ReturnValue
}pub enum BinaryOp {
Add
Sub
Mul
MatMul
Div
FloorDiv
Mod
Pow
ShiftLeft
ShiftRight
BitAnd
BitXor
BitOr
} derive(ToJson)pub enum Expr {
Literal(Literal)
Name(String)
Tuple(Array[Expr])
List(Array[Expr])
ListComp(elt~ : Expr, clauses~ : Array[CompClause], filters~ : Array[Expr])
GenExp(elt~ : Expr, clauses~ : Array[CompClause], filters~ : Array[Expr])
Dict(Array[(Expr, Expr)])
DictComp(key~ : Expr, value~ : Expr, clauses~ : Array[CompClause], filters~ : Array[Expr])
Set(Array[Expr])
SetComp(elt~ : Expr, clauses~ : Array[CompClause], filters~ : Array[Expr])
Lambda(params~ : Array[String], defaults~ : Array[Expr], body~ : Expr)
IfExpr(condition~ : Expr, then_expr~ : Expr, else_expr~ : Expr)
FString(String)
NamedExpr(name~ : String, value~ : Expr)
Yield(Expr?)
YieldFrom(Expr)
Await(Expr)
Slice(start~ : Expr?, end~ : Expr?, step~ : Expr?)
Attribute(value~ : Expr, attr~ : String)
Subscript(value~ : Expr, index~ : Expr)
Call(callee~ : Expr, args~ : Array[Expr])
Keyword(name~ : String, value~ : Expr)
Starred(value~ : Expr)
DoubleStarred(value~ : Expr)
Unary(op~ : UnaryOp, expr~ : Expr)
Binary(op~ : BinaryOp, left~ : Expr, right~ : Expr)
BoolOp(op~ : BoolOp, values~ : Array[Expr])
Compare(left~ : Expr, ops~ : Array[CompareOp], comparators~ : Array[Expr])
WithSpan(span~ : Span, expr~ : Expr)
} derive(ToJson)fn Interpreter::execute_test_dir(self : Interpreter, path : String) -> TestResult raise MpythonErrorfn Interpreter::set_main_module_spec(self : Interpreter, module_name : String, origin : String, parent : String, is_package_main : Bool) -> Unitpub struct MockIO {
stdin : Array[String]
stdin_pos : Ref[Int]
stdout : StringBuilder
stderr : StringBuilder
}pub(all) struct RuntimeError {
kind : RuntimeErrorKind
message : String
span : Span?
traceback : Array[TracebackFrame]
traceback_envs : Array[TracebackEnv]
exc_type : String
exc_args : Array[String]
exc_value : Value?
exc_cause : Value?
exc_context : Value?
exc_suppress_context : Bool
} derive(ToJson)pub(all) enum RuntimeErrorKind {
Name
Type
Attribute
Index
Key
ZeroDivision
NotImplemented
Runtime
} derive(ToJson)pub enum Stmt {
ExprStmt(Expr)
Assign(target~ : Target, value~ : Expr)
AnnAssign(target~ : Target, annotation~ : Expr, value~ : Expr?)
AugAssign(target~ : Target, op~ : BinaryOp, value~ : Expr)
TypeAlias(name~ : String, type_params~ : Array[String], value~ : Expr)
Return(Expr?)
Yield(Expr?)
YieldFrom(Expr)
If(condition~ : Expr, body~ : Array[Stmt], else_body~ : Array[Stmt])
Match(subject~ : Expr, cases~ : Array[(Pattern, Expr?, Array[Stmt])])
While(condition~ : Expr, body~ : Array[Stmt], else_body~ : Array[Stmt])
For(target~ : Target, iter~ : Expr, body~ : Array[Stmt], else_body~ : Array[Stmt])
AsyncFor(target~ : Target, iter~ : Expr, body~ : Array[Stmt], else_body~ : Array[Stmt])
Break
Continue
Function(name~ : String, decorators~ : Array[Expr], type_params~ : Array[String], params~ : Array[String], defaults~ : Array[Expr], annotations~ : Array[(String, Expr)], return_annotation~ : Expr?, body~ : Array[Stmt], is_generator~ : Bool, is_async~ : Bool)
Pass
Global(Array[String])
Nonlocal(Array[String])
Assert(condition~ : Expr, message~ : Expr?)
Raise(exc~ : Expr?, cause~ : Expr?)
Del(Array[Target])
Import(module_name~ : String, alias_name~ : String?)
FromImport(module_name~ : String, names~ : Array[(String, String?)])
With(context~ : Expr, target~ : String?, body~ : Array[Stmt])
AsyncWith(context~ : Expr, target~ : String?, body~ : Array[Stmt])
Try(body~ : Array[Stmt], handlers~ : Array[ExceptHandler], else_body~ : Array[Stmt], finally_body~ : Array[Stmt])
Class(name~ : String, decorators~ : Array[Expr], type_params~ : Array[String], bases~ : Array[Expr], keywords~ : Array[(String, Expr)], body~ : Array[Stmt])
WithSpan(span~ : Span, stmt~ : Stmt)
} derive(ToJson)pub(all) struct TracebackFrame {
name : String
filename : String
line : Int
column : Int
end_column : Int
} derive(ToJson)pub enum Value {
None
Bool(Bool)
Int(BigInt)
Float(Double)
Complex(Double, Double)
Str(String)
Bytes(Array[Int])
ByteArray(Array[Int])
MemoryView(Array[Int])
List(Array[Value])
Tuple(Array[Value])
Dict(Array[(Value, Value)])
Set(Array[Value])
Function(FunctionValue)
Class(ClassValue)
Instance(InstanceValue)
BoundMethod(BoundMethodValue)
} derive(ToJson)fn compile_stmts_to_bc(body : Array[Stmt], name : String, filename : String) -> Result[BcCode, RuntimeError]fn compile_stmts_to_bc_with_future(body : Array[Stmt], name : String, filename : String, future_annotations : Bool) -> Result[BcCode, RuntimeError]