package compiler import ( "jinx/pkg/lang/ast" "jinx/pkg/lang/vm/code" ) type Compiler struct { ast ast.Program } func New(ast ast.Program) *Compiler { return &Compiler{ ast: ast, } } func (comp *Compiler) Compile() (code.Code, error) { bc := make([]byte, 0, 1024) for _, stmt := range comp.ast.Stmts { if stmt.Kind != ast.StmtKindExpr { panic("statements other than expressions not implemented") } expr := stmt.Value.(ast.StmtExpr).Value res, err := comp.compileExpr(expr) if err != nil { return code.Code{}, err } bc = append(bc, res...) } return code.New(bc, code.NewDebugInfo("unknown file")), nil } func (comp *Compiler) compileExpr(expr ast.Expr) ([]byte, error) { panic("not implemented") }