Skip to content

Commit

Permalink
Add support for WASM build (#12)
Browse files Browse the repository at this point in the history
* Init wasm build support

* remove null

* Add logger that can be customized

Update print to fix flushing issue

* Use env logger to print parse errors

* Remove binary builds

* Publish examples in a release

* init console module

* Improve wasm console support

* Update README.md
  • Loading branch information
sevenreup authored Nov 21, 2024
1 parent 60c5aa6 commit f20a410
Show file tree
Hide file tree
Showing 23 changed files with 501 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22
go-version: 1.23

- name: Set up gotestfmt
uses: gotesttools/gotestfmt-action@v2
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ">=1.22.2"
go-version: ">=1.23.0"

- run: go mod tidy
- name: Go tidy
run: go mod tidy
# - name: Run tests
# run: go test ./...

- name: Zip examples directory
run: zip -r examples.zip examples/

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
Expand All @@ -31,3 +35,11 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload examples zip to release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: examples.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 14 additions & 14 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ before:
builds:
- id: build_archive_all
env: [CGO_ENABLED=0]
main: ./src
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- id: build_no_archive
env: [CGO_ENABLED=0]
main: ./src
main: ./src/cmd/duwa
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# - id: build_no_archive
# env: [CGO_ENABLED=0]
# main: ./src/cmd/duwa
# goos:
# - linux
# - windows
# - darwin
# goarch:
# - amd64
# - arm64

archives:
- id: archive_noncgo
builds: [build_archive_all]
format: zip
- id: binary_noncgo
builds: [build_no_archive]
format: binary
# - id: binary_noncgo
# builds: [build_no_archive]
# format: binary
17 changes: 15 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/src/main.go",
"program": "${workspaceRoot}\\src\\cmd\\duwa\\duwa.go",
"console": "integratedTerminal",
"cwd": "${workspaceRoot}",
"args": [
"-f",
"${workspaceRoot}\\examples\\games\\tictactoe.duwa"
]
},
{
"name": "Wasm",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/src/cmd/wasm/duwa.go",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"args": [
"-f",
"./examples/games/tictactoe.ny"
"${workspaceRoot}\\examples\\games\\tictactoe.duwa"
]
}
]
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Start with the official TinyGo development image
FROM tinygo/tinygo-dev:latest

# Install additional development tools
RUN apt-get update && apt-get install -y \
git \
make \
gcc \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install Go tools
RUN go install golang.org/x/tools/cmd/goimports@latest \
&& go install github.com/go-delve/delve/cmd/dlv@latest

# Set working directory
WORKDIR /app

# Add convenient aliases and environment variables
RUN echo 'alias tg="tinygo"' >> ~/.bashrc \
&& echo 'alias tgb="tinygo build"' >> ~/.bashrc \
&& echo 'alias tgr="tinygo run"' >> ~/.bashrc

# Set default command
CMD ["/bin/bash"]
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
build:
@go build -C src -o ../bin/duwa
@go build -C ./src/cmd/duwa -o ../../../bin/duwa

build-wasm:
set TEMP=U:\projects\skybox\duwa\chewa\temp
@GOOS=js GOARCH=wasm tinygo build -o ../duwa-site/public/duwa.wasm -opt 1 ./src/cmd/wasm/duwa.go

build-docker:
@docker-compose up -d
@docker-compose exec tinygo-dev tinygo build -o ./bin/duwa.wasm -target=wasm ./src/cmd/wasm/duwa.go
@docker-compose exec tinygo-dev cp /tinygo/targets/wasm_exec.js /app/bin/
@cp ./bin/duwa.wasm ../duwa-site/public/duwa.wasm
@cp ./bin/wasm_exec.js ../duwa-site/public/wasm_exec.js
@docker-compose stop

build-all: build build-wasm

dev:
@go run src/main.go
@go run ./src/cmd/duwa/duwa.go

run: build
@./bin/duwa
Expand Down
76 changes: 44 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
# Duwa Programming Language (in progress)
This project is an interpreter for the `duwa` language (Name still getting worked shopped), a language based on the Chewa Bantu language.
This project is written in Golang.

## Setup and Moni ku dziko
Download the prebuilt binaries for your platform from the [release](https://github.com/sevenreup/duwa/releases)

Create a new source file, `main.ny` (💀 for now the extension does not matter).

Paste the following cool code

```c#
lemba("Moni Dziko");
```
Run you new application
This project is an interpreter for the `duwa` language, a language based on the Chewa Bantu language.
This project is written in Golang.

```bash
duwa -f ./main.ny
```
## Setup and Zowerenga

## Zowerenga bwa?
Documentation is on its way, stay on the cutting edge and freestyle your code.
Follow the setup documentations at [official site](https://www.duwa.cphiri.dev)

You can check out examples in `./examples` folder to quickly see what the language can do for now.

## Main Milestones

- [ ] Create an initial interpreter
- [x] Lexer
- [x] Parser (Recursive descent parser)
- [x] Interpreter (Tree walking interpreter)
- [x] Lexer
- [x] Parser (Recursive descent parser)
- [x] Interpreter (Tree walking interpreter)
- [ ] Language features
- [x] Basic data types (string, numbers)
- [x] arithmetic operations
- [x] Control Flow (loops, conditional statements)
- [x] Functions
- [ ] Type checking (for now it does not strictly enforce types)
- [ ] Data Structures
- [x] arrays
- [x] dictionaries
- [ ] Input/ Output
- [ ] Error Handling
- [ ] Class support
- [x] Basic data types (string, numbers)
- [x] arithmetic operations
- [x] Control Flow (loops, conditional statements)
- [x] Functions
- [ ] Type checking (for now it does not strictly enforce types)
- [ ] Data Structures
- [x] arrays
- [x] dictionaries
- [ ] Input/ Output
- [ ] Error Handling
- [ ] Class support
- [ ] Working Wasm version of the language

Other Milestones

- [ ] Modularity
- [ ] Standard library

## Building

### Prerequisites

- TinyGo: If you are building the web assembly version you will need `TinyGo`, hers is the [setup](https://tinygo.org/getting-started/install)
- GNU make (optional): Using make for building. You can build the project without `make`.

### Builing/running

You can build the project by running any of the build make tasks

```bash
make build
```

Or you can run go build directly

```bash
go build -C ./src/cmd/duwa -o ../../../bin/duwa
```

Running the project is the same either use make or go directly
23 changes: 23 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.8"

services:
tinygo-dev:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/app
- go-cache:/home/dev/go
- go-mod-cache:/go/pkg/mod
environment:
- GOPATH=/go
- GOCACHE=/home/dev/go
- GOMODCACHE=/go/pkg/mod
ports:
- "2345:2345" # for delve debugger
tty: true
stdin_open: true

volumes:
go-cache:
go-mod-cache:
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/sevenreup/duwa

go 1.22.0
go 1.23.0

require github.com/shopspring/decimal v1.3.1
10 changes: 8 additions & 2 deletions src/main.go → src/cmd/duwa/duwa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package main
import (
"flag"
"log"
"log/slog"
"os"

"github.com/sevenreup/duwa/src/duwa"
"github.com/sevenreup/duwa/src/object"
"github.com/sevenreup/duwa/src/runtime/native"
)

var (
Expand All @@ -22,6 +26,8 @@ func main() {
log.Fatal("Please provide a file to run")
}

duwa := duwa.New(file)
duwa.Run()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
console := native.NewConsole()
duwa := duwa.New(object.New(logger, console))
duwa.RunFile(file)
}
Loading

0 comments on commit f20a410

Please sign in to comment.