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.

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 Token

func Token(tok htok.Token) btok.Token

func Transpile added in v0.3.0

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

Types

type BatchTranspiler added in v0.3.0

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

func NewBatchTranspiler added in v0.3.0

func NewBatchTranspiler(opts *config.Huloc, vfs vfs.VFS) *BatchTranspiler

func (*BatchTranspiler) Convert added in v0.3.0

func (bt *BatchTranspiler) Convert(node hast.Node) bast.Node

func (*BatchTranspiler) ConvertArrayLiteralExpr added in v0.3.0

func (bt *BatchTranspiler) ConvertArrayLiteralExpr(node *hast.ArrayLiteralExpr) bast.Node

func (*BatchTranspiler) ConvertAssignStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertAssignStmt(node *hast.AssignStmt) bast.Node

func (*BatchTranspiler) ConvertBinaryExpr added in v0.3.0

func (bt *BatchTranspiler) ConvertBinaryExpr(node *hast.BinaryExpr) bast.Node

func (*BatchTranspiler) ConvertBlockStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertBlockStmt(node *hast.BlockStmt) bast.Node

func (*BatchTranspiler) ConvertCallExpr added in v0.3.0

func (bt *BatchTranspiler) ConvertCallExpr(node *hast.CallExpr) bast.Node

func (*BatchTranspiler) ConvertCmdExpr added in v0.3.0

func (bt *BatchTranspiler) ConvertCmdExpr(node *hast.CmdExpr) bast.Node

func (*BatchTranspiler) ConvertCommentGroup added in v0.3.0

func (bt *BatchTranspiler) ConvertCommentGroup(node *hast.CommentGroup) bast.Node

func (*BatchTranspiler) ConvertDoWhileStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertDoWhileStmt(node *hast.DoWhileStmt) bast.Node

func (*BatchTranspiler) ConvertFile added in v0.3.0

func (bt *BatchTranspiler) ConvertFile(node *hast.File) bast.Node

func (*BatchTranspiler) ConvertForStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertForStmt(node *hast.ForStmt) bast.Node

func (*BatchTranspiler) ConvertForeachStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertForeachStmt(node *hast.ForeachStmt) bast.Node

func (*BatchTranspiler) ConvertFuncDecl added in v0.3.0

func (bt *BatchTranspiler) ConvertFuncDecl(node *hast.FuncDecl) bast.Node

func (*BatchTranspiler) ConvertIfStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertIfStmt(node *hast.IfStmt) bast.Node

func (*BatchTranspiler) ConvertImport added in v0.3.0

func (bt *BatchTranspiler) ConvertImport(node *hast.Import) bast.Node

func (*BatchTranspiler) ConvertIncDecExpr added in v0.3.0

func (bt *BatchTranspiler) ConvertIncDecExpr(node *hast.IncDecExpr) bast.Node

func (*BatchTranspiler) ConvertMatchStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertMatchStmt(node *hast.MatchStmt) bast.Node

func (*BatchTranspiler) ConvertRefExpr added in v0.3.0

func (bt *BatchTranspiler) ConvertRefExpr(node *hast.RefExpr) bast.Node

func (*BatchTranspiler) ConvertReturnStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertReturnStmt(node *hast.ReturnStmt) bast.Node

func (*BatchTranspiler) ConvertWhileStmt added in v0.3.0

func (bt *BatchTranspiler) ConvertWhileStmt(node *hast.WhileStmt) bast.Node

func (*BatchTranspiler) Emit added in v0.3.0

func (bt *BatchTranspiler) Emit(n ...bast.Stmt)

func (*BatchTranspiler) Flush added in v0.3.0

func (bt *BatchTranspiler) Flush() []bast.Stmt

func (*BatchTranspiler) Transpile added in v0.3.0

func (bt *BatchTranspiler) Transpile(mainFile string) (map[string]string, error)

type DependencyResolver added in v0.3.0

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

type ExportInfo added in v0.3.0

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

type ExportKind added in v0.3.0

type ExportKind int

Function, Class, Constant, etc.

const (
	ExportFunction ExportKind = iota
	ExportClass
	ExportConstant
	ExportVariable
)

type ImportInfo added in v0.3.0

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

type ImportKind added in v0.3.0

type ImportKind int

Named, All, Default

const (
	ImportSingle ImportKind = iota
	ImportMulti
	ImportAll
)

type Module added in v0.3.0

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

type ModuleManager added in v0.3.0

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

func (*ModuleManager) GetModule added in v0.3.0

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

func (*ModuleManager) ResolveAllDependencies added in v0.3.0

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

type Scope added in v0.3.0

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

type ScopeStack added in v0.3.0

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

func (*ScopeStack) Current added in v0.3.0

func (ss *ScopeStack) Current() *Scope

func (*ScopeStack) Pop added in v0.3.0

func (ss *ScopeStack) Pop()

func (*ScopeStack) Push added in v0.3.0

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

type ScopeType added in v0.3.0

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

type Symbol added in v0.3.0

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

type SymbolTable added in v0.3.0

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

func NewSymbolTable added in v0.3.0

func NewSymbolTable(moduleName string, enableMangle bool) *SymbolTable

NewSymbolTable 创建新的符号表

func (*SymbolTable) AddClass added in v0.3.0

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

AddClass 添加类

func (*SymbolTable) AddConstant added in v0.3.0

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

AddConstant 添加常量

func (*SymbolTable) AddFunction added in v0.3.0

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

AddFunction 添加函数

func (*SymbolTable) AddSymbol added in v0.3.0

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

添加符号到当前作用域

func (*SymbolTable) AddVariable added in v0.3.0

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

AddVariable 添加变量

func (*SymbolTable) AllocVariableName added in v0.3.0

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

变量分配策略

func (*SymbolTable) CurrentScope added in v0.3.0

func (st *SymbolTable) CurrentScope() *Scope

func (*SymbolTable) HasClass added in v0.3.0

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

HasClass 检查是否包含类

func (*SymbolTable) HasConstant added in v0.3.0

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

HasConstant 检查是否包含常量

func (*SymbolTable) HasFunction added in v0.3.0

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

HasFunction 检查是否包含函数

func (*SymbolTable) HasVariable added in v0.3.0

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

HasVariable 检查是否包含变量

func (*SymbolTable) LookupSymbol added in v0.3.0

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

符号查找

func (*SymbolTable) PopScope added in v0.3.0

func (st *SymbolTable) PopScope()

func (*SymbolTable) PushScope added in v0.3.0

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

作用域管理方法

type SymbolType added in v0.3.0

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