-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from majiru/plan9-support
Plan9 support
- Loading branch information
Showing
7 changed files
with
194 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !plan9 | ||
|
||
package core | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// +build !plan9 | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
. "github.com/candid82/joker/core" | ||
"github.com/chzyer/readline" | ||
) | ||
|
||
func repl(phase Phase) { | ||
ProcessReplData() | ||
GLOBAL_ENV.FindNamespace(MakeSymbol("user")).ReferAll(GLOBAL_ENV.FindNamespace(MakeSymbol("joker.repl"))) | ||
fmt.Printf("Welcome to joker %s. Use EOF (Ctrl-D) or SIGINT (Ctrl-C) to exit.\n", VERSION) | ||
parseContext := &ParseContext{GlobalEnv: GLOBAL_ENV} | ||
replContext := NewReplContext(parseContext.GlobalEnv) | ||
|
||
var runeReader io.RuneReader | ||
var rl *readline.Instance | ||
var err error | ||
if noReadline { | ||
runeReader = bufio.NewReader(Stdin) | ||
} else { | ||
rl, err = readline.New("") | ||
if err != nil { | ||
fmt.Println("Error: " + err.Error()) | ||
return | ||
} | ||
defer rl.Close() | ||
runeReader = NewLineRuneReader(rl) | ||
for _, line := range strings.Split(string(dataRead), "\n") { | ||
rl.SaveHistory(line) | ||
} | ||
dataRead = []rune{} | ||
} | ||
|
||
reader := NewReader(runeReader, "<repl>") | ||
|
||
for { | ||
if noReadline { | ||
print(GLOBAL_ENV.CurrentNamespace().Name.ToString(false) + "=> ") | ||
} else { | ||
rl.SetPrompt(GLOBAL_ENV.CurrentNamespace().Name.ToString(false) + "=> ") | ||
} | ||
if processReplCommand(reader, phase, parseContext, replContext) { | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
|
||
. "github.com/candid82/joker/core" | ||
) | ||
|
||
func repl(phase Phase) { | ||
ProcessReplData() | ||
GLOBAL_ENV.FindNamespace(MakeSymbol("user")).ReferAll(GLOBAL_ENV.FindNamespace(MakeSymbol("joker.repl"))) | ||
fmt.Printf("Welcome to joker %s. Use EOF (Ctrl-D) or SIGINT (Ctrl-C) to exit.\n", VERSION) | ||
parseContext := &ParseContext{GlobalEnv: GLOBAL_ENV} | ||
replContext := NewReplContext(parseContext.GlobalEnv) | ||
|
||
var runeReader io.RuneReader | ||
runeReader = bufio.NewReader(Stdin) | ||
reader := NewReader(runeReader, "<repl>") | ||
|
||
for { | ||
print(GLOBAL_ENV.CurrentNamespace().Name.ToString(false) + "=> ") | ||
if processReplCommand(reader, phase, parseContext, replContext) { | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// +build !plan9 | ||
|
||
package os | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os/exec" | ||
"syscall" | ||
|
||
. "github.com/candid82/joker/core" | ||
) | ||
|
||
func sh(dir string, stdin io.Reader, stdout io.Writer, stderr io.Writer, name string, args []string) Object { | ||
cmd := exec.Command(name, args...) | ||
cmd.Dir = dir | ||
cmd.Stdin = stdin | ||
|
||
var stdoutBuffer, stderrBuffer bytes.Buffer | ||
if stdout != nil { | ||
cmd.Stdout = stdout | ||
} else { | ||
cmd.Stdout = &stdoutBuffer | ||
} | ||
if stderr != nil { | ||
cmd.Stderr = stderr | ||
} else { | ||
cmd.Stderr = &stderrBuffer | ||
} | ||
|
||
err := cmd.Start() | ||
PanicOnErr(err) | ||
|
||
err = cmd.Wait() | ||
|
||
res := EmptyArrayMap() | ||
res.Add(MakeKeyword("success"), Boolean{B: err == nil}) | ||
|
||
var exitCode int | ||
if err != nil { | ||
res.Add(MakeKeyword("err-msg"), String{S: err.Error()}) | ||
if exiterr, ok := err.(*exec.ExitError); ok { | ||
ws := exiterr.Sys().(syscall.WaitStatus) | ||
exitCode = ws.ExitStatus() | ||
} else { | ||
exitCode = defaultFailedCode | ||
} | ||
} else { | ||
ws := cmd.ProcessState.Sys().(syscall.WaitStatus) | ||
exitCode = ws.ExitStatus() | ||
} | ||
res.Add(MakeKeyword("exit"), Int{I: exitCode}) | ||
if stdout == nil { | ||
res.Add(MakeKeyword("out"), String{S: string(stdoutBuffer.Bytes())}) | ||
} | ||
if stderr == nil { | ||
res.Add(MakeKeyword("err"), String{S: string(stderrBuffer.Bytes())}) | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package os | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os/exec" | ||
|
||
. "github.com/candid82/joker/core" | ||
) | ||
|
||
func sh(dir string, stdin io.Reader, stdout io.Writer, stderr io.Writer, name string, args []string) Object { | ||
cmd := exec.Command(name, args...) | ||
cmd.Dir = dir | ||
cmd.Stdin = stdin | ||
|
||
var stdoutBuffer, stderrBuffer bytes.Buffer | ||
if stdout != nil { | ||
cmd.Stdout = stdout | ||
} else { | ||
cmd.Stdout = &stdoutBuffer | ||
} | ||
if stderr != nil { | ||
cmd.Stderr = stderr | ||
} else { | ||
cmd.Stderr = &stderrBuffer | ||
} | ||
|
||
err := cmd.Start() | ||
PanicOnErr(err) | ||
|
||
err = cmd.Wait() | ||
|
||
res := EmptyArrayMap() | ||
res.Add(MakeKeyword("success"), Boolean{B: err == nil}) | ||
|
||
var exitCode int | ||
if err != nil { | ||
res.Add(MakeKeyword("err-msg"), String{S: err.Error()}) | ||
exitCode = defaultFailedCode | ||
} else { | ||
exitCode = 0 | ||
} | ||
res.Add(MakeKeyword("exit"), Int{I: exitCode}) | ||
if stdout == nil { | ||
res.Add(MakeKeyword("out"), String{S: string(stdoutBuffer.Bytes())}) | ||
} | ||
if stderr == nil { | ||
res.Add(MakeKeyword("err"), String{S: string(stderrBuffer.Bytes())}) | ||
} | ||
return res | ||
} |