Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* [Monkey](#monkey)
* [My changes](#my-changes)
* [1. Installation](#1-installation)
* [Source Installation go <= 1.11](#source-installation-go---111)
* [Source installation go >= 1.12](#source-installation-go--112)
* [Binary Releases](#binary-releases)
* [1.1 Usage](#11-usage)
* [2 Syntax](#2-syntax)
Expand Down Expand Up @@ -87,17 +85,9 @@ The interpreter in _this_ repository has been significantly extended from the st

## 1. Installation

There are two ways to install `monkey` from source, depending upon the version of go you're using:
Due to the embedded [standard-library implementation](data/stdlib.mon), which is implemented in monkey, you'll need to compile this project with go version 1.16beta1 or higher.

### Source Installation go <= 1.11

If you're using `go` before 1.11 then the following command should fetch/update `monkey`, and install it upon your system:

$ go get -u github.com/skx/monkey

### Source installation go >= 1.12

If you're using a more recent version of `go` (which is _highly_ recommended), you need to clone to a directory which is not present upon your `GOPATH`:
You can install from source like so:

git clone https://github.com/skx/monkey
cd monkey
Expand Down Expand Up @@ -303,21 +293,13 @@ You can see the implementation of the go-based standard-library beneath [evaluat

**NOTE**: Parts of our standard-library are implemented in 100% pure monkey,
and these are embedded in our compiled interpreter. The source of the functions
can be viewed in [data/stdlib.mon](data/stdlib.mon), but to ease compilation
these are included in the compiled interpreter via [static.go](static.go).
can be viewed in [data/stdlib.mon](data/stdlib.mon).

If you wish to make changes to the monkey-based standard-library you'll
need to rebuild `static.go` after editing `stdlib.mon`. To do this use the
`implant` tool.

If you don't already have `implant` installed fetch it like so:

go get -u github.com/skx/implant/
need to rebuild the interpreter after making your changes, to ensure they are bundled into the executable.

Now regenerate the embedded version of the standard-library and rebuild the
binary to make your changes:
Nothing special is required, the following will suffice as you'd expect:

implant -input data/ -output static.go
go build .


Expand Down
17 changes: 4 additions & 13 deletions data/stdlib.mon
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@
//
// i.e. This is part of our standard-library.
//
// If you wish to make changes to the standard-library functions defined
// here you'll need to rebuild `static.go` after editing this file, as
// that contains the embedded copy of this code which is included in
// the generated monkey-interpreter.
// If you wish to make changes to the standard-library functions in this
// file you'll need to rebuild the interpreter after making your changes.
//
// To rebuild `static.go` use the `implant` tool.
// This file it is embedded in the generated-binary as part of the build
// process.
//
// If you don't already have `implant` installed fetch it like so:
//
// go get -u github.com/skx/implant/
//
// Now regenerate the embedded version of this file and rebuild the
// interpreter with your changes:
//
// implant -input data/ -output static.go
// go build .
//

Expand Down
4 changes: 2 additions & 2 deletions evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ func evalSwitchStatement(se *ast.SwitchExpression, env *object.Environment) obje
(obj.Inspect() == out.Inspect()) {

// Evaluate the block and return the value
out = evalBlockStatement(opt.Block, env)
return out
blockOut := evalBlockStatement(opt.Block, env)
return blockOut
}

// Is it a regexp-match?
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/skx/monkey

go 1.12
go 1.16
22 changes: 6 additions & 16 deletions monkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package main

import (
_ "embed"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -20,9 +21,12 @@ import (
"github.com/skx/monkey/parser"
)

// This version-string will be updated via travis for generated binaries.
// This version-string will be updated via CI system for generated binaries.
var version = "master/unreleased"

//go:embed data/stdlib.mon
var stdlib string

//
// Implemention of "version()" function.
//
Expand Down Expand Up @@ -72,24 +76,10 @@ func Execute(input string) int {
return (argsFun(args...))
})

//
// Our standard-library is mostly written in C,
// and can be found implemented in evaluator/stdlib*.go
//
// However there is also data/stdlib.mon, and here we
// load that
//
tmpl, err := getResource("data/stdlib.mon")
if err != nil {
fmt.Printf("Failed to load our standard-library: %s",
err.Error())
os.Exit(33)
}

//
// Parse and evaluate our standard-library.
//
initL := lexer.New(string(tmpl))
initL := lexer.New(stdlib)
initP := parser.New(initL)
initProg := initP.ParseProgram()
evaluator.Eval(initProg, env)
Expand Down
1 change: 0 additions & 1 deletion object/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (e *Environment) Set(name string, val Object) Object {
if e.outer != nil {
return e.outer.Set(name, val)
}

fmt.Printf("scoping weirdness; please report a bug\n")
os.Exit(5)
}
Expand Down
91 changes: 0 additions & 91 deletions static.go

This file was deleted.