aboutsummaryrefslogtreecommitdiff
path: root/pkg/lang
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang')
-rw-r--r--pkg/lang/compiler/compiler.go41
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")
+}