Skip to content

Commit

Permalink
- removing redundant declaration of string literal
Browse files Browse the repository at this point in the history
- updating example
  • Loading branch information
dfirebaugh committed Jan 2, 2025
1 parent eb1f7ad commit 3f713b1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/adder/adder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ WebAssembly.instantiate(wasmBuffer, importObject).then(wasmModule => {

console.log(`Sum from add_four: ${sum}`);
console.log(`Sum from add_two: ${sum2}`);
hello(false)
hello(true)
});
3 changes: 1 addition & 2 deletions examples/adder/adder.punch
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ pub i32 add_four(i32 a, i32 b, i32 c, i32 d) {
return a + b + c + d
}

pub i64 hello(bool is_hello) {
pub fn hello(bool is_hello) {
if is_hello {
println("hello, again")
}
return 0
}
8 changes: 5 additions & 3 deletions internal/emitters/wat/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/dfirebaugh/punch/internal/ast"
)

var scopeStack []map[string]string
var stringLiteralMap map[string]string
var (
scopeStack []map[string]string
stringLiteralMap map[string]string
)

func pushScope() {
scopeStack = append(scopeStack, make(map[string]string))
Expand Down Expand Up @@ -153,7 +155,7 @@ func collectExpressionLocals(
}
strInit.WriteString(fmt.Sprintf("(i32.store8 offset=%d (local.get $%s) (i32.const 0))\n", length-1, localVarName))
*stringLiterals = append(*stringLiterals, strInit.String())
*initializations = append(*initializations, fmt.Sprintf("(local.get $%s)\n", localVarName))
// *initializations = append(*initializations, fmt.Sprintf("(local.get $%s)\n", localVarName))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/emitters/wat/wat.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func generateStringLiteral(str *ast.StringLiteral) string {

out.WriteString(fmt.Sprintf("(i32.store8 offset=%d (local.get $%s) (i32.const 0))\n", length-1, localVarName))

out.WriteString(fmt.Sprintf("(local.get $%s)\n", localVarName))
// out.WriteString(fmt.Sprintf("(local.get $%s)\n", localVarName))

return out.String()
}
Expand Down

0 comments on commit 3f713b1

Please sign in to comment.