Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions gen_sort_variants.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module main

import os

struct Variant {
// name is the variant name: should be unique among variants.
name string
// Path is the file path into which the generator will emit the code for this
// variant.
path string
// @module is the @module this code will be emitted into.
@module string
// fn_suffix is appended to all function names in this variant's code. All
// suffixes should be unique within a @module.
fn_suffix string
// data_type is the type of the data parameter of functions in this variant's
// code.
data_type string
}

fn main() {
generate(Variant{
name: 'interface'
path: 'zsortinterface.v'
@module: 'sort'
data_type: 'Interface'
})
generate(Variant{
name: 'func'
path: 'zsortfunction.v'
@module: 'sort'
fn_suffix: '_fn'
data_type: 'LessSwap'
})
}

fn generate(v Variant) {
variant := v
text := $tmpl('sort.tmpl')
os.write_file(os.resource_abs_path(v.path), text) or { panic(err) }
}
Loading