lang: funcs: core: Make module names public

This is needed for when we have nested modules.
This commit is contained in:
James Shubin
2019-05-20 08:45:43 -04:00
parent d5074871c7
commit 12582e963d
35 changed files with 49 additions and 49 deletions

View File

@@ -18,6 +18,6 @@
package coredatetime package coredatetime
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "datetime" ModuleName = "datetime"
) )

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
facts.ModuleRegister(moduleName, "now", func() facts.Fact { return &DateTimeFact{} }) // must register the fact and name facts.ModuleRegister(ModuleName, "now", func() facts.Fact { return &DateTimeFact{} }) // must register the fact and name
} }
// DateTimeFact is a fact which returns the current date and time. // DateTimeFact is a fact which returns the current date and time.

View File

@@ -27,7 +27,7 @@ import (
func init() { func init() {
// FIXME: consider renaming this to printf, and add in a format string? // FIXME: consider renaming this to printf, and add in a format string?
simple.ModuleRegister(moduleName, "print", &types.FuncValue{ simple.ModuleRegister(ModuleName, "print", &types.FuncValue{
T: types.NewType("func(a int) str"), T: types.NewType("func(a int) str"),
V: func(input []types.Value) (types.Value, error) { V: func(input []types.Value) (types.Value, error) {
epochDelta := input[0].Int() epochDelta := input[0].Int()

View File

@@ -27,7 +27,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "weekday", &types.FuncValue{ simple.ModuleRegister(ModuleName, "weekday", &types.FuncValue{
T: types.NewType("func(a int) str"), T: types.NewType("func(a int) str"),
V: Weekday, V: Weekday,
}) })

View File

@@ -26,7 +26,7 @@ import (
const Answer = 42 const Answer = 42
func init() { func init() {
simple.ModuleRegister(moduleName, "answer", &types.FuncValue{ simple.ModuleRegister(ModuleName, "answer", &types.FuncValue{
T: types.NewType("func() int"), T: types.NewType("func() int"),
V: func([]types.Value) (types.Value, error) { V: func([]types.Value) (types.Value, error) {
return &types.IntValue{V: Answer}, nil return &types.IntValue{V: Answer}, nil

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "errorbool", &types.FuncValue{ simple.ModuleRegister(ModuleName, "errorbool", &types.FuncValue{
T: types.NewType("func(a bool) str"), T: types.NewType("func(a bool) str"),
V: func(input []types.Value) (types.Value, error) { V: func(input []types.Value) (types.Value, error) {
if input[0].Bool() { if input[0].Bool() {

View File

@@ -18,6 +18,6 @@
package coreexample package coreexample
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "example" ModuleName = "example"
) )

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
facts.ModuleRegister(moduleName, "flipflop", func() facts.Fact { return &FlipFlopFact{} }) // must register the fact and name facts.ModuleRegister(ModuleName, "flipflop", func() facts.Fact { return &FlipFlopFact{} }) // must register the fact and name
} }
// FlipFlopFact is a fact which flips a bool repeatedly. This is an example fact // FlipFlopFact is a fact which flips a bool repeatedly. This is an example fact

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "int2str", &types.FuncValue{ simple.ModuleRegister(ModuleName, "int2str", &types.FuncValue{
T: types.NewType("func(a int) str"), T: types.NewType("func(a int) str"),
V: func(input []types.Value) (types.Value, error) { V: func(input []types.Value) (types.Value, error) {
return &types.StrValue{ return &types.StrValue{

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "str2int", &types.FuncValue{ simple.ModuleRegister(ModuleName, "str2int", &types.FuncValue{
T: types.NewType("func(a str) int"), T: types.NewType("func(a str) int"),
V: func(input []types.Value) (types.Value, error) { V: func(input []types.Value) (types.Value, error) {
var i int64 var i int64

View File

@@ -33,7 +33,7 @@ import (
) )
func init() { func init() {
funcs.ModuleRegister(moduleName, "vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name funcs.ModuleRegister(ModuleName, "vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name
} }
// VUMeterFunc is a gimmic function to display a vu meter from the microphone. // VUMeterFunc is a gimmic function to display a vu meter from the microphone.

View File

@@ -18,6 +18,6 @@
package corefmt package corefmt
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "fmt" ModuleName = "fmt"
) )

View File

@@ -29,7 +29,7 @@ import (
func init() { func init() {
// FIXME: should this be named sprintf instead? // FIXME: should this be named sprintf instead?
funcs.ModuleRegister(moduleName, "printf", func() interfaces.Func { return &PrintfFunc{} }) funcs.ModuleRegister(ModuleName, "printf", func() interfaces.Func { return &PrintfFunc{} })
} }
const ( const (

View File

@@ -18,6 +18,6 @@
package coremath package coremath
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "math" ModuleName = "math"
) )

View File

@@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
simplepoly.ModuleRegister(moduleName, "mod", []*types.FuncValue{ simplepoly.ModuleRegister(ModuleName, "mod", []*types.FuncValue{
{ {
T: types.NewType("func(int, int) int"), T: types.NewType("func(int, int) int"),
V: Mod, V: Mod,

View File

@@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "pow", &types.FuncValue{ simple.ModuleRegister(ModuleName, "pow", &types.FuncValue{
T: types.NewType("func(x float, y float) float"), T: types.NewType("func(x float, y float) float"),
V: Pow, V: Pow,
}) })

View File

@@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "sqrt", &types.FuncValue{ simple.ModuleRegister(ModuleName, "sqrt", &types.FuncValue{
T: types.NewType("func(x float) float"), T: types.NewType("func(x float) float"),
V: Sqrt, V: Sqrt,
}) })

View File

@@ -26,15 +26,15 @@ import (
func init() { func init() {
// TODO: Create a family method that will return a giant struct. // TODO: Create a family method that will return a giant struct.
simple.ModuleRegister(moduleName, "is_debian", &types.FuncValue{ simple.ModuleRegister(ModuleName, "is_debian", &types.FuncValue{
T: types.NewType("func() bool"), T: types.NewType("func() bool"),
V: IsDebian, V: IsDebian,
}) })
simple.ModuleRegister(moduleName, "is_redhat", &types.FuncValue{ simple.ModuleRegister(ModuleName, "is_redhat", &types.FuncValue{
T: types.NewType("func() bool"), T: types.NewType("func() bool"),
V: IsRedHat, V: IsRedHat,
}) })
simple.ModuleRegister(moduleName, "is_archlinux", &types.FuncValue{ simple.ModuleRegister(ModuleName, "is_archlinux", &types.FuncValue{
T: types.NewType("func() bool"), T: types.NewType("func() bool"),
V: IsArchLinux, V: IsArchLinux,
}) })

View File

@@ -18,6 +18,6 @@
package coreos package coreos
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "os" ModuleName = "os"
) )

View File

@@ -30,7 +30,7 @@ import (
) )
func init() { func init() {
funcs.ModuleRegister(moduleName, "readfile", func() interfaces.Func { return &ReadFileFunc{} }) // must register the func and name funcs.ModuleRegister(ModuleName, "readfile", func() interfaces.Func { return &ReadFileFunc{} }) // must register the func and name
} }
// ReadFileFunc is a function that reads the full contents from a local file. If // ReadFileFunc is a function that reads the full contents from a local file. If

View File

@@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "match", &types.FuncValue{ simple.ModuleRegister(ModuleName, "match", &types.FuncValue{
T: types.NewType("func(pattern str, s str) bool"), T: types.NewType("func(pattern str, s str) bool"),
V: Match, V: Match,
}) })

View File

@@ -18,6 +18,6 @@
package coreregexp package coreregexp
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "regexp" ModuleName = "regexp"
) )

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "split", &types.FuncValue{ simple.ModuleRegister(ModuleName, "split", &types.FuncValue{
T: types.NewType("func(a str, b str) []str"), T: types.NewType("func(a str, b str) []str"),
V: Split, V: Split,
}) })

View File

@@ -18,6 +18,6 @@
package corestrings package corestrings
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "strings" ModuleName = "strings"
) )

View File

@@ -25,7 +25,7 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "to_lower", &types.FuncValue{ simple.ModuleRegister(ModuleName, "to_lower", &types.FuncValue{
T: types.NewType("func(a str) str"), T: types.NewType("func(a str) str"),
V: ToLower, V: ToLower,
}) })

View File

@@ -41,7 +41,7 @@ const (
) )
func init() { func init() {
facts.ModuleRegister(moduleName, "cpu_count", func() facts.Fact { return &CPUCountFact{} }) // must register the fact and name facts.ModuleRegister(ModuleName, "cpu_count", func() facts.Fact { return &CPUCountFact{} }) // must register the fact and name
} }
// CPUCountFact is a fact that returns the current CPU count. // CPUCountFact is a fact that returns the current CPU count.

View File

@@ -26,19 +26,19 @@ import (
) )
func init() { func init() {
simple.ModuleRegister(moduleName, "getenv", &types.FuncValue{ simple.ModuleRegister(ModuleName, "getenv", &types.FuncValue{
T: types.NewType("func(str) str"), T: types.NewType("func(str) str"),
V: GetEnv, V: GetEnv,
}) })
simple.ModuleRegister(moduleName, "defaultenv", &types.FuncValue{ simple.ModuleRegister(ModuleName, "defaultenv", &types.FuncValue{
T: types.NewType("func(str, str) str"), T: types.NewType("func(str, str) str"),
V: DefaultEnv, V: DefaultEnv,
}) })
simple.ModuleRegister(moduleName, "hasenv", &types.FuncValue{ simple.ModuleRegister(ModuleName, "hasenv", &types.FuncValue{
T: types.NewType("func(str) bool"), T: types.NewType("func(str) bool"),
V: HasEnv, V: HasEnv,
}) })
simple.ModuleRegister(moduleName, "env", &types.FuncValue{ simple.ModuleRegister(ModuleName, "env", &types.FuncValue{
T: types.NewType("func() map{str: str}"), T: types.NewType("func() map{str: str}"),
V: Env, V: Env,
}) })

View File

@@ -23,7 +23,7 @@ import (
) )
func init() { func init() {
facts.ModuleRegister(moduleName, "hostname", func() facts.Fact { return &HostnameFact{} }) // must register the fact and name facts.ModuleRegister(ModuleName, "hostname", func() facts.Fact { return &HostnameFact{} }) // must register the fact and name
} }
// HostnameFact is a function that returns the hostname. // HostnameFact is a function that returns the hostname.

View File

@@ -30,7 +30,7 @@ const (
) )
func init() { func init() {
facts.ModuleRegister(moduleName, "load", func() facts.Fact { return &LoadFact{} }) // must register the fact and name facts.ModuleRegister(ModuleName, "load", func() facts.Fact { return &LoadFact{} }) // must register the fact and name
} }
// LoadFact is a fact which returns the current system load. // LoadFact is a fact which returns the current system load.

View File

@@ -18,6 +18,6 @@
package coresys package coresys
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "sys" ModuleName = "sys"
) )

View File

@@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
facts.ModuleRegister(moduleName, "uptime", func() facts.Fact { return &UptimeFact{} }) facts.ModuleRegister(ModuleName, "uptime", func() facts.Fact { return &UptimeFact{} })
} }
// UptimeFact is a fact which returns the current uptime of your system. // UptimeFact is a fact which returns the current uptime of your system.

View File

@@ -28,7 +28,7 @@ import (
) )
func init() { func init() {
funcs.ModuleRegister(moduleName, "exchange", func() interfaces.Func { return &ExchangeFunc{} }) funcs.ModuleRegister(ModuleName, "exchange", func() interfaces.Func { return &ExchangeFunc{} })
} }
// ExchangeFunc is special function which returns all the values of a given key // ExchangeFunc is special function which returns all the values of a given key

View File

@@ -28,7 +28,7 @@ import (
) )
func init() { func init() {
funcs.ModuleRegister(moduleName, "kvlookup", func() interfaces.Func { return &KVLookupFunc{} }) funcs.ModuleRegister(ModuleName, "kvlookup", func() interfaces.Func { return &KVLookupFunc{} })
} }
// KVLookupFunc is special function which returns all the values of a given key // KVLookupFunc is special function which returns all the values of a given key

View File

@@ -46,7 +46,7 @@ const (
) )
func init() { func init() {
funcs.ModuleRegister(moduleName, "schedule", func() interfaces.Func { return &SchedulePolyFunc{} }) funcs.ModuleRegister(ModuleName, "schedule", func() interfaces.Func { return &SchedulePolyFunc{} })
} }
// SchedulePolyFunc is special function which determines where code should run // SchedulePolyFunc is special function which determines where code should run

View File

@@ -18,6 +18,6 @@
package coreworld package coreworld
const ( const (
// moduleName is the prefix given to all the functions in this module. // ModuleName is the prefix given to all the functions in this module.
moduleName = "world" ModuleName = "world"
) )