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 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
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
66 changes: 66 additions & 0 deletions samples/Wa/brainfuck.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// BrainFuck VM
// https://github.com/chai2010/brainfuck-wa

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

func Run(code: string) => string {
vm := NewBrainFuck(code)
return string(vm.Run())
}

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

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

func BrainFuck.Run => []byte {
output := make([]byte, 0, 64)
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 '.':
output = append(output, this.mem[this.pos])
case ',':
// TODO: support read byte
}
}
return output
}

func BrainFuck.loop(inc: int) {
for i := inc; i != 0; this.pc += inc {
switch this.code[this.pc+inc] {
case '[':
i++
case ']':
i--
}
}
}
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 24bc75
Loading