transpiler

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

View Source
const WILDCARD = "_"

Variables

This section is empty.

Functions

func Token

func Token(tok htok.Token) vtok.Token

func Transpile

func Transpile(opts *config.Huloc, vfs vfs.VFS, basePath string) (map[string]string, error)

Types

type ClassSymbol

type ClassSymbol struct {
	Name   string   // 类名
	Fields []string // 字段名列表
	Public bool     // 是否为公共类
}

ClassSymbol 表示类的符号表信息

type DependencyResolver

type DependencyResolver struct {
	// contains filtered or unexported fields
}

type EnumSymbol

type EnumSymbol struct {
	Name   string       // 枚举名
	Values []*EnumValue // 枚举值列表
}

EnumSymbol 表示枚举的符号表信息

type EnumValue

type EnumValue struct {
	Name  string // 枚举值名
	Value string // 实际值
	Type  string // 值类型:number, string, boolean
}

EnumValue 表示枚举值的信息

type ExportInfo

type ExportInfo struct {
	Name   string
	Value  hast.Node
	Kind   ExportKind
	Public bool
}

type ExportKind

type ExportKind int

Function, Class, Constant, etc.

const (
	ExportFunction ExportKind = iota
	ExportClass
	ExportConstant
	ExportVariable
)

type ImportInfo

type ImportInfo struct {
	ModulePath string
	SymbolName []string
	Alias      string
	Kind       ImportKind
}

type ImportKind

type ImportKind int

Named, All, Default

const (
	ImportSingle ImportKind = iota
	ImportMulti
	ImportAll
)

type Module

type Module struct {
	Name         string
	Path         string
	AST          *hast.File
	Exports      map[string]*ExportInfo
	Imports      []*ImportInfo
	Dependencies []string
	Transpiled   *vast.File
	Symbols      *SymbolTable
}

type ModuleManager

type ModuleManager struct {
	// contains filtered or unexported fields
}

func (*ModuleManager) GetModule

func (mm *ModuleManager) GetModule(path string) *Module

func (*ModuleManager) ResolveAllDependencies

func (mm *ModuleManager) ResolveAllDependencies(mainFile string) ([]*Module, error)

type Scope

type Scope struct {
	ID        string             // 作用域唯一标识
	Type      ScopeType          // 作用域类型
	Variables map[string]*Symbol // 变量名 -> 符号
	Parent    *Scope             // 父作用域
	Module    *Module            // 所属模块
}

type ScopeStack

type ScopeStack struct {
	// contains filtered or unexported fields
}

func (*ScopeStack) Current

func (ss *ScopeStack) Current() *Scope

func (*ScopeStack) Pop

func (ss *ScopeStack) Pop()

func (*ScopeStack) Push

func (ss *ScopeStack) Push(scope *Scope)

type ScopeType

type ScopeType int
const (
	GlobalScope ScopeType = iota
	FunctionScope
	ClassScope
	BlockScope
	ForScope
)

type StringPart

type StringPart struct {
	Text       string
	IsVariable bool
	Expr       vast.Expr
}

func ParseStringInterpolation

func ParseStringInterpolation(s string) []StringPart

type Symbol

type Symbol struct {
	Name        string     // 原始名称
	MangledName string     // 混淆后的名称
	Type        SymbolType // 符号类型
	Value       hast.Node  // 原始AST节点
	Scope       *Scope     // 所属作用域
	Module      *Module    // 所属模块
	IsExported  bool       // 是否导出
}

type SymbolTable

type SymbolTable struct {
	// contains filtered or unexported fields
}

func NewSymbolTable

func NewSymbolTable(moduleName string, enableMangle bool) *SymbolTable

NewSymbolTable 创建新的符号表

func (*SymbolTable) AddClass

func (st *SymbolTable) AddClass(name string, class *ClassSymbol)

AddClass 添加类

func (*SymbolTable) AddConstant

func (st *SymbolTable) AddConstant(name string, node hast.Node)

AddConstant 添加常量

func (*SymbolTable) AddEnum

func (st *SymbolTable) AddEnum(name string, values []*EnumValue)

func (*SymbolTable) AddFunction

func (st *SymbolTable) AddFunction(name string, node hast.Node)

AddFunction 添加函数

func (*SymbolTable) AddSymbol

func (st *SymbolTable) AddSymbol(symbol *Symbol)

添加符号到当前作用域

func (*SymbolTable) AddVariable

func (st *SymbolTable) AddVariable(name string, node hast.Node)

AddVariable 添加变量

func (*SymbolTable) AllocVariableName

func (st *SymbolTable) AllocVariableName(originalName string, scope *Scope) string

变量分配策略

func (*SymbolTable) CurrentScope

func (st *SymbolTable) CurrentScope() *Scope

func (*SymbolTable) GetClass

func (st *SymbolTable) GetClass(name string) (*ClassSymbol, bool)

func (*SymbolTable) GetEnum

func (st *SymbolTable) GetEnum(name string) (*EnumSymbol, bool)

func (*SymbolTable) HasClass

func (st *SymbolTable) HasClass(name string) bool

HasClass 检查是否包含类

func (*SymbolTable) HasConstant

func (st *SymbolTable) HasConstant(name string) bool

HasConstant 检查是否包含常量

func (*SymbolTable) HasEnum

func (st *SymbolTable) HasEnum(name string) bool

func (*SymbolTable) HasEnumValue

func (st *SymbolTable) HasEnumValue(enumName, valueName string) bool

func (*SymbolTable) HasFunction

func (st *SymbolTable) HasFunction(name string) bool

HasFunction 检查是否包含函数

func (*SymbolTable) HasVariable

func (st *SymbolTable) HasVariable(name string) bool

HasVariable 检查是否包含变量

func (*SymbolTable) LookupSymbol

func (st *SymbolTable) LookupSymbol(name string) *Symbol

符号查找

func (*SymbolTable) PopScope

func (st *SymbolTable) PopScope()

func (*SymbolTable) PushScope

func (st *SymbolTable) PushScope(scopeType ScopeType, module *Module, id ...string) *Scope

作用域管理方法

type SymbolType

type SymbolType int
const (
	SymbolVariable SymbolType = iota
	SymbolFunction
	SymbolClass
	SymbolConstant
	SymbolArray
	SymbolObject
)

type VBScriptTranspiler

type VBScriptTranspiler struct {
	// contains filtered or unexported fields
}

func NewVBScriptTranspiler

func NewVBScriptTranspiler(opts *config.Huloc, vfs vfs.VFS) *VBScriptTranspiler

func (*VBScriptTranspiler) Convert

func (v *VBScriptTranspiler) Convert(node hast.Node) vast.Node

func (*VBScriptTranspiler) ConvertArrayLiteral

func (v *VBScriptTranspiler) ConvertArrayLiteral(node *hast.ArrayLiteralExpr) vast.Node

ConvertArrayLiteral 将Hulo数组字面量转换为VBScript的Array函数调用

func (*VBScriptTranspiler) ConvertAssignStmt

func (v *VBScriptTranspiler) ConvertAssignStmt(node *hast.AssignStmt) vast.Node

func (*VBScriptTranspiler) ConvertBlock

func (v *VBScriptTranspiler) ConvertBlock(node *hast.BlockStmt) vast.Node

func (*VBScriptTranspiler) ConvertCallExpr

func (v *VBScriptTranspiler) ConvertCallExpr(node *hast.CallExpr) vast.Node

func (*VBScriptTranspiler) ConvertClassDecl

func (v *VBScriptTranspiler) ConvertClassDecl(node *hast.ClassDecl) vast.Node

func (*VBScriptTranspiler) ConvertCmdExpr

func (v *VBScriptTranspiler) ConvertCmdExpr(node *hast.CmdExpr) vast.Node

func (*VBScriptTranspiler) ConvertDeclareDecl

func (v *VBScriptTranspiler) ConvertDeclareDecl(node *hast.DeclareDecl) vast.Node

func (*VBScriptTranspiler) ConvertEnumDecl

func (v *VBScriptTranspiler) ConvertEnumDecl(node *hast.EnumDecl) vast.Node

ConvertEnumDecl 将 Hulo 的枚举声明转换为 VBScript 的常量声明

func (*VBScriptTranspiler) ConvertExternDecl

func (v *VBScriptTranspiler) ConvertExternDecl(node *hast.ExternDecl) vast.Node

func (*VBScriptTranspiler) ConvertFile

func (v *VBScriptTranspiler) ConvertFile(node *hast.File) vast.Node

func (*VBScriptTranspiler) ConvertForStmt

func (v *VBScriptTranspiler) ConvertForStmt(node *hast.ForStmt) vast.Node

func (*VBScriptTranspiler) ConvertForeachStmt

func (v *VBScriptTranspiler) ConvertForeachStmt(node *hast.ForeachStmt) vast.Node

ConvertForeachStmt 将Hulo的foreach语句转换为VBScript的For Each语句

func (*VBScriptTranspiler) ConvertFuncDecl

func (v *VBScriptTranspiler) ConvertFuncDecl(node *hast.FuncDecl) vast.Node

func (*VBScriptTranspiler) ConvertIfStmt

func (v *VBScriptTranspiler) ConvertIfStmt(node *hast.IfStmt) vast.Node

func (*VBScriptTranspiler) ConvertImport

func (v *VBScriptTranspiler) ConvertImport(node *hast.Import) vast.Node

func (*VBScriptTranspiler) ConvertIncDecExpr

func (v *VBScriptTranspiler) ConvertIncDecExpr(node *hast.IncDecExpr) vast.Node

func (*VBScriptTranspiler) ConvertMatchStmt

func (v *VBScriptTranspiler) ConvertMatchStmt(node *hast.MatchStmt) vast.Node

ConvertMatchStmt 将 Hulo 的 match 语句转换为 VBScript 的 if-elseif-else 语句

func (*VBScriptTranspiler) ConvertModAccessExpr

func (v *VBScriptTranspiler) ConvertModAccessExpr(node *hast.ModAccessExpr) vast.Node

ConvertModAccessExpr 将模块访问表达式转换为相应的常量引用 例如:Status::Pending 转换为 0(数字枚举)或生成常量声明(字符串枚举)

func (*VBScriptTranspiler) ConvertObjectLiteral

func (v *VBScriptTranspiler) ConvertObjectLiteral(node *hast.ObjectLiteralExpr) vast.Node

ConvertObjectLiteral 将Hulo对象字面量转换为VBScript的Dictionary对象

func (*VBScriptTranspiler) ConvertParameter

func (v *VBScriptTranspiler) ConvertParameter(node *hast.Parameter) vast.Node

func (*VBScriptTranspiler) ConvertReturnStmt

func (v *VBScriptTranspiler) ConvertReturnStmt(node *hast.ReturnStmt) vast.Node

func (*VBScriptTranspiler) ConvertSelectExpr

func (v *VBScriptTranspiler) ConvertSelectExpr(node *hast.SelectExpr) vast.Node

func (*VBScriptTranspiler) ConvertStringLiteral

func (v *VBScriptTranspiler) ConvertStringLiteral(node *hast.StringLiteral) vast.Node

func (*VBScriptTranspiler) ConvertUnsafeStmt

func (v *VBScriptTranspiler) ConvertUnsafeStmt(node *hast.UnsafeStmt) vast.Node

func (*VBScriptTranspiler) Emit

func (v *VBScriptTranspiler) Emit(n ...vast.Stmt)

func (*VBScriptTranspiler) Flush

func (v *VBScriptTranspiler) Flush() []vast.Stmt

func (*VBScriptTranspiler) Transpile

func (b *VBScriptTranspiler) Transpile(mainFile string) (map[string]string, error)

Jump to

Keyboard shortcuts

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