-
Notifications
You must be signed in to change notification settings - Fork 0
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 #63 from skx/61-stdlib
61 stdlib
- Loading branch information
Showing
17 changed files
with
701 additions
and
580 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
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 |
---|---|---|
@@ -1,19 +1,74 @@ | ||
// Package stdlib contains a simple/small standard-library, which | ||
// is written in lisp itself. | ||
// Package stdlib contains a simple/small standard-library, which is written in lisp itself. | ||
// | ||
// By default our standard library is loaded prior to the execution of any user-supplied | ||
// code, however parts of it can be selectively ignored, or the whole thing. | ||
// | ||
// If the environmental varialbe "YAL_STDLIB_EXCLUDE_ALL" contains non-empty content then | ||
// all of our standard-library is disabled. | ||
// | ||
// Otherwise if YAL_STDLIB_EXCLUDE is set to a non-empty string it will be assumed to be | ||
// a comma-separated list of filename substrings to exclude. | ||
package stdlib | ||
|
||
import ( | ||
_ "embed" // embedded-resource magic | ||
"embed" // embedded-resource magic | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
//go:embed stdlib.lisp | ||
var stdlib string | ||
|
||
//go:embed mal.lisp | ||
var mal string | ||
//go:embed stdlib/*.lisp | ||
var stdlib embed.FS | ||
|
||
// Contents returns the embedded contents of our Lisp standard-library. | ||
// | ||
// We embed "*.lisp" when we build our binary | ||
func Contents() []byte { | ||
|
||
return []byte(stdlib + "\n" + mal + "\n") | ||
// Result | ||
result := []byte{} | ||
|
||
// We can allow disabling the stdlib. | ||
if os.Getenv("YAL_STDLIB_EXCLUDE_ALL") != "" { | ||
return result | ||
} | ||
|
||
// We might exclude only one/two files | ||
exclude := []string{} | ||
if os.Getenv("YAL_STDLIB_EXCLUDE") != "" { | ||
exclude = strings.Split(os.Getenv("YAL_STDLIB_EXCLUDE"), ",") | ||
} | ||
|
||
// Read the list of entries - can't fail | ||
entries, _ := stdlib.ReadDir("stdlib") | ||
|
||
// For each entry | ||
for _, entry := range entries { | ||
|
||
// Get the filename | ||
fp := filepath.Join("stdlib", entry.Name()) | ||
|
||
// Does this match an excluded value? | ||
skip := false | ||
|
||
for _, tmp := range exclude { | ||
if strings.Contains(fp, tmp) { | ||
skip = true | ||
} | ||
} | ||
|
||
if skip { | ||
fmt.Printf("Skipping %s\n", fp) | ||
continue | ||
} | ||
|
||
// Read the content - can't fail | ||
data, _ := stdlib.ReadFile(fp) | ||
|
||
// Append to our result | ||
result = append(result, data...) | ||
} | ||
|
||
return result | ||
} |
Oops, something went wrong.