Skip to content

Commit 5322b2b

Browse files
🎨 Final code formatting and quality improvements
1 parent ea74b2a commit 5322b2b

21 files changed

Lines changed: 327 additions & 210 deletions

File tree

examples/hello.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ func main() {
66
// Basic output
77
fmt.Println("Hello from Go!")
88
fmt.Println("Running on Ditto embedded interpreter")
9-
9+
1010
// Variables
1111
name := "Ditto"
1212
version := "0.1.0"
1313
fmt.Println("Project:", name, "v"+version)
14-
14+
1515
// Arithmetic
1616
a := 10
1717
b := 20
1818
fmt.Println("Sum:", a+b)
19-
19+
2020
// Array
2121
colors := []string{"red", "green", "blue"}
2222
fmt.Println("Colors:", len(colors), "items")
23-
23+
2424
// Loop
2525
for i := 0; i < 3; i++ {
2626
fmt.Println("Counting:", i)
2727
}
28-
28+
2929
// If statement
3030
x := 10
3131
if x > 5 {

internal/config/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88

99
// Config holds the application configuration
1010
type Config struct {
11-
TempDir string
12-
RuntimesDir string
13-
CacheDir string
14-
TargetOS string
15-
TargetArch string
11+
TempDir string
12+
RuntimesDir string
13+
CacheDir string
14+
TargetOS string
15+
TargetArch string
1616
}
1717

1818
// RuntimeInfo describes a bundled runtime
@@ -30,11 +30,11 @@ func Default() *Config {
3030
runtimesDir := filepath.Join(os.TempDir(), "Ditto-runtimes")
3131

3232
return &Config{
33-
TempDir: filepath.Join(os.TempDir(), "Ditto"),
34-
RuntimesDir: runtimesDir,
35-
CacheDir: cacheDir,
36-
TargetOS: runtime.GOOS,
37-
TargetArch: runtime.GOARCH,
33+
TempDir: filepath.Join(os.TempDir(), "Ditto"),
34+
RuntimesDir: runtimesDir,
35+
CacheDir: cacheDir,
36+
TargetOS: runtime.GOOS,
37+
TargetArch: runtime.GOARCH,
3838
}
3939
}
4040

internal/interpreter/c.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func (c *CInterpreter) executePureGo(code string, args []string, stdin io.Reader
6464
// Simplified C-like execution for basic programs
6565
cvm := &cVM{
6666
variables: make(map[string]interface{}),
67-
stdin: stdin,
68-
stdout: stdout,
69-
stderr: stderr,
70-
args: args,
67+
stdin: stdin,
68+
stdout: stdout,
69+
stderr: stderr,
70+
args: args,
7171
}
7272

7373
return cvm.Run(code)

internal/interpreter/go.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func (g *GoInterpreter) Execute(engine *Engine, code string, args []string, stdi
2929
goVM := &goVM{
3030
variables: make(map[string]interface{}),
3131
functions: make(map[string]*goFunction),
32-
stdin: stdin,
33-
stdout: stdout,
34-
stderr: stderr,
35-
args: args,
32+
stdin: stdin,
33+
stdout: stdout,
34+
stderr: stderr,
35+
args: args,
3636
}
3737

3838
// Walk the AST and execute
@@ -53,10 +53,10 @@ func (g *GoInterpreter) executeSimple(code string, args []string, stdin io.Reade
5353
goVM := &goVM{
5454
variables: make(map[string]interface{}),
5555
functions: make(map[string]*goFunction),
56-
stdin: stdin,
57-
stdout: stdout,
58-
stderr: stderr,
59-
args: args,
56+
stdin: stdin,
57+
stdout: stdout,
58+
stderr: stderr,
59+
args: args,
6060
}
6161

6262
return goVM.Run(code)
@@ -85,10 +85,10 @@ func (vm *goVM) Run(code string) error {
8585
func (vm *goVM) executeLines(lines []string) error {
8686
for i, line := range lines {
8787
line = strings.TrimSpace(line)
88-
88+
8989
// Skip empty lines, comments, package/import declarations
90-
if line == "" || strings.HasPrefix(line, "//") ||
91-
strings.HasPrefix(line, "package ") || strings.HasPrefix(line, "import ") {
90+
if line == "" || strings.HasPrefix(line, "//") ||
91+
strings.HasPrefix(line, "package ") || strings.HasPrefix(line, "import ") {
9292
continue
9393
}
9494

@@ -147,7 +147,7 @@ func (vm *goVM) handleFmtPrintln(line string) {
147147

148148
argsStr := line[start+1 : end]
149149
args := vm.parseArgs(argsStr)
150-
150+
151151
for i, arg := range args {
152152
if i > 0 {
153153
fmt.Fprint(vm.stdout, " ")
@@ -166,7 +166,7 @@ func (vm *goVM) handleFmtPrintf(line string) {
166166

167167
argsStr := line[start+1 : end]
168168
args := vm.parseArgs(argsStr)
169-
169+
170170
if len(args) > 0 {
171171
format := args[0]
172172
values := make([]interface{}, len(args[1:]))
@@ -186,7 +186,7 @@ func (vm *goVM) handleFmtPrint(line string) {
186186

187187
argsStr := line[start+1 : end]
188188
args := vm.parseArgs(argsStr)
189-
189+
190190
for _, arg := range args {
191191
fmt.Fprint(vm.stdout, arg)
192192
}
@@ -274,8 +274,8 @@ func (vm *goVM) evaluate(expr string) string {
274274

275275
// Try to parse as number
276276
if expr == "0" || expr == "1" || expr == "2" || expr == "3" || expr == "4" ||
277-
expr == "5" || expr == "6" || expr == "7" || expr == "8" || expr == "9" ||
278-
expr == "10" || expr == "42" || expr == "100" {
277+
expr == "5" || expr == "6" || expr == "7" || expr == "8" || expr == "9" ||
278+
expr == "10" || expr == "42" || expr == "100" {
279279
return expr
280280
}
281281

internal/interpreter/interpreter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type Interpreter interface {
2222

2323
// Engine manages all interpreters
2424
type Engine struct {
25-
wasmRuntime wazero.Runtime
26-
interpreters map[string]Interpreter
25+
wasmRuntime wazero.Runtime
26+
interpreters map[string]Interpreter
2727
}
2828

2929
// NewEngine creates a new execution engine
@@ -91,7 +91,7 @@ func (e *Engine) ExecuteWASM(ctx context.Context, wasmBytes []byte, code string,
9191

9292
// Create a temporary file in the WASM memory or via WASI
9393
// For MicroPython/QuickJS, we often pass the code via stdin or as an argument
94-
94+
9595
config := wazero.NewModuleConfig().
9696
WithName("interpreter").
9797
WithStdout(stdout).

internal/interpreter/javascript.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (j *JavaScriptInterpreter) executeWASM(engine *Engine, code string, args []
9090
// For now, fall back to pure Go interpreter
9191
// The WASM infrastructure is in place for future enhancement
9292
_ = wasmModule
93-
93+
9494
return fmt.Errorf("QuickJS WASM requires WASI filesystem setup - using pure Go interpreter with package support")
9595
}
9696

@@ -99,11 +99,11 @@ func (j *JavaScriptInterpreter) executePureGo(code string, args []string, stdin
9999
variables: make(map[string]interface{}),
100100
functions: make(map[string]*jsFunction),
101101
modules: make(map[string]map[string]interface{}),
102-
stdin: stdin,
103-
stdout: stdout,
104-
stderr: stderr,
105-
args: args,
106-
vfs: vfs,
102+
stdin: stdin,
103+
stdout: stdout,
104+
stderr: stderr,
105+
args: args,
106+
vfs: vfs,
107107
}
108108
js.stdlib = stdlib.NewNodeStdLib()
109109

@@ -256,7 +256,7 @@ func (vm *jsVM) handleConsoleLog(expr string) error {
256256
if match := regexp.MustCompile(`^(\w+)\.(\w+)\(([^)]*)\)$`).FindStringSubmatch(expr); match != nil {
257257
return vm.handleModuleCall(match[1], match[2], match[3])
258258
}
259-
259+
260260
// Handle typeof expressions
261261
if match := regexp.MustCompile(`^typeof\s+(\w+)$`).FindStringSubmatch(expr); match != nil {
262262
varName := match[1]
@@ -277,14 +277,14 @@ func (vm *jsVM) handleConsoleLog(expr string) error {
277277
fmt.Fprintln(vm.stdout, "undefined")
278278
return nil
279279
}
280-
280+
281281
// Handle string concatenation
282282
if strings.Contains(expr, "+") && (strings.HasPrefix(expr, `"`) || strings.Contains(expr, `"`)) {
283283
result := vm.evalStringConcat(expr)
284284
fmt.Fprintln(vm.stdout, result)
285285
return nil
286286
}
287-
287+
288288
result, err := vm.evaluate(expr)
289289
if err != nil {
290290
return err
@@ -459,7 +459,7 @@ func (vm *jsVM) loadModuleFromVFS(moduleName, modulePath string) error {
459459

460460
// Create a module scope
461461
moduleExports := make(map[string]interface{})
462-
462+
463463
// Create a simplified require for nested imports
464464
moduleRequire := func(name string) map[string]interface{} {
465465
// Check stdlib first
@@ -479,12 +479,12 @@ func (vm *jsVM) loadModuleFromVFS(moduleName, modulePath string) error {
479479

480480
vm.modules[moduleName] = moduleExports
481481
vm.variables[moduleName] = moduleExports
482-
482+
483483
// Execute the module code in a simplified way
484484
// This is a placeholder - full execution would need proper JS VM
485485
_ = content
486486
_ = moduleObj
487-
487+
488488
return nil
489489
}
490490

internal/interpreter/lua.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ func (l *LuaInterpreter) Execute(engine *Engine, code string, args []string, std
2020
lua := &luaVM{
2121
variables: make(map[string]interface{}),
2222
functions: make(map[string]*luaFunction),
23-
stdin: stdin,
24-
stdout: stdout,
25-
stderr: stderr,
26-
args: args,
23+
stdin: stdin,
24+
stdout: stdout,
25+
stderr: stderr,
26+
args: args,
2727
}
2828

2929
return lua.Run(code)
@@ -39,9 +39,9 @@ type luaVM struct {
3939
}
4040

4141
type luaFunction struct {
42-
name string
42+
name string
4343
params []string
44-
body string
44+
body string
4545
}
4646

4747
func (vm *luaVM) Run(code string) error {
@@ -53,7 +53,7 @@ func (vm *luaVM) executeLines(lines []string) error {
5353
i := 0
5454
for i < len(lines) {
5555
line := strings.TrimSpace(lines[i])
56-
56+
5757
// Skip empty lines and comments
5858
if line == "" || strings.HasPrefix(line, "--") {
5959
i++
@@ -185,9 +185,9 @@ func (vm *luaVM) handleFunctionDef(name, params string, lineNum int) (int, error
185185
// Simplified - would need to collect body until "end"
186186
paramList := vm.parseParams(params)
187187
vm.functions[name] = &luaFunction{
188-
name: name,
188+
name: name,
189189
params: paramList,
190-
body: "",
190+
body: "",
191191
}
192192
return lineNum + 1, nil
193193
}

internal/interpreter/python.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ func (p *PythonInterpreter) executePureGo(code string, args []string, stdin io.R
8080
functions: make(map[string]*pythonFunction),
8181
classes: make(map[string]*pythonClass),
8282
stdlib: stdlib.NewPythonStdLib(),
83-
stdin: stdin,
84-
stdout: stdout,
85-
stderr: stderr,
86-
args: args,
87-
vfs: vfs,
83+
stdin: stdin,
84+
stdout: stdout,
85+
stderr: stderr,
86+
args: args,
87+
vfs: vfs,
8888
}
8989
py.stdlib.Init()
9090

internal/interpreter/python_builtins.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (vm *pythonVM) callFunction(fn *pythonFunction, argsStr string) error {
113113
func (vm *pythonVM) callPythonFunction(fn *pythonFunction, argsStr string) (interface{}, error) {
114114
// Parse arguments
115115
args := vm.parseArgs(argsStr)
116-
116+
117117
// Create a new scope for the function
118118
funcVM := &pythonVM{
119119
variables: make(map[string]interface{}),
@@ -125,7 +125,7 @@ func (vm *pythonVM) callPythonFunction(fn *pythonFunction, argsStr string) (inte
125125
stderr: vm.stderr,
126126
vfs: vm.vfs,
127127
}
128-
128+
129129
// Bind arguments to parameters (simplified - just bind by position)
130130
for i, param := range fn.params {
131131
param = strings.TrimSpace(param)
@@ -141,7 +141,7 @@ func (vm *pythonVM) callPythonFunction(fn *pythonFunction, argsStr string) (inte
141141
funcVM.variables[param] = args[i]
142142
}
143143
}
144-
144+
145145
// Execute function body line by line
146146
lines := strings.Split(fn.body, "\n")
147147
var lastResult interface{}
@@ -155,7 +155,7 @@ func (vm *pythonVM) callPythonFunction(fn *pythonFunction, argsStr string) (inte
155155
}
156156

157157
fmt.Fprintf(os.Stderr, "[DEBUG] func line (%d): %s\n", i, line)
158-
158+
159159
// Handle return statement
160160
if strings.HasPrefix(line, "return ") {
161161
returnExpr := strings.TrimPrefix(line, "return ")
@@ -194,7 +194,7 @@ func (vm *pythonVM) callPythonFunction(fn *pythonFunction, argsStr string) (inte
194194
continue
195195
}
196196
}
197-
197+
198198
// Return nil for functions without explicit return
199199
return lastResult, nil
200200
}

internal/interpreter/python_expressions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (vm *pythonVM) evaluate(expr string) (interface{}, error) {
2626
if pyFn, ok := fn.(*pythonFunction); ok {
2727
return vm.callPythonFunction(pyFn, argsStr)
2828
}
29-
29+
3030
// Call the function with arguments
3131
switch f := fn.(type) {
3232
case func(string) interface{}:

0 commit comments

Comments
 (0)