Skip to content

Commit 6c1468d

Browse files
committed
Ignore errors to generate stdlib core go
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent e3fec30 commit 6c1468d

3 files changed

Lines changed: 81822 additions & 6 deletions

File tree

pkg/codegen/codegen.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func (g *Generator) Generate(ns *lang.Namespace) error {
162162
formatted, err := format.Source(sourceBytes)
163163
if err != nil {
164164
// If formatting fails, write the unformatted code with the error
165+
g.originalWriter.Write(sourceBytes)
165166
return fmt.Errorf("formatting failed: %w\n\nGenerated code:\n%s", err, string(sourceBytes))
166167
}
167168

@@ -272,7 +273,11 @@ func (g *Generator) generateValue(value any) string {
272273
}
273274
return fmt.Sprintf("lang.NewList(%s)", strings.Join(vals, ", "))
274275
}
275-
panic(fmt.Sprintf("unsupported value type %T: %s", v, v))
276+
277+
fmt.Println("Unsupported value type:", reflect.TypeOf(v), v)
278+
return "nil"
279+
// TODO: panic
280+
//panic(fmt.Sprintf("unsupported value type %T: %s", v, v))
276281
}
277282
}
278283

@@ -675,11 +680,21 @@ func (g *Generator) generateFnMethod(methodNode *ast.FnMethodNode, argsVar strin
675680
// generateASTNode generates code for an AST node
676681
func (g *Generator) generateASTNode(node *ast.Node) string {
677682
switch node.Op {
678-
// OpDef
679-
// OpSetBang
680-
// OpLetFn
681-
// OpGo
682-
// OpCase
683+
case ast.OpDef:
684+
fmt.Println("Def not yet implemented; returning nil")
685+
return "nil"
686+
case ast.OpSetBang:
687+
fmt.Println("SetBang not yet implemented; returning nil")
688+
return "nil"
689+
case ast.OpLetFn:
690+
fmt.Println("LetFn not yet implemented; returning nil")
691+
return "nil"
692+
case ast.OpGo:
693+
fmt.Println("Go not yet implemented; returning nil")
694+
return "nil"
695+
case ast.OpCase:
696+
fmt.Println("Case not yet implemented; returning nil")
697+
return "nil"
683698
case ast.OpTry:
684699
return g.generateTry(node)
685700
case ast.OpThrow:

pkg/codegen/codegen_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ func generateAndTestNamespace(t *testing.T, ns *lang.Namespace, goldenFile strin
7979
var buf bytes.Buffer
8080
gen := codegen.New(&buf)
8181
if err := gen.Generate(ns); err != nil {
82+
if os.Getenv("UPDATE_SNAPSHOT") == "1" {
83+
// write the output anyway if we're updating the snapshot
84+
generated := buf.Bytes()
85+
if len(generated) > 0 {
86+
ioutil.WriteFile(goldenFile, generated, 0644)
87+
}
88+
}
89+
8290
t.Fatalf("failed to generate code: %v", err)
8391
}
8492

0 commit comments

Comments
 (0)