Skip to content

Commit

Permalink
Fix for WASM support
Browse files Browse the repository at this point in the history
  • Loading branch information
odino committed Aug 25, 2019
1 parent 1b49f23 commit 5fb8d57
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Binary file modified docs/abs.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ func TestStringIndexExpressions(t *testing.T) {
}

func testEval(input string) object.Object {
env := object.NewEnvironment(os.Stdout)
env := object.NewEnvironment(os.Stdout, "")
lex := lexer.New(input)
p := parser.New(lex)
program := p.ParseProgram()
Expand Down
5 changes: 2 additions & 3 deletions evaluator/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ func jsonFn(tok token.Token, env *object.Environment, args ...object.Object) obj

s := args[0].(*object.String)
str := strings.TrimSpace(s.Value)
env = object.NewEnvironment(env.Writer)
env = object.NewEnvironment(env.Writer, env.Dir)
l := lexer.New(str)
p := parser.New(l)
var node ast.Node
Expand Down Expand Up @@ -1567,8 +1567,7 @@ func sourceFn(tok token.Token, env *object.Environment, args ...object.Object) o
// require("file.abs")
func requireFn(tok token.Token, env *object.Environment, args ...object.Object) object.Object {
file := filepath.Join(env.Dir, args[0].Inspect())
e := object.NewEnvironment(env.Writer)
e.Dir = filepath.Dir(file)
e := object.NewEnvironment(env.Writer, filepath.Dir(file))
return doSource(tok, e, file, args...)
}

Expand Down
2 changes: 1 addition & 1 deletion js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func runCode(this js.Value, i []js.Value) interface{} {
var buf bytes.Buffer
// the first argument to our function
code := i[0].String()
env := object.NewEnvironment(&buf)
env := object.NewEnvironment(&buf, "")
lex := lexer.New(code)
p := parser.New(lex)

Expand Down
12 changes: 6 additions & 6 deletions object/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package object

import (
"io"
"os"
"sort"
)

Expand All @@ -11,17 +10,18 @@ import (
// new environment has access to identifiers stored
// in the outer one.
func NewEnclosedEnvironment(outer *Environment) *Environment {
env := NewEnvironment(outer.Writer)
env := NewEnvironment(outer.Writer, outer.Dir)
env.outer = outer
return env
}

// NewEnvironment creates a new environment to run
// ABS in
func NewEnvironment(w io.Writer) *Environment {
// ABS in, specifying a writer for the output of the
// program and the base dir (which is used to require
// other scripts)
func NewEnvironment(w io.Writer, dir string) *Environment {
s := make(map[string]Object)
d, _ := os.Getwd()
return &Environment{store: s, outer: nil, Writer: w, Dir: d}
return &Environment{store: s, outer: nil, Writer: w, Dir: dir}
}

// Environment represent the environment associated
Expand Down
3 changes: 2 additions & 1 deletion repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var (
)

func init() {
env = object.NewEnvironment(os.Stdout)
d, _ := os.Getwd()
env = object.NewEnvironment(os.Stdout, d)
}

func completer(d prompt.Document) []prompt.Suggest {
Expand Down

0 comments on commit 5fb8d57

Please sign in to comment.