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: 16 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transpile

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

Types

type DependencyResolver

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

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   *past.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 PowerShellTranspiler

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

func NewPowerShellTranspiler

func NewPowerShellTranspiler(opts *config.Huloc, vfs vfs.VFS) *PowerShellTranspiler

func (*PowerShellTranspiler) Convert

func (p *PowerShellTranspiler) Convert(node hast.Node) past.Node

func (*PowerShellTranspiler) ConvertArrayLiteralExpr

func (p *PowerShellTranspiler) ConvertArrayLiteralExpr(node *hast.ArrayLiteralExpr) past.Node

func (*PowerShellTranspiler) ConvertAssignStmt

func (p *PowerShellTranspiler) ConvertAssignStmt(node *hast.AssignStmt) past.Node

func (*PowerShellTranspiler) ConvertBinaryExpr

func (p *PowerShellTranspiler) ConvertBinaryExpr(node *hast.BinaryExpr) past.Node

func (*PowerShellTranspiler) ConvertBlockStmt

func (p *PowerShellTranspiler) ConvertBlockStmt(node *hast.BlockStmt) past.Node

func (*PowerShellTranspiler) ConvertBoolLiteral

func (p *PowerShellTranspiler) ConvertBoolLiteral(node *hast.TrueLiteral) past.Node

func (*PowerShellTranspiler) ConvertBreakStmt

func (p *PowerShellTranspiler) ConvertBreakStmt(node *hast.BreakStmt) past.Node

func (*PowerShellTranspiler) ConvertCallExpr

func (p *PowerShellTranspiler) ConvertCallExpr(node *hast.CallExpr) past.Node

func (*PowerShellTranspiler) ConvertCaseClause

func (p *PowerShellTranspiler) ConvertCaseClause(node *hast.CaseClause) past.Node

func (*PowerShellTranspiler) ConvertCatchClause

func (p *PowerShellTranspiler) ConvertCatchClause(node *hast.CatchClause) past.Node

func (*PowerShellTranspiler) ConvertClassDecl

func (p *PowerShellTranspiler) ConvertClassDecl(node *hast.ClassDecl) past.Node

func (*PowerShellTranspiler) ConvertCmdExpr

func (p *PowerShellTranspiler) ConvertCmdExpr(node *hast.CmdExpr) past.Node

func (*PowerShellTranspiler) ConvertComment

func (p *PowerShellTranspiler) ConvertComment(node *hast.Comment) past.Node

func (*PowerShellTranspiler) ConvertCommentGroup

func (p *PowerShellTranspiler) ConvertCommentGroup(node *hast.CommentGroup) past.Node

func (*PowerShellTranspiler) ConvertContinueStmt

func (p *PowerShellTranspiler) ConvertContinueStmt(node *hast.ContinueStmt) past.Node

func (*PowerShellTranspiler) ConvertDoWhileStmt

func (p *PowerShellTranspiler) ConvertDoWhileStmt(node *hast.DoWhileStmt) past.Node

func (*PowerShellTranspiler) ConvertEnumDecl

func (p *PowerShellTranspiler) ConvertEnumDecl(node *hast.EnumDecl) past.Node

func (*PowerShellTranspiler) ConvertExprStmt

func (p *PowerShellTranspiler) ConvertExprStmt(node *hast.ExprStmt) past.Node

func (*PowerShellTranspiler) ConvertFalseLiteral

func (p *PowerShellTranspiler) ConvertFalseLiteral(node *hast.FalseLiteral) past.Node

func (*PowerShellTranspiler) ConvertFile

func (p *PowerShellTranspiler) ConvertFile(node *hast.File) past.Node

func (*PowerShellTranspiler) ConvertForStmt

func (p *PowerShellTranspiler) ConvertForStmt(node *hast.ForStmt) past.Node

func (*PowerShellTranspiler) ConvertForeachStmt

func (p *PowerShellTranspiler) ConvertForeachStmt(node *hast.ForeachStmt) past.Node

func (*PowerShellTranspiler) ConvertFuncDecl

func (p *PowerShellTranspiler) ConvertFuncDecl(node *hast.FuncDecl) past.Node

func (*PowerShellTranspiler) ConvertIdent

func (p *PowerShellTranspiler) ConvertIdent(node *hast.Ident) past.Node

func (*PowerShellTranspiler) ConvertIfStmt

func (p *PowerShellTranspiler) ConvertIfStmt(node *hast.IfStmt) past.Node

func (*PowerShellTranspiler) ConvertImport

func (p *PowerShellTranspiler) ConvertImport(node *hast.Import) past.Node

func (*PowerShellTranspiler) ConvertIncDecExpr

func (p *PowerShellTranspiler) ConvertIncDecExpr(node *hast.IncDecExpr) past.Node

func (*PowerShellTranspiler) ConvertNumericLiteral

func (p *PowerShellTranspiler) ConvertNumericLiteral(node *hast.NumericLiteral) past.Node

func (*PowerShellTranspiler) ConvertObjectLiteralExpr

func (p *PowerShellTranspiler) ConvertObjectLiteralExpr(node *hast.ObjectLiteralExpr) past.Node

func (*PowerShellTranspiler) ConvertParameter

func (p *PowerShellTranspiler) ConvertParameter(node *hast.Parameter) past.Node

func (*PowerShellTranspiler) ConvertRefExpr

func (p *PowerShellTranspiler) ConvertRefExpr(node *hast.RefExpr) past.Node

func (*PowerShellTranspiler) ConvertReturnStmt

func (p *PowerShellTranspiler) ConvertReturnStmt(node *hast.ReturnStmt) past.Node

func (*PowerShellTranspiler) ConvertSelectExpr

func (p *PowerShellTranspiler) ConvertSelectExpr(node *hast.SelectExpr) past.Node

func (*PowerShellTranspiler) ConvertStringLiteral

func (p *PowerShellTranspiler) ConvertStringLiteral(node *hast.StringLiteral) past.Node

func (*PowerShellTranspiler) ConvertSwitchStmt

func (p *PowerShellTranspiler) ConvertSwitchStmt(node *hast.MatchStmt) past.Node

func (*PowerShellTranspiler) ConvertThrowStmt

func (p *PowerShellTranspiler) ConvertThrowStmt(node *hast.ThrowStmt) past.Node

func (*PowerShellTranspiler) ConvertTryStmt

func (p *PowerShellTranspiler) ConvertTryStmt(node *hast.TryStmt) past.Node

func (*PowerShellTranspiler) ConvertWhileStmt

func (p *PowerShellTranspiler) ConvertWhileStmt(node *hast.WhileStmt) past.Node

func (*PowerShellTranspiler) Transpile

func (p *PowerShellTranspiler) Transpile(mainFile string) (map[string]string, 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
)

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, node hast.Node)

AddClass 添加类

func (*SymbolTable) AddConstant

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

AddConstant 添加常量

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) HasClass

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

HasClass 检查是否包含类

func (*SymbolTable) HasConstant

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

HasConstant 检查是否包含常量

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) *Scope

作用域管理方法

type SymbolType

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

Jump to

Keyboard shortcuts

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