Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out []byte-array generation for core-library namespaces #345

Merged
merged 9 commits into from
Feb 6, 2020
51 changes: 51 additions & 0 deletions core/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// +build !gen_data

package core

func InitInternalLibs() {
internalLibs = map[string][]byte{
"joker.walk": walkData,
"joker.template": templateData,
"joker.repl": replData,
"joker.test": testData,
"joker.set": setData,
"joker.tools.cli": tools_cliData,
"joker.hiccup": hiccupData,
"joker.pprint": pprintData,
"joker.better-cond": better_condData,
}
}

func ProcessCoreData() {
processData(coreData)
if !haveSetCoreNamespaces {
setCoreNamespaces()
haveSetCoreNamespaces = true
}
}

func ProcessReplData() {
processData(replData)
}

func ProcessLinterData(dialect Dialect) {
if dialect == EDN {
markJokerNamespacesAsUsed()
return
}
processData(linter_allData)
GLOBAL_ENV.CoreNamespace.Resolve("*loaded-libs*").Value = EmptySet()
if dialect == JOKER {
markJokerNamespacesAsUsed()
processData(linter_jokerData)
return
}
processData(linter_cljxData)
switch dialect {
case CLJ:
processData(linter_cljData)
case CLJS:
processData(linter_cljsData)
}
removeJokerNamespaces()
}
2 changes: 2 additions & 0 deletions core/gen_data/gen_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const template string = `// Generated by gen_data. Don't modify manually!

{slowInit}package core

var {name}Data []byte

func init() {
{name}Data = []byte("{content}")
}
Expand Down
2 changes: 1 addition & 1 deletion core/object.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:generate go run gen/gen_types.go assert Comparable *Vector Char String Symbol Keyword *Regex Boolean Time Number Seqable Callable *Type Meta Int Double Stack Map Set Associative Reversible Named Comparator *Ratio *Namespace *Var Error *Fn Deref *Atom Ref KVReduce Pending *File io.Reader io.Writer StringReader io.RuneReader *Channel
//go:generate go run gen/gen_types.go info *List *ArrayMapSeq *ArrayMap *HashMap *ExInfo *Fn *Var Nil *Ratio *BigInt *BigFloat Char Double Int Boolean Time Keyword *Regex Symbol String *LazySeq *MappingSeq *ArraySeq *ConsSeq *NodeSeq *ArrayNodeSeq *MapSet *Vector *VectorSeq *VectorRSeq
//go:generate go run gen_data/gen_data.go
//go:generate go run -tags gen_data gen_data/gen_data.go

package core

Expand Down
73 changes: 5 additions & 68 deletions core/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,9 @@ import (
"unicode/utf8"
)

var coreNamespaces []string
var internalLibs map[string][]byte

var (
coreData []byte
replData []byte
walkData []byte
templateData []byte
testData []byte
setData []byte
tools_cliData []byte
linter_allData []byte
linter_jokerData []byte
linter_cljxData []byte
linter_cljData []byte
linter_cljsData []byte
hiccupData []byte
pprintData []byte
better_condData []byte
)
var coreNamespaces []string

type (
Phase int
Expand All @@ -57,8 +41,6 @@ const (

const VERSION = "v0.14.1"

var internalLibs map[string][]byte

const (
CLJ Dialect = iota
CLJS
Expand All @@ -67,20 +49,6 @@ const (
UNKNOWN
)

func InitInternalLibs() {
internalLibs = map[string][]byte{
"joker.walk": walkData,
"joker.template": templateData,
"joker.repl": replData,
"joker.test": testData,
"joker.set": setData,
"joker.tools.cli": tools_cliData,
"joker.hiccup": hiccupData,
"joker.pprint": pprintData,
"joker.better-cond": better_condData,
}
}

func ExtractCallable(args []Object, index int) Callable {
return EnsureCallable(args, index)
}
Expand Down Expand Up @@ -1772,6 +1740,9 @@ func processData(data []byte) {
_, err := TryEval(expr)
PanicOnErr(err)
}
if VerbosityLevel > 0 {
fmt.Fprintf(Stderr, "processData: Evaluated code for %s\n", GLOBAL_ENV.CurrentNamespace().ToString(false))
}
}

func setCoreNamespaces() {
Expand Down Expand Up @@ -1808,18 +1779,6 @@ var procIsNamespaceInitialized = func(args []Object) Object {

var haveSetCoreNamespaces bool

func ProcessCoreData() {
processData(coreData)
if !haveSetCoreNamespaces {
setCoreNamespaces()
haveSetCoreNamespaces = true
}
}

func ProcessReplData() {
processData(replData)
}

func findConfigFile(filename string, workingDir string, findDir bool) string {
var err error
configName := ".joker"
Expand Down Expand Up @@ -2022,28 +1981,6 @@ func markJokerNamespacesAsUsed() {
}
}

func ProcessLinterData(dialect Dialect) {
if dialect == EDN {
markJokerNamespacesAsUsed()
return
}
processData(linter_allData)
GLOBAL_ENV.CoreNamespace.Resolve("*loaded-libs*").Value = EmptySet()
if dialect == JOKER {
markJokerNamespacesAsUsed()
processData(linter_jokerData)
return
}
processData(linter_cljxData)
switch dialect {
case CLJ:
processData(linter_cljData)
case CLJS:
processData(linter_cljsData)
}
removeJokerNamespaces()
}

func NewReaderFromFile(filename string) (*Reader, error) {
f, err := os.Open(filename)
if err != nil {
Expand Down