Skip to content
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
40 changes: 26 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
branches: [ main, dev ]
paths-ignore:
- "**.md"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -34,24 +35,26 @@ jobs:
- name: Verify dependencies
run: go mod verify

- uses: golangci/golangci-lint-action@v9
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
args: --timeout=5m

build:
name: Build and test (${{ matrix.os }})
needs: lint
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

env:
BIN_NAME: ${{ runner.os == 'Windows' && 'azc.exe' || 'azc' }}
include:
- os: ubuntu-latest
bin: azc
- os: macos-latest
bin: azc
- os: windows-latest
bin: azc.exe

defaults:
run:
Expand All @@ -66,24 +69,33 @@ jobs:
cache: true
cache-dependency-path: go.sum

- name: Setup MSVC
- name: Install modern GCC (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq software-properties-common
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get install -y -qq gcc-14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100

- name: Setup MSVC (Windows)
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1

- name: Download dependencies
run: go mod download

- name: Build binary
run: go build -v -o "$BIN_NAME" ./cmd/azc
run: go build -v -o "${{ matrix.bin }}" ./cmd/azc

- name: Run tests
env:
AZC: ${{ github.workspace }}/${{ env.BIN_NAME }}
run: go test -v -race -count=1 -cover ./...
AZC: ${{ github.workspace }}/${{ matrix.bin }}
run: go test -v -count=1 -cover ./...

- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: azc-${{ runner.os }}
path: ${{ env.BIN_NAME }}
retention-days: 7
name: azc-${{ matrix.os }}
path: ${{ matrix.bin }}
retention-days: 7
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Deploy API Docs

on:
push:
branches: [ dev ]
branches: [ main, dev ]
pull_request:
branches: [ dev ]
branches: [ main, dev ]
workflow_dispatch:

concurrency:
Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ linters:

# Quality
- copyloopvar
- exhaustive
- gocheckcompilerdirectives
- goconst
- gocritic
- intrange
- iotamixing
- makezero
- mirror
- misspell
- modernize
- nolintlint
- prealloc
- predeclared
- recvcheck
Expand Down
47 changes: 23 additions & 24 deletions internal/codegen/c/analysis/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ var Builtins = map[string]Builtin{
"getchar": {Stdio},
"putchar": {Stdio},

"malloc": {Stdlib},
"calloc": {Stdlib},
"realloc": {Stdlib},
"free": {Stdlib},
"exit": {Stdlib},
"abs" : {Stdlib},
"atoi" : {Stdlib},
"atof" : {Stdlib},
"atol" : {Stdlib},
"atoll" : {Stdlib},
"strtol": {Stdlib},
"strtoll": {Stdlib},
"strtoul": {Stdlib},
"strtoull":{Stdlib},
"strtod": {Stdlib},
"strtof": {Stdlib},
"malloc": {Stdlib},
"calloc": {Stdlib},
"realloc": {Stdlib},
"free": {Stdlib},
"exit": {Stdlib},
"abs": {Stdlib},
"atoi": {Stdlib},
"atof": {Stdlib},
"atol": {Stdlib},
"atoll": {Stdlib},
"strtol": {Stdlib},
"strtoll": {Stdlib},
"strtoul": {Stdlib},
"strtoull": {Stdlib},
"strtod": {Stdlib},
"strtof": {Stdlib},

"strlen": {String},
"strcpy": {String},
Expand All @@ -64,14 +64,13 @@ var Builtins = map[string]Builtin{
"memmove": {String},
"memcmp": {String},

"sqrt": {Math},
"pow": {Math},
"sin": {Math},
"cos": {Math},
"floor": {Math},
"ceil": {Math},
"fabs": {Math},

"sqrt": {Math},
"pow": {Math},
"sin": {Math},
"cos": {Math},
"floor": {Math},
"ceil": {Math},
"fabs": {Math},
}

func LookupBuiltin(name string) (Builtin, bool) {
Expand Down
6 changes: 3 additions & 3 deletions internal/codegen/c/analysis/builtins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestLookupBuiltin(t *testing.T) {

for _, tt := range tests {
result, ok := LookupBuiltin(tt.name)
if (result.Include != tt.exceptedValue || ok != tt.exceptedOk) {
t.Errorf("LookupBuiltin(%q) = (%q, %v); want (%q, %v)",
tt.name, result, ok, tt.exceptedValue, tt.exceptedOk)
if result.Include != tt.exceptedValue || ok != tt.exceptedOk {
t.Errorf("LookupBuiltin(%q) = (%q, %v); want (%q, %v)",
tt.name, result, ok, tt.exceptedValue, tt.exceptedOk)
}
}
}
1 change: 1 addition & 0 deletions internal/codegen/c/analysis/visit_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import "github.com/azin-lang/Azin/internal/ast"

func (a *Analyzer) visitVar(fn string, stmt *ast.VarStmt) {
a.registerVariable(fn, stmt.Name.Value)
a.visitExpr(fn, stmt.Value)
}
6 changes: 0 additions & 6 deletions internal/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ func (s *Scope) Invalidate(name string) {
}

func (s *Scope) ClearAll() {
// Wipe this scope's known values and stores (e.g. for Loops)
s.values = make(map[string]ast.Expr)
s.lastStore = make(map[string]ast.Stmt)

// Recursively wipe parent scopes
if s.parent != nil {
s.parent.ClearAll()
}
}
12 changes: 11 additions & 1 deletion internal/sema/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func mangleFunctionName(fn *ast.FuncStmt) string {
var name strings.Builder
name.WriteString(fn.Name.Value)
for _, param := range fn.Params {
name.WriteString("__" + param.SynType.Value)
if param.SynType != nil {
name.WriteString("__" + param.SynType.Value)
}
}

return name.String()
Expand Down Expand Up @@ -351,6 +353,9 @@ func (a *Analyzer) registerTopLevelSymbols(program *ast.Program) {
})

for _, param := range n.Params {
if param.SynType == nil {
continue
}
paramType := a.lookupType(param.SynType.Value)
if paramType == nil {
a.errorf(param.SynType, "unknown parameter type: %s", param.SynType.Value)
Expand Down Expand Up @@ -635,6 +640,11 @@ func (a *Analyzer) visitStatement(stmt ast.Stmt) {
return
}

if sym := a.lookup(objectType.Name); sym != nil && sym.Kind == SymbolEnum {
a.errorf(n.Value, "'%s' is an enum and cannot be assigned to", objectType.Name)
return
}

strct := a.lookupStruct(objectType.Name)
if strct == nil {
a.errorf(n.Value, "'%s' is not a struct", objectType.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/source/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func New(name string, text []byte) *File {

for i, ch := range text {
if ch == '\n' {
lines = append(lines, uint32(i+1))
lines = append(lines, uint32(i+1)) //nolint:gosec
}
}

Expand Down
Loading