Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for dynamic namespace #36

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions extractor/lean_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func ExportGadgets(exGadgets []ExGadget) string {
return strings.Join(gadgets, "\n\n")
}

func ExportCircuit(circuit ExCircuit) string {
func ExportCircuit(circuit ExCircuit, name string) string {
gadgets := ExportGadgets(circuit.Gadgets)
circ := fmt.Sprintf("def circuit %s: Prop :=\n%s", genArgs(circuit.Inputs), genCircuitBody(circuit))
prelude := ExportPrelude(circuit.Name, circuit.Field.ScalarField())
footer := ExportFooter(circuit.Name)
prelude := ExportPrelude(name, circuit.Field.ScalarField())
footer := ExportFooter(name)
return fmt.Sprintf("%s\n\n%s\n\n%s\n\n%s", prelude, gadgets, circ, footer)
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func getStructName(circuit any) string {
return reflect.TypeOf(circuit).Elem().Name()
}

func CircuitToLean(circuit abstractor.Circuit, field ecc.ID) (string, error) {
func CircuitToLeanWithName(circuit abstractor.Circuit, field ecc.ID, namespace string) (string, error) {
schema, err := GetSchema(circuit)
if err != nil {
return "", err
Expand Down Expand Up @@ -211,25 +211,34 @@ func CircuitToLean(circuit abstractor.Circuit, field ecc.ID) (string, error) {
Field: api.Field,
Name: name,
}
out := ExportCircuit(extractorCircuit)
out := ExportCircuit(extractorCircuit, namespace)
return out, nil
}

func GadgetToLean(circuit abstractor.GadgetDefinition, field ecc.ID) (string, error) {
func CircuitToLean(circuit abstractor.Circuit, field ecc.ID) (string, error) {
name := getStructName(circuit)
return CircuitToLeanWithName(circuit, field, name)
}

func GadgetToLeanWithName(circuit abstractor.GadgetDefinition, field ecc.ID, namespace string) (string, error) {
api := CodeExtractor{
Code: []App{},
Gadgets: []ExGadget{},
Field: field,
}
name := getStructName(circuit)

api.DefineGadget(circuit)
gadgets := ExportGadgets(api.Gadgets)
prelude := ExportPrelude(name, api.Field.ScalarField())
footer := ExportFooter(name)
prelude := ExportPrelude(namespace, api.Field.ScalarField())
footer := ExportFooter(namespace)
return fmt.Sprintf("%s\n\n%s\n\n%s", prelude, gadgets, footer), nil
}

func GadgetToLean(circuit abstractor.GadgetDefinition, field ecc.ID) (string, error) {
name := getStructName(circuit)
return GadgetToLeanWithName(circuit, field, name)
}

func genNestedArrays(a ExArgType) string {
if a.Type != nil {
return fmt.Sprintf("Vector (%s) %d", genNestedArrays(*a.Type), a.Size)
Expand Down