wa

command module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

README

The Wa Programming Language

Build Status Go Report Card Coverage Status GitHub release Go Reference license

Wa is a general-purpose programming language designed for developing robustness and maintainability WebAssembly software. Instead of requiring complex toolchains to set up, you can simply go install it - or run it in a browser.

Note: Our canonical Git repository is located at https://gitee.com/wa-lang/wa. There is a mirror of the repository at https://github.com/wa-lang/wa. Unless otherwise noted, the Wa source files are distributed under the AGPL-v3 license found in the LICENSE file.

Playground

https://wa-lang.org/playground

Snake Game

Install and Run:

  1. go install wa-lang.org/wa@latest
  2. wa init -name=_examples/hi
  3. wa run _examples/hi

The Wa project is still in very early stage. If you want to submit PR, please read the Contribution Guide(Chinese). We do not accept PR only about 3rdparty changes.

Example: Print Wa

Print rune and call function:

# Copyright @2019-2022 The Wa author. All rights reserved.

import "fmt"

fn main {
	println("hello, Wa!")
	println(add(40, 2))

	fmt.Println(1+1)
}

fn add(a: i32, b: i32) => i32 {
	return a+b
}

Execute the program:

$ go run main.go hello.wa 
hello, Wa!
42
2

Example: Print Prime

Print prime numbers up to 30:

fn main {
	for n := 2; n <= 30; n = n + 1 {
		var isPrime int = 1
		for i := 2; i*i <= n; i = i + 1 {
			if x := n % i; x == 0 {
				isPrime = 0
			}
		}
		if isPrime != 0 {
			println(n)
		}
	}
}

Execute the program:

$ go run main.go run _examples/prime
2
3
5
7
11
13
17
19
23
29

More examples _examples

Execut as a script

The Wa language itself can also be executed like the Lua language embedded in the Go host locale:

package main

import (
	"fmt"
	"wa-lang.org/wa/api"
)

func main() {
	output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code)
	fmt.Print(string(output), err)
}

Note: Executing as a script currently only supports native environments.

Documentation

Overview

凹语言,The Wa Programming Language.

Directories

Path Synopsis
凹语言™ 功能 API 包。
凹语言™ 功能 API 包。
internal
3rdparty/cli
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
app
ast
Package ast declares the types used to represent syntax trees for Go packages.
Package ast declares the types used to represent syntax trees for Go packages.
ast/astutil
Package astutil contains common utilities for working with the Go AST.
Package astutil contains common utilities for working with the Go AST.
ast/inspector
Package inspector provides helper functions for traversal over the syntax trees of a package, including node filtering by type, and materialization of the traversal stack.
Package inspector provides helper functions for traversal over the syntax trees of a package, including node filtering by type, and materialization of the traversal stack.
backends/compiler_c/cir/ctypes
ctypes包定义C-IR的类型
ctypes包定义C-IR的类型
backends/compiler_wat/wir/wat
WAT 文本格式的模块。
WAT 文本格式的模块。
constant
Package constant implements Values representing untyped Go constants and their corresponding operations.
Package constant implements Values representing untyped Go constants and their corresponding operations.
format
Package format implements standard formatting of Go source.
Package format implements standard formatting of Go source.
frontend/wz/parser
Package parser implements a parser for Go source files.
Package parser implements a parser for Go source files.
frontend/wz/scanner
Package scanner implements a scanner for Go source text.
Package scanner implements a scanner for Go source text.
frontend/wz/token
Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
parser
Package parser implements a parser for Go source files.
Package parser implements a parser for Go source files.
printer
Package printer implements printing of AST nodes.
Package printer implements printing of AST nodes.
scanner
Package scanner implements a scanner for Go source text.
Package scanner implements a scanner for Go source text.
ssa
Package ssa defines a representation of the elements of Go programs (packages, types, functions, variables and constants) using a static single-assignment (SSA) form intermediate representation (IR) for the bodies of functions.
Package ssa defines a representation of the elements of Go programs (packages, types, functions, variables and constants) using a static single-assignment (SSA) form intermediate representation (IR) for the bodies of functions.
token
Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
types
Package types declares the data types and implements the algorithms for type-checking of Go packages.
Package types declares the data types and implements the algorithms for type-checking of Go packages.
types/objectpath
Package objectpath defines a naming scheme for types.Objects (that is, named entities in Go programs) relative to their enclosing package.
Package objectpath defines a naming scheme for types.Objects (that is, named entities in Go programs) relative to their enclosing package.
types/typeutil
Package typeutil defines various utilities for types, such as Map, a mapping from types.Type to interface{} values.
Package typeutil defines various utilities for types, such as Map, a mapping from types.Type to interface{} values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL