Skip to content

Commit ab769f9

Browse files
committed
fix up codegen test
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent f65333d commit ab769f9

File tree

7 files changed

+70
-39
lines changed

7 files changed

+70
-39
lines changed

pkg/codegen/codegen.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
"github.com/glojurelang/glojure/pkg/runtime"
1313
)
1414

15+
// TODO
16+
// - handle namespace requires/uses/etc.
17+
// - handle let bindings that are shared across multiple vars
18+
1519
// varScope represents a variable allocation scope
1620
type varScope struct {
1721
nextNum int
@@ -148,10 +152,18 @@ func (g *Generator) generateVar(nsVariableName string, name *lang.Symbol, vr *la
148152
}
149153

150154
// check if the var has a value
155+
varVar := g.allocateVar("var")
151156
if vr.IsBound() {
152-
g.writef("%s.InternWithValue(%s, %s, true)\n", nsVariableName, varSym, g.generateValue(vr.Get()))
157+
g.writef("%s := %s.InternWithValue(%s, %s, true)\n", varVar, nsVariableName, varSym, g.generateValue(vr.Get()))
153158
} else {
154-
g.writef("%s.Intern(%s)\n", nsVariableName, varSym)
159+
g.writef("%s := %s.Intern(%s)\n", varVar, nsVariableName, varSym)
160+
}
161+
162+
// Set metadata on the var if the symbol has metadata
163+
if meta != nil {
164+
g.writef("if %s.Meta() != nil {\n", varSym)
165+
g.writef("\t%s.SetMeta(%s.Meta().(lang.IPersistentMap))\n", varVar, varSym)
166+
g.writef("}\n")
155167
}
156168

157169
return nil

pkg/codegen/codegengotest/codegengo_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package codegentest
1+
package codegengotest
22

33
import (
44
"io/ioutil"
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
_ "github.com/glojurelang/glojure/pkg/codegen/testdata/codegen/test"
11+
_ "github.com/glojurelang/glojure/pkg/glj"
1112
"github.com/glojurelang/glojure/pkg/lang"
1213
)
1314

pkg/codegen/testdata/codegen/test/const_keyword.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codegen/testdata/codegen/test/const_number.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codegen/testdata/codegen/test/const_string.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codegen/testdata/codegen/test/def_simple.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/codegen/testdata/codegen/test/loop_simple.go

Lines changed: 38 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)