Skip to content

Commit 8111d1a

Browse files
committed
feat: improve Batch transpiler and combine transpiler with interpreter
1 parent 4648e41 commit 8111d1a

21 files changed

Lines changed: 889 additions & 244 deletions

File tree

cmd/hulo/strategies/compile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ func (c *CompileStrategy) Execute(params *Parameters, args []string) error {
8787

8888
// 如果 targets 中没有指定语言,则默认编译所有
8989
if len(huloc.Targets) == 0 {
90-
huloc.Targets = append(huloc.Targets, config.L_VBSCRIPT, config.L_BASH)
90+
huloc.Targets = append(huloc.Targets, "bash", "vbs", "ps", "bat")
9191
}
9292

9393
if len(huloc.OutDir) == 0 {
9494
huloc.OutDir = "."
9595
}
9696

97-
if len(params.OutDir) > 0 {
97+
if params.OutDir != "." {
9898
huloc.OutDir = params.OutDir
9999
}
100100

examples/comp.hl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let a = comptime {
2+
let sum = 0
3+
loop $i := 0; $i < 10; $i++ {
4+
echo $i;
5+
$sum += $i;
6+
}
7+
return $sum
8+
}
9+
10+
comptime when $TARGET == "vbs" {
11+
MsgBox $a
12+
} else when $TARGET == "powershell" {
13+
Write-Output $a
14+
} else {
15+
echo $a
16+
}

examples/target.hl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
comptime when $TARGET == "powershell" {
2+
Write-Host "Hello, PowerShell"
3+
} else when $TARGET == "batch" {
4+
echo "Hello, Batch"
5+
} else when $TARGET == "bash" {
6+
echo "Hello, Bash"
7+
} else when $TARGET == "vbs" {
8+
MsgBox "Hello, VBScript"
9+
}

internal/compiler/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Compile(cfg *config.Huloc) error {
3535

3636
for _, target := range cfg.Targets {
3737
switch target {
38-
case config.L_BASH:
38+
case "bash":
3939
_, err := build.Transpile(cfg, nil, ".")
4040
if err != nil {
4141
return err

internal/config/huloc.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ type CompilerOptions struct {
3939
VBScript *VBScriptOptions `yaml:"vbs"`
4040
}
4141

42-
const (
43-
L_BASH = "bash"
44-
L_BATCH = "batch"
45-
L_VBSCRIPT = "vbs"
46-
L_PWSH = "powershell"
47-
)
48-
4942
// ParserOptions is the options for the parser.
5043
type ParserOptions struct {
5144
// ShowASTTree is the option to show the AST tree.

internal/interpreter/builtin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2025 The Hulo Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
14
package interpreter
25

36
import (

internal/interpreter/env.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2025 The Hulo Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
14
package interpreter
25

36
import (

internal/interpreter/env_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2025 The Hulo Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
14
package interpreter
25

36
import (

0 commit comments

Comments
 (0)