optimizations
This commit is contained in:
14
monkey.go
14
monkey.go
@@ -99,6 +99,10 @@ func ExecFile(fn string, opts *Options) error {
|
||||
err error
|
||||
)
|
||||
|
||||
if opts == nil {
|
||||
opts = &Options{}
|
||||
}
|
||||
|
||||
ext := filepath.Ext(fn)
|
||||
mc := fn[:len(fn)-len(ext)] + ".mc"
|
||||
|
||||
@@ -128,7 +132,7 @@ func ExecFile(fn string, opts *Options) error {
|
||||
}
|
||||
}
|
||||
|
||||
mvm := vm.New(fn, bytecode, vm.WithDebug(opts.Debug), vm.WithTrace(opts.Trace))
|
||||
mvm := vm.New(fn, bytecode, opts.ToVMOptions()...)
|
||||
if err := mvm.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -138,6 +142,10 @@ func ExecFile(fn string, opts *Options) error {
|
||||
|
||||
// ExecString executes a Monkey program from a string.
|
||||
func ExecString(input string, opts *Options) error {
|
||||
if opts == nil {
|
||||
opts = &Options{}
|
||||
}
|
||||
|
||||
bytecode, err := compileString(input, opts.Debug)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -157,6 +165,10 @@ func ExecString(input string, opts *Options) error {
|
||||
|
||||
// CompileFiles compiles multiple Monkey files and returns any errors encountered during compilation.
|
||||
func CompileFiles(fns []string, opts *Options) error {
|
||||
if opts == nil {
|
||||
opts = &Options{}
|
||||
}
|
||||
|
||||
for _, fn := range fns {
|
||||
ext := filepath.Ext(fn)
|
||||
mc := fn[:len(fn)-len(ext)] + ".mc"
|
||||
|
||||
Reference in New Issue
Block a user