Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wa Language #7180

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,9 @@
[submodule "vendor/grammars/vscode_mikrotik_routeros_script"]
path = vendor/grammars/vscode_mikrotik_routeros_script
url = https://github.com/devMikeUA/vscode_mikrotik_routeros_script.git
[submodule "vendor/grammars/wa-tmLanguage"]
path = vendor/grammars/wa-tmLanguage
url = https://github.com/wa-lang/wa-tmLanguage.git
[submodule "vendor/grammars/wgsl-analyzer"]
path = vendor/grammars/wgsl-analyzer
url = https://github.com/wgsl-analyzer/wgsl-analyzer.git
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,8 @@ vendor/grammars/vscode_cobol:
- source.utreport
vendor/grammars/vscode_mikrotik_routeros_script:
- source.rsc
vendor/grammars/wa-tmLanguage:
- source.wa
vendor/grammars/wgsl-analyzer:
- source.wgsl
vendor/grammars/witcherscript-grammar:
Expand Down
11 changes: 11 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8722,3 +8722,14 @@ xBase:
tm_scope: source.harbour
ace_mode: text
language_id: 421
Wa:
type: programming
color: "#20b2aa"
extensions:
- ".wa"
aliases:
- wa-lang
- 凹语言
tm_scope: source.wa
ace_mode: text
language_id: 600611382
58 changes: 58 additions & 0 deletions samples/Wa/brainfuck.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 版权 @2019 凹语言 作者。保留所有权利。

func main {
// print hi
const code = "++++++++++[>++++++++++<-]>++++.+."
vm := NewBrainFuck(code)
vm.Run()
}

type BrainFuck struct {
mem :[30000]byte
code :string
pos :int
pc :int
}

func NewBrainFuck(code: string) => *BrainFuck {
return &BrainFuck{code: code}
}

func BrainFuck.Run {
for ; this.pc != len(this.code); this.pc++ {
switch x := this.code[this.pc]; x {
case '>':
this.pos++
case '<':
this.pos--
case '+':
this.mem[this.pos]++
case '-':
this.mem[this.pos]--
case '[':
if this.mem[this.pos] == 0 {
this.loop(1)
}
case ']':
if this.mem[this.pos] != 0 {
this.loop(-1)
}
case '.':
print(rune(this.mem[this.pos]))
case ',':
// TODO: support read byte
}
}
return
}

func BrainFuck.loop(inc: int) {
for i := inc; i != 0; this.pc += inc {
switch this.code[this.pc+inc] {
case '[':
i++
case ']':
i--
}
}
}
42 changes: 42 additions & 0 deletions samples/Wa/closure.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 版权 @2019 凹语言 作者。保留所有权利。

type FP func(i: i32) => i32

type ST struct {
i :i32
}

func ST.meth(p: i32) => i32 {
this.i += p
return this.i
}

global g_f: FP

func main {
o: ST
o.i = 11
g_f = o.meth
println(g_f(11)) // 22
println(o.i) // 22

n := i32(21)
g_f = func(i: i32) => i32 {
n += i
return n
}
println(g_f(22)) // 43
println(n) // 43

func(i: i32) {
n += i
}(22)
println(n) // 65

g_f = Double
println(g_f(13)) // 26
}

func Double(i: i32) => i32 {
return i * 2
}
9 changes: 9 additions & 0 deletions samples/Wa/complex.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 版权 @2024 凹语言 作者。保留所有权利。

func main {
x: complex128 = complex(1, 2) // 1+2i
y: complex128 = complex(3, 4) // 3+4i
println(x*y) // "(-5+10i)"
println(real(x*y)) // "-5"
println(imag(x*y)) // "10"
}
19 changes: 19 additions & 0 deletions samples/Wa/count.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 版权 @2019 凹语言 作者。保留所有权利。

func main {
print("30以内的质数:")
for n := 2; n <= 30; n = n + 1 {
isPrime: int = 1
for i := 2; i*i <= n; i = i + 1 {
if x := n % i; x == 0 {
isPrime = 0
}
}
if isPrime != 0 {
print(n)
if n != 29 {
print("、")
}
}
}
}
15 changes: 15 additions & 0 deletions samples/Wa/defer.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 版权 @2024 凹语言 作者。保留所有权利。

func main {
defer println("a1")
defer println("a2")
println("a3")

for i := 0; i < 3; i++ {
defer println("i.v0:", i)
}

for i := 0; i < 3; i++ {
defer func { println("i.v1:", i) } ()
}
}
16 changes: 16 additions & 0 deletions samples/Wa/heart.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 版权 @2019 凹语言 作者。保留所有权利。

func main {
a := 0.0
for y := 1.5; y > -1.5; y = y - 0.15 {
for x := -1.5; x < 1.5; x = x + 0.07 {
a = x*x + y*y - 1.0
if a*a*a < x*x*y*y*y {
print("@")
} else {
print(" ")
}
}
println()
}
}
17 changes: 17 additions & 0 deletions samples/Wa/hello-p5.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 版权 @2024 P5-hello 作者。保留所有权利。

import "js/p5"

func init {
p5.CreateCanvas(400)
p5.Background(220)
p5.Stroke(p5.RED)
}

func Draw {
if p5.MouseIsPressed {
p5.Line(p5.MouseX, p5.MouseY, p5.PMouseX, p5.PMouseY)
} else {
p5.Point(p5.MouseX, p5.MouseY)
}
}
15 changes: 15 additions & 0 deletions samples/Wa/hello.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 版权 @2019 凹语言 作者。保留所有权利。

import "fmt"
import "runtime"

func main {
println("你好,凹语言!", runtime.WAOS)
println(add(40, 2))

fmt.Println(1+1)
}

func add(a: i32, b: i32) => i32 {
return a+b
}
32 changes: 32 additions & 0 deletions samples/Wa/iface.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 版权 @2021 凹语言 作者。保留所有权利。

type S1 struct {
a: i32
}

type S2 struct {
a: i32
}

type i1 interface {
f()
}

func S1.f {
println("This is S1, this.a==", this.a)
}

func S2.f {
println("This is S2, this.a==", this.a)
}

func main {
v1 := S1{a: 13}
v2 := S2{a: 42}

i: i1 = &v1
i.f()

i = &v2
i.f()
}
12 changes: 12 additions & 0 deletions samples/Wa/map.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 版权 @2024 凹语言 作者。保留所有权利。

func main {
m := make(map[string]int)
m["a"] = 13
m["b"] = 42
m["c"] = 29

for k, v := range m {
println(k, v)
}
}
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Vyper:** [davidhq/SublimeEthereum](https://github.com/davidhq/SublimeEthereum)
- **WDL:** [stjude-rust-labs/sprocket-vscode](https://github.com/stjude-rust-labs/sprocket-vscode)
- **WGSL:** [wgsl-analyzer/wgsl-analyzer](https://github.com/wgsl-analyzer/wgsl-analyzer)
- **Wa:** [wa-lang/wa-tmLanguage](https://github.com/wa-lang/wa-tmLanguage)
- **Wavefront Material:** [Alhadis/language-wavefront](https://github.com/Alhadis/language-wavefront)
- **Wavefront Object:** [Alhadis/language-wavefront](https://github.com/Alhadis/language-wavefront)
- **Web Ontology Language:** [textmate/xml.tmbundle](https://github.com/textmate/xml.tmbundle)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/wa-tmLanguage
Submodule wa-tmLanguage added at bf5c4f
Loading