Skip to content

Commit 2a66684

Browse files
committed
Move vm and related packages to a single package
The idea is that the VM can be in an independent single package and used with multiple frontend compilers and languages. Right now, the elemental package still relies on the ast package. The AST probably also belongs in the elemental package, but I'm not sure yet. There also needs to be mechanism that de-couples module imports from the ast package. This could probably be done by giving the VM an import function to be called whenever an IMPORT opcode is executed. This would hand off the actualy importing to the support application using the VM.
1 parent 50fe7ed commit 2a66684

53 files changed

Lines changed: 547 additions & 542 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/nitrogen/nitrogen.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818
builtinOs "github.com/nitrogen-lang/nitrogen/src/builtins/os"
1919
"github.com/nitrogen-lang/nitrogen/src/compiler"
2020
"github.com/nitrogen-lang/nitrogen/src/compiler/marshal"
21+
"github.com/nitrogen-lang/nitrogen/src/elemental/compile"
22+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
23+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
2124
"github.com/nitrogen-lang/nitrogen/src/lexer"
2225
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
23-
"github.com/nitrogen-lang/nitrogen/src/object"
2426
"github.com/nitrogen-lang/nitrogen/src/parser"
2527
"github.com/nitrogen-lang/nitrogen/src/scgi"
26-
"github.com/nitrogen-lang/nitrogen/src/vm"
2728

2829
_ "github.com/nitrogen-lang/nitrogen/src/builtins"
2930
)
@@ -111,7 +112,7 @@ func main() {
111112
// Add Noble package manager path
112113
homeDir, _ := os.UserHomeDir()
113114
if homeDir != "" {
114-
modulePaths = append(modulePaths, filepath.Join(homeDir, ".noble", "pkg"))
115+
modulePaths = append(modulePaths, filepath.Join(homeDir, ".noble", "pkgs"))
115116
}
116117

117118
if printVersion {
@@ -167,7 +168,7 @@ func main() {
167168
env := makeEnv(sourceFile)
168169
builtinOs.SetCmdArgs(getScriptArgs(sourceFile))
169170

170-
var code *compiler.CodeBlock
171+
var code *compile.CodeBlock
171172
var program *ast.Program
172173
var err error
173174
if filepath.Ext(sourceFile) == ".nib" {
@@ -231,7 +232,7 @@ func main() {
231232
}
232233
}
233234

234-
func runCompiledCode(code *compiler.CodeBlock, env *object.Environment) object.Object {
235+
func runCompiledCode(code *compile.CodeBlock, env *object.Environment) object.Object {
235236
if fullDebug {
236237
fmt.Println("DEBUG: Script bytecode:")
237238
code.Print(" ")
@@ -312,7 +313,7 @@ func startRepl(in io.Reader, out io.Writer) {
312313
scanner := bufio.NewScanner(in)
313314
env := makeEnv("")
314315

315-
var code *compiler.CodeBlock
316+
var code *compile.CodeBlock
316317
for {
317318
fmt.Fprint(out, interactivePrompt)
318319
scanned := scanner.Scan()

cmd/nitrogenc/nitrogenc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
"github.com/nitrogen-lang/nitrogen/src/compiler"
1212
"github.com/nitrogen-lang/nitrogen/src/compiler/marshal"
13+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
1314
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
14-
"github.com/nitrogen-lang/nitrogen/src/vm"
1515
)
1616

1717
var (

cmd/nitrogenrun/nitrogenrun.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"time"
1414

1515
builtinOs "github.com/nitrogen-lang/nitrogen/src/builtins/os"
16-
"github.com/nitrogen-lang/nitrogen/src/compiler"
1716
"github.com/nitrogen-lang/nitrogen/src/compiler/marshal"
17+
"github.com/nitrogen-lang/nitrogen/src/elemental/compile"
18+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
19+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
1820
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
19-
"github.com/nitrogen-lang/nitrogen/src/object"
2021
"github.com/nitrogen-lang/nitrogen/src/scgi"
21-
"github.com/nitrogen-lang/nitrogen/src/vm"
2222

2323
_ "github.com/nitrogen-lang/nitrogen/src/builtins"
2424
)
@@ -92,7 +92,7 @@ func main() {
9292
// Add Noble package manager path
9393
homeDir, _ := os.UserHomeDir()
9494
if homeDir != "" {
95-
modulePaths = append(modulePaths, filepath.Join(homeDir, ".noble", "pkg"))
95+
modulePaths = append(modulePaths, filepath.Join(homeDir, ".noble", "pkgs"))
9696
}
9797

9898
if printVersion {
@@ -177,7 +177,7 @@ func main() {
177177
}
178178
}
179179

180-
func runCompiledCode(code *compiler.CodeBlock, env *object.Environment) object.Object {
180+
func runCompiledCode(code *compile.CodeBlock, env *object.Environment) object.Object {
181181
if fullDebug {
182182
code.Print("")
183183
}

src/builtins/classes/classes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package classes
22

33
import (
4+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
5+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
46
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
5-
"github.com/nitrogen-lang/nitrogen/src/object"
6-
"github.com/nitrogen-lang/nitrogen/src/vm"
77
)
88

99
func init() {

src/builtins/collections/collections.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package collections
33
import (
44
"sort"
55

6+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
7+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
68
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
7-
"github.com/nitrogen-lang/nitrogen/src/object"
8-
"github.com/nitrogen-lang/nitrogen/src/vm"
99
)
1010

1111
func init() {

src/builtins/errors/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package errors
22

33
import (
4+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
5+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
46
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
5-
"github.com/nitrogen-lang/nitrogen/src/object"
6-
"github.com/nitrogen-lang/nitrogen/src/vm"
77
)
88

99
func init() {

src/builtins/file/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"io/ioutil"
66
"os"
77

8+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
9+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
810
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
9-
"github.com/nitrogen-lang/nitrogen/src/object"
10-
"github.com/nitrogen-lang/nitrogen/src/vm"
1111
)
1212

1313
const (

src/builtins/file/filec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"io/ioutil"
88
"os"
99

10+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
11+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
1012
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
11-
"github.com/nitrogen-lang/nitrogen/src/object"
12-
"github.com/nitrogen-lang/nitrogen/src/vm"
1313
)
1414

1515
func vmFileOpenFile(interpreter *vm.VirtualMachine, self *vm.VMInstance, env *object.Environment, args ...object.Object) object.Object {

src/builtins/filepath/filepath.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"os"
55
stdfp "path/filepath"
66

7+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
8+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
79
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
8-
"github.com/nitrogen-lang/nitrogen/src/object"
9-
"github.com/nitrogen-lang/nitrogen/src/vm"
1010
)
1111

1212
func init() {

src/builtins/http/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"net/http"
77
"strings"
88

9+
"github.com/nitrogen-lang/nitrogen/src/elemental/object"
10+
"github.com/nitrogen-lang/nitrogen/src/elemental/vm"
911
"github.com/nitrogen-lang/nitrogen/src/moduleutils"
10-
"github.com/nitrogen-lang/nitrogen/src/object"
11-
"github.com/nitrogen-lang/nitrogen/src/vm"
1212
)
1313

1414
func init() {

0 commit comments

Comments
 (0)