diff options
| author | Mel <einebeere@gmail.com> | 2022-06-02 01:09:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-02 01:09:33 +0000 |
| commit | e57216d3b29ba9688918972c683da3ab0da3ad95 (patch) | |
| tree | c78634bb2165bb2149848b86e0a5c411318fef2b /pkg | |
| parent | 87d115da565618b2f2f1cbbdcca883bbc0c57e60 (diff) | |
| download | jinx-e57216d3b29ba9688918972c683da3ab0da3ad95.tar.zst jinx-e57216d3b29ba9688918972c683da3ab0da3ad95.zip | |
Create Lang compiler package
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/lang/compiler/compiler.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler.go b/pkg/lang/compiler/compiler.go new file mode 100644 index 0000000..bf34487 --- /dev/null +++ b/pkg/lang/compiler/compiler.go @@ -0,0 +1,41 @@ +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") +} |
