Skip to content

Commit

Permalink
Clojure doesn't really stabilize any std ports, so Joker needn't
Browse files Browse the repository at this point in the history
  • Loading branch information
jcburley committed Dec 31, 2019
1 parent 9dcc40c commit d4107ce
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
8 changes: 3 additions & 5 deletions core/buffered_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ type (
}
)

func MakeBufferedReader(rd io.Reader, hash uint32) *BufferedReader {
res := &BufferedReader{bufio.NewReader(rd), hash}
if hash == 0 {
res.hash = HashPtr(uintptr(unsafe.Pointer(res)))
}
func MakeBufferedReader(rd io.Reader) *BufferedReader {
res := &BufferedReader{bufio.NewReader(rd), 0}
res.hash = HashPtr(uintptr(unsafe.Pointer(res)))
return res
}

Expand Down
10 changes: 3 additions & 7 deletions core/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func (env *Env) SetClassPath(cp string) {
env.classPath.Value = cpVec
}

const stdinHashValue uint32 = 0x1fc542bb
const stdoutHashValue uint32 = 0xef3ebf05
const stderrHashValue uint32 = 0xbfa32704

func NewEnv(currentNs Symbol, stdin io.Reader, stdout io.Writer, stderr io.Writer) *Env {
features := EmptySet()
features.Add(MakeKeyword("default"))
Expand All @@ -91,11 +87,11 @@ func NewEnv(currentNs Symbol, stdin io.Reader, stdout io.Writer, stderr io.Write
res.ns = res.CoreNamespace.Intern(MakeSymbol("*ns*"))
res.ns.Value = res.EnsureNamespace(currentNs)
res.stdin = res.CoreNamespace.Intern(MakeSymbol("*in*"))
res.stdin.Value = MakeBufferedReader(stdin, stdinHashValue)
res.stdin.Value = MakeBufferedReader(stdin)
res.stdout = res.CoreNamespace.Intern(MakeSymbol("*out*"))
res.stdout.Value = MakeIOWriter(stdout, stdoutHashValue)
res.stdout.Value = MakeIOWriter(stdout)
res.stderr = res.CoreNamespace.Intern(MakeSymbol("*err*"))
res.stderr.Value = MakeIOWriter(stderr, stderrHashValue)
res.stderr.Value = MakeIOWriter(stderr)
res.file = res.CoreNamespace.Intern(MakeSymbol("*file*"))
res.MainFile = res.CoreNamespace.Intern(MakeSymbol("*main-file*"))
res.version = res.CoreNamespace.InternVar("*joker-version*", versionMap(),
Expand Down
8 changes: 3 additions & 5 deletions core/io_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ type (
}
)

func MakeIOWriter(w io.Writer, hash uint32) *IOWriter {
res := &IOWriter{w, hash}
if hash == 0 {
res.hash = HashPtr(uintptr(unsafe.Pointer(res)))
}
func MakeIOWriter(w io.Writer) *IOWriter {
res := &IOWriter{w, 0}
res.hash = HashPtr(uintptr(unsafe.Pointer(res)))
return res
}

Expand Down
2 changes: 1 addition & 1 deletion core/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ var procBuffer Proc = func(args []Object) Object {
var procBufferedReader Proc = func(args []Object) Object {
switch rdr := args[0].(type) {
case io.Reader:
return MakeBufferedReader(rdr, 0)
return MakeBufferedReader(rdr)
default:
panic(RT.NewArgTypeError(0, args[0], "IOReader"))
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func srepl(port string, phase Phase) {
Stdin = conn
Stdout = conn
Stderr = conn
newIn := MakeBufferedReader(conn, 0)
newOut := MakeIOWriter(conn, 0)
newIn := MakeBufferedReader(conn)
newOut := MakeIOWriter(conn)
GLOBAL_ENV.SetStdIO(newIn, newOut, newOut)
defer func() {
conn.Close()
Expand Down
6 changes: 1 addition & 5 deletions tests/eval/hash.joke
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@
(is (= (hash :hey) 819820356))
(is (= (hash :there) 1648208352))
(is (= (hash ::you) 3944753178))
(is (= (hash :user/foo) 1616868817)))
(testing "stable stdio hashes"
(is (= (hash *in*) 533021371))
(is (= (hash *out*) 4013866757))
(is (= (hash *err*) 3215140612))))
(is (= (hash :user/foo) 1616868817))))

0 comments on commit d4107ce

Please sign in to comment.