Skip to content

Commit

Permalink
minor cleanup, new go version
Browse files Browse the repository at this point in the history
  • Loading branch information
boynton committed Feb 6, 2023
1 parent b02ddfd commit b2ce5b4
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
.goreleaser.yml

ell.prof
.DS_Store
4 changes: 2 additions & 2 deletions blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

package ell

import(
import (
"fmt"

. "github.com/boynton/ell/data"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/ell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
13 changes: 0 additions & 13 deletions code.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func (code1 *Code) Equals(another Value) bool {
return false
}


func (code *Code) signature() string {
//
//experimental: external annotations on the functions: *declarations* is a map from symbol to string
Expand Down Expand Up @@ -251,19 +250,7 @@ func (code *Code) loadOps(lst *List) error {
var defaults []Value
var keys []Value
var err error
/* if IsSymbol(funcParams) {
//legacy form, just the argc
argc, err = AsIntValue(funcParams)
if err != nil {
return err
}
if argc < 0 {
argc = -argc - 1
defaults = make([]*Object, 0)
}
} else */
if lst, ok := funcParams.(*List); ok && lst.Length() == 4 {
// if IsList(funcParams) && ListLength(funcParams) == 4 {
a := lst.Car
lst = lst.Cdr
name, err = AsStringValue(a)
Expand Down
4 changes: 2 additions & 2 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ limitations under the License.

package ell

import(
"fmt"
import (
"fmt"
. "github.com/boynton/ell/data"
)

Expand Down
26 changes: 12 additions & 14 deletions ell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -17,21 +17,23 @@ package ell

import (
"testing"

. "github.com/boynton/ell/data"
)

func testType(t *testing.T, name string, sym *Object) {
func testType(t *testing.T, name string, sym Value) {
if sym != Intern(name) {
t.Error("type is not ", name, ":", sym)
}
}

func testIdentical(t *testing.T, o1 *Object, o2 *Object) {
func testIdentical(t *testing.T, o1 Value, o2 Value) {
if o1 != o2 {
t.Error("objects should be identical but are not:", o1, "and", o2)
}
}

func testNotIdentical(t *testing.T, o1 *Object, o2 *Object) {
func testNotIdentical(t *testing.T, o1 Value, o2 Value) {
if o1 == o2 {
t.Error("objects should not be identical but are:", o1, "and", o2)
}
Expand All @@ -41,7 +43,7 @@ func TestNull(t *testing.T) {
n1 := Null
testIdentical(t, n1, Null)
testNotIdentical(t, Null, nil)
testType(t, "<null>", Null.Type)
testType(t, "<null>", Null.Type())
if n1 != Null {
t.Error("nil isn't Null")
}
Expand All @@ -50,16 +52,12 @@ func TestNull(t *testing.T) {
func TestBooleans(t *testing.T) {
b1 := True
b2 := False
testType(t, "<boolean>", True.Type)
testType(t, "<boolean>", False.Type)
testIdentical(t, True.Type, False.Type)
testType(t, "<boolean>", True.Type())
testType(t, "<boolean>", False.Type())
testIdentical(t, True.Type(), False.Type())
testIdentical(t, b1, True)
testIdentical(t, b2, False)
testNotIdentical(t, b1, b2)
if !IsBoolean(b1) {
t.Error("boolean value isn't:", b1)
}
if !IsBoolean(b2) {
t.Error("boolean value isn't:", b2)
}
testType(t, "<boolean>", b1.Type())
testType(t, "<boolean>", b2.Type())
}
2 changes: 1 addition & 1 deletion generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

package ell

import(
import (
. "github.com/boynton/ell/data"
)

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/boynton/ell

go 1.16
go 1.19

require (
github.com/boynton/cli v0.0.0-20170122194616-c91dc790ccff
github.com/boynton/repl v0.0.0-20170116235056-348863958e3e
github.com/pborman/uuid v1.2.0
)

require github.com/google/uuid v1.0.0 // indirect
8 changes: 7 additions & 1 deletion lib/bench.ell
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
;; `time ell --optimize bench`
;;
;; Apple M1 (go1.16 darwin/arm64, ell v2) 2.62s
;; Apple M1 Max (go1.19.2, darwin/arm64) 2.85s
;; Apple M1 Max (go1.17.2, darwin/arm64) 3.04s
;; Apple M1 (go1.17.2, darwin/arm64) 3.07s
;; Apple M1 (go1.16 darwin/arm64) 3.31s
;; Apple M1 (go1.16 linux/aarch64, docker) 3.92s
;; Apple M1 (go1.16 darwin/amd64, rosetta 2) 5.78s
Expand All @@ -15,15 +18,18 @@
;; For reference, here are some comparable numbers for the same
;; benchmark in scheme-5.9:
;;
;; DrRacket Scheme (arm64, Apple M1 Max) 0.23
;; DrRacket Scheme (arm64, Apple M1) 0.28
;; Macmini9,1 (arm64, Apple M1) 0.97
;; MacBookPro16,1 (x86-64, i9-9900K) 0.97
;; MacbookPro18,4 (arm64, Apple M1 Max) 0.99
;; MacBookPro14,1 (x86-64, I7-7660U) 1.27
;; MacNookPro16,1 (x86-64, i9-9900k, rosetta2) 1.41
;; MacPro6,1 (x86-64, xeon e5-1650) 1.73
;; iMac11,1 (x86-64, i7-860) 1.90
;; MacBookPro9,1 (x86-64, I7-3720QM) 1.90
;; Macmini3,1 (x86-64, core2-duo P7350) 3.47
;;
;; Chicken Scheme (64, Apple M1) 3.91

(use sort)
(use pi)
Expand Down
6 changes: 4 additions & 2 deletions macro.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ func expandUndef(expr Value) (Value, error) {
}

// (defn f (x) (+ 1 x))
// ->
//
// ->
//
// (def f (fn (x) (+ 1 x)))
func expandDefn(expr Value) (Value, error) {
exprLen := ListLength(expr)
Expand Down Expand Up @@ -567,7 +569,7 @@ func expandQQList(lst *List) (*List, error) {
result := NewList(Intern("concat"))
tail := result
for lst != EmptyList {
if item, ok := Car(lst).(*List); ok && item != EmptyList{
if item, ok := Car(lst).(*List); ok && item != EmptyList {
if item.Car == QuasiquoteSymbol {
return nil, NewError(MacroErrorKey, "nested quasiquote not supported")
}
Expand Down
8 changes: 4 additions & 4 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func defMacro(sym Value, val *Function) {
macroMap[sym] = NewMacro(sym, val)
}

//note: unlike java, we cannot use maps or arrays as keys (they are not comparable).
//so, we will end up with duplicates, unless we do some deep compare, when putting map or array constants
// note: unlike java, we cannot use maps or arrays as keys (they are not comparable).
// so, we will end up with duplicates, unless we do some deep compare, when putting map or array constants
func putConstant(val Value) int {
idx, present := constantsMap[val]
if !present {
Expand Down Expand Up @@ -328,7 +328,7 @@ func compileValue(expr Value) (string, error) {
return thunk.decompile(true) + "\n", nil
}

//caveats: when you compile a file, you actually run it. This is so we can handle imports and macros correctly.
// caveats: when you compile a file, you actually run it. This is so we can handle imports and macros correctly.
func CompileFile(name string) (Value, error) {
file, err := FindModuleFile(name)
if err != nil {
Expand Down Expand Up @@ -432,7 +432,7 @@ func Main(extns ...Extension) {
os.Exit(1)
}
interactive := len(args) == 0
SetFlags(optimize, verbose, debug, trace, interactive)
SetFlags(optimize, verbose, debug, trace, interactive)
Init(extns...)
if path != "" {
for _, p := range strings.Split(path, ":") {
Expand Down
14 changes: 7 additions & 7 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ var ConnectionType = Intern("<connection>")

type Connection struct {
Name string
In *Channel
Out *Channel
Con net.Conn
In *Channel
Out *Channel
Con net.Conn
}

func (c *Connection) Type() Value {
Expand All @@ -232,9 +232,9 @@ func NewConnection(con net.Conn, endpoint string) Value {
name := fmt.Sprintf("connection on %s", endpoint)
return &Connection{
Name: name,
In: inchan,
Out: outchan,
Con: con,
In: inchan,
Out: outchan,
Con: con,
}
}

Expand All @@ -244,7 +244,7 @@ func closeConnection(obj Value) {
CloseChannel(p.In)
CloseChannel(p.Out)
p.Con.Close()
p.Con = nil;
p.Con = nil
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"os"
"strconv"
"strings"

. "github.com/boynton/ell/data"
)

Expand Down Expand Up @@ -103,7 +103,7 @@ func SpitFile(path string, data string) error {

func ReadFromString(s string) (Value, error) {
reader := &Reader{
Input: bufio.NewReader(strings.NewReader(s)),
Input: bufio.NewReader(strings.NewReader(s)),
Position: 0,
}
reader.Extension = &EllReaderExtension{r: reader}
Expand All @@ -112,7 +112,7 @@ func ReadFromString(s string) (Value, error) {

func ReadAllFromString(s string) (*List, error) {
reader := &Reader{
Input: bufio.NewReader(strings.NewReader(s)),
Input: bufio.NewReader(strings.NewReader(s)),
Position: 0,
}
reader.Extension = &EllReaderExtension{r: reader}
Expand Down
1 change: 0 additions & 1 deletion number.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,3 @@ func Float64Value(obj Value) float64 {
}
return 0
}

20 changes: 10 additions & 10 deletions primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,14 @@ func numeq(n1 Value, n2 Value) bool {
func numericPair(argv []Value) (float64, float64, error) {
return (argv[0].(*Number)).Value, (argv[1].(*Number)).Value, nil
/* f1, err := AsFloat64Value(argv[0])
if err != nil {
return 0, 0, err
}
f2, err := AsFloat64Value(argv[1])
if err != nil {
return 0, 0, err
}
return f1, f2, nil
if err != nil {
return 0, 0, err
}
f2, err := AsFloat64Value(argv[1])
if err != nil {
return 0, 0, err
}
return f1, f2, nil
*/
}

Expand Down Expand Up @@ -980,8 +980,8 @@ func ellSend(argv []Value) (Value, error) {
ch := ChannelValue(argv[0])
if ch != nil { //not closed
val := argv[1]
timeout := Float64Value(argv[2]) //FIX: timeouts in seconds, floating point
if NumberEqual(timeout, 0.0) { //non-blocking
timeout := Float64Value(argv[2]) //FIX: timeouts in seconds, floating point
if NumberEqual(timeout, 0.0) { //non-blocking
select {
case ch <- val:
return True, nil
Expand Down
2 changes: 1 addition & 1 deletion repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"sort"
"strings"

"github.com/boynton/repl"
. "github.com/boynton/ell/data"
"github.com/boynton/repl"
)

type ellHandler struct {
Expand Down
Loading

0 comments on commit b2ce5b4

Please sign in to comment.