Skip to content

Commit

Permalink
Merge pull request #500 from nevalang/float_const_with_inst_lit
Browse files Browse the repository at this point in the history
fix(compiler): analyzer pass float const with int lit and desugarer r…
  • Loading branch information
emil14 authored Mar 7, 2024
2 parents 8aeaddf + 3921fd0 commit ef46bd0
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ jobs:
go-version: '1.21'
- name: build
run: go build -v ./...
- name: install
run: go install ./cmd/neva/main.go
- name: test
run: go test -v ./...
38 changes: 19 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["get", "github.com/nevalang/x"]
},
Expand All @@ -18,7 +18,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "0_do_nothing"]
},
Expand All @@ -27,7 +27,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "1_echo"]
},
Expand All @@ -36,7 +36,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "2_hello_world/0_verbose"]
},
Expand All @@ -45,7 +45,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "2_hello_world/1_with_const_sender"]
},
Expand All @@ -54,7 +54,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "-debug", "2_hello_world/2_with_then_connection"]
},
Expand All @@ -63,7 +63,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "2_hello_world/3_with_literal_sender"]
},
Expand All @@ -72,7 +72,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "2_hello_world/4_with_unnamed_node"]
},
Expand All @@ -81,7 +81,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "3_interfaces"]
},
Expand All @@ -90,7 +90,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "-debug", "4_add_numbers/verbose"]
},
Expand All @@ -99,7 +99,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "-debug", "4_add_numbers/with_bridge"]
},
Expand All @@ -108,7 +108,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "5_add_real_numbers/naive"]
},
Expand All @@ -117,7 +117,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "5_add_real_numbers/with_err_handling"]
},
Expand All @@ -126,7 +126,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "5_add_real_numbers/with_sub_components"]
},
Expand All @@ -135,7 +135,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "6_struct_builder/verbose"]
},
Expand All @@ -144,7 +144,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "6_struct_builder/with_sugar"]
},
Expand All @@ -153,7 +153,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "7_struct_selector/verbose"]
},
Expand All @@ -162,7 +162,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "7_struct_selector/verbose"]
},
Expand All @@ -171,7 +171,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cli",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "8_enums"]
},
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# build neva cli for host OS and put to the PATH
.PHONY: install
install:
@go build -ldflags="-s -w" ./cmd/cli && \
@go build -ldflags="-s -w" ./cmd/neva && \
rm -rf /usr/local/bin/neva && \
mv cli /usr/local/bin/neva
mv neva /usr/local/bin/neva

# generate go parser from antlr grammar
.PHONY: antlr
Expand Down Expand Up @@ -33,30 +33,30 @@ build:
# build neva cli for amd64 mac
.PHONY: build-darwin-amd64
build-darwin-amd64:
@GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o neva-darwin-amd64 ./cmd/cli
@GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o neva-darwin-amd64 ./cmd/neva

# build neva cli for arm64 mac
.PHONY: build-darwin-arm64
build-darwin-arm64:
@GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o neva-darwin-arm64 ./cmd/cli
@GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o neva-darwin-arm64 ./cmd/neva

# build neva cli for amd64 linux
.PHONY: build-linux-amd64
build-linux-amd64:
@GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o neva-linux-amd64 ./cmd/cli
@GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o neva-linux-amd64 ./cmd/neva

# build neva cli for arm64 linux
.PHONY: build-linux-arm64
build-linux-arm64:
@GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o neva-linux-arm64 ./cmd/cli
@GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o neva-linux-arm64 ./cmd/neva

# build neva cli for amd64 windows
.PHONY: build-windows-amd64
build-windows-amd64:
@GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o neva-windows-amd64.exe ./cmd/cli
@GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o neva-windows-amd64.exe ./cmd/neva

# build neva cli for arm64 windows
.PHONY: build-windows-arm64
build-windows-arm64:
@GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" -o neva-windows-arm64.exe ./cmd/cli
@GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" -o neva-windows-arm64.exe ./cmd/neva

File renamed without changes.
5 changes: 5 additions & 0 deletions e2e/mod/float_const_with_int_lit/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const x float = 1000

component Main(start) (stop) {
net { :start -> :stop }
}
1 change: 1 addition & 0 deletions e2e/mod/neva.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neva: 0.10.0
51 changes: 51 additions & 0 deletions e2e/run_examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//go:build e2e
// +build e2e

package test

// in this file we only check that code in examples folder works as expected.

import (
"os"
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestDoNothing(t *testing.T) {
err := os.Chdir("../examples")
require.NoError(t, err)

cmd := exec.Command("neva", "run", "0_do_nothing")

out, err := cmd.CombinedOutput()
require.NoError(t, err)
require.Equal(
t,
0,
len(strings.TrimSpace(string(out))),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}

func TestEcho(t *testing.T) {
err := os.Chdir("../examples")
require.NoError(t, err)

cmd := exec.Command("neva", "run", "1_echo")

cmd.Stdin = strings.NewReader("yo\n")
out, err := cmd.CombinedOutput()
require.NoError(t, err)

require.Equal(
t,
"yo",
strings.TrimSpace(string(out)),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
33 changes: 33 additions & 0 deletions e2e/run_tests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build e2e
// +build e2e

package test

// in this file we test files designed specifically for e2e.

import (
"os"
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

// There is special case where constant has float type but integer literal.
func TestFloatConstWithIntLit(t *testing.T) {
err := os.Chdir("./mod")
require.NoError(t, err)

cmd := exec.Command("neva", "run", "float_const_with_int_lit")

out, err := cmd.CombinedOutput()
require.NoError(t, err)
require.Equal(
t,
0,
len(strings.TrimSpace(string(out))),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
2 changes: 1 addition & 1 deletion examples/0_do_nothing/main.neva
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
component Main(start any) (stop any) {
component Main(start) (stop) {
net { :start -> :stop }
}
2 changes: 1 addition & 1 deletion examples/neva.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neva: 0.6.0
neva: 0.10.0
deps:
github.com/nevalang/x:
path: github.com/nevalang/x
Expand Down
Loading

0 comments on commit ef46bd0

Please sign in to comment.