diff --git a/examples/game_of_life/automaton/automaton.v b/examples/game_of_life/automaton/automaton.v new file mode 100644 index 0000000000..5664439b6c --- /dev/null +++ b/examples/game_of_life/automaton/automaton.v @@ -0,0 +1,114 @@ +module automaton + +///////////////////////////////////////////////////////////// + +pub struct A2D { +pub mut: + maxx int + maxy int + data &int +} +[inline] pub fn (a &A2D) set(x,y int, newval int) { + unsafe { + mut e := &int(0) + e = a.data + y*a.maxx + x + *e = newval + } +} +[inline] pub fn (a &A2D) get(x,y int) int { + unsafe { + mut e := &int(0) + e = a.data + y*a.maxx + x + return *e + } +} +[inline] pub fn (a &A2D) clear() { + for y := 0; y 'VROOT/vlib/strings' // 'installed_mod' => '~/.vmodules/installed_mod' // 'local_mod' => '/path/to/current/dir/local_mod' fn (v &V) find_module_path(mod string) ?string { + // Module search order: + // 1) search in the *same* directory, as the compiled final v program source + // (i.e. the . in `v .` or file.v in `v file.v`) + // 2) search in the current work dir (this preserves existing behaviour) + // 3) search in vlib/ + // 4) search in ~/.vmodules/ (i.e. modules installed with vpm) mod_path := v.module_path(mod) - // First check for local modules in the same directory - mut import_path := os.getwd() + '${os.path_separator}$mod_path' - // Now search in vlib/ - if mod == 'compiler' || !os.dir_exists(import_path) { - import_path = '${v.pref.vlib_path}${os.path_separator}$mod_path' - } - //println('ip=$import_path') - // Finally try modules installed with vpm (~/.vmodules) - if !os.dir_exists(import_path) { - import_path = '${v.pref.vpath}${os.path_separator}$mod_path' - if !os.dir_exists(import_path){ - return error('module "$mod" not found') + mut tried_paths := []string + tried_paths << filepath.join(v.compiled_dir, mod_path) + tried_paths << filepath.join(os.getwd(), mod_path) + tried_paths << filepath.join(v.pref.vlib_path, mod_path) + tried_paths << filepath.join(v_modules_path, mod_path) + for try_path in tried_paths { + if v.pref.is_verbose { println(' >> trying to find $mod in $try_path ...') } + if os.dir_exists(try_path) { + return try_path } } - return import_path + return error('module "$mod" not found') } [inline] fn mod_gen_name(mod string) string {