api

package
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: 8 Imported by: 0

Documentation

Overview

凹语言™ 功能 API 包。

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	FlagDebugMode = &config.DebugMode

	FlagEnableTrace_api      = &config.EnableTrace_api
	FlagEnableTrace_app      = &config.EnableTrace_app
	FlagEnableTrace_compiler = &config.EnableTrace_compiler
	FlagEnableTrace_loader   = &config.EnableTrace_loader
)

调试参数

Functions

func BuildFile

func BuildFile(cfg *config.Config, filename string, src interface{}) (wat []byte, err error)

构建 wat 目标

func BuildVFS

func BuildVFS(cfg *config.Config, vfs *config.PkgVFS, appPkg string) (wat []byte, err error)

构建 wat 目标

func FormatCode

func FormatCode(filename, code string) (string, error)

格式化代码

Example
package main

import (
	"fmt"

	"wa-lang.org/wa/api"
)

func main() {
	s, err := api.FormatCode("hello.wa", "fn add(a:i32, b:i32)=>i32 {return a+b}")
	if err != nil {
		panic(err)
	}
	fmt.Println(s)

}
Output:

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

func RunCode

func RunCode(cfg *config.Config, filename, code string) (stdoutStderr []byte, err error)

执行凹代码

Example
package main

import (
	"fmt"
	"log"

	"wa-lang.org/wa/api"
)

func main() {
	const code = `
		var gBase: i32 = 1000

		fn main() {
			println(add(40, 2) + gBase)
		}

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

	output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Print(string(output))

}
Output:

1042

Types

type Config

type Config = config.Config

配置参数, 包含文件系统和 OS 等信息

func DefaultConfig

func DefaultConfig() *Config

默认配置

type Manifest

type Manifest = config.Manifest

模块元信息, 主包路径

func LoadManifest

func LoadManifest(vfs fs.FS, appPath string) (p *Manifest, err error)

加载 WaModFile 文件 如果 vfs 为空则从本地文件系统读取

type Manifest_package

type Manifest_package = config.Manifest_package

模块元信息中的包信息

type PkgVFS

type PkgVFS = config.PkgVFS

包虚拟文件系统

type Program

type Program = loader.Program

程序对象, 包含全量的 AST 和 SSA 信息, 经过语义检查

func LoadProgram

func LoadProgram(cfg *config.Config, appPath string) (*Program, error)

加载程序 入口 appPath 是包对应目录的路径

func LoadProgramFile

func LoadProgramFile(cfg *config.Config, filename string, src interface{}) (*Program, error)

加载单文件程序 入口 appPath 是包对应目录的路径

func LoadProgramVFS

func LoadProgramVFS(vfs *config.PkgVFS, cfg *config.Config, pkgPath string) (*Program, error)

基于 VFS 加载程序 入口 pkgPath 是包路径, 必须是 vfs.App 子包

type StdSize

type StdSize = config.StdSizes

指针和整数大小

Jump to

Keyboard shortcuts

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