summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--examples/plugin_hello_world.py10
-rw-r--r--ranger/ext/cached_function.py20
2 files changed, 15 insertions, 15 deletions
diff --git a/examples/plugin_hello_world.py b/examples/plugin_hello_world.py
index 187f428e..e43eb61d 100644
--- a/examples/plugin_hello_world.py
+++ b/examples/plugin_hello_world.py
@@ -11,11 +11,11 @@ old_hook_ready = ranger.api.hook_ready
 
 # Create a replacement for the hook that...
 def hook_ready(fm):
-  # ...does the desired action...
-  fm.notify("Hello World")
-  # ...and calls the saved hook.  If you don't care about the return value, simply
-  # return the return value of the previous hook to be on the safe side.
-  return old_hook_ready(fm)
+    # ...does the desired action...
+    fm.notify("Hello World")
+    # ...and calls the saved hook.  If you don't care about the return value,
+    # simply return the return value of the previous hook to be safe.
+    return old_hook_ready(fm)
 
 # Finally, "monkey patch" the existing hook_ready function with our replacement:
 ranger.api.hook_ready = hook_ready
diff --git a/ranger/ext/cached_function.py b/ranger/ext/cached_function.py
index bbd6d2d4..daee6397 100644
--- a/ranger/ext/cached_function.py
+++ b/ranger/ext/cached_function.py
@@ -2,14 +2,14 @@
 # This software is distributed under the terms of the GNU GPL version 3.
 
 def cached_function(fnc):
-  cache = {}
-  def inner_cached_function(*args):
-    try:
-      return cache[args]
-    except:
-      value = fnc(*args)
-      cache[args] = value
-      return value
-  inner_cached_function._cache = cache
-  return inner_cached_function
+    cache = {}
+    def inner_cached_function(*args):
+        try:
+            return cache[args]
+        except:
+            value = fnc(*args)
+            cache[args] = value
+            return value
+    inner_cached_function._cache = cache
+    return inner_cached_function
 
k with names' href='/akkartik/mu/commit/047global.cc?h=hlt&id=dfc6e268c7685e7ea5f5cdb434e62e63d2d7c915'>dfc6e268 ^
385d3080 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75










                                                                            
                                                        

                                                         



















                                                                      

                                                                                       











                                                                          

















                                                                      

                                  
                                          

                                                                            
                                                                                               


               
// So far we have local variables, and we can nest local variables of short
// lifetimes inside longer ones. Now let's support 'global' variables that
// last for the life of a routine. If we create multiple routines they won't
// have access to each other's globals.

:(scenario global_space)
recipe main [
  # pretend arrays; in practice we'll use new
  10:number <- copy 5:literal
  20:number <- copy 5:literal
  # actual start of this recipe
  global-space:address:array:location <- copy 20:literal
  default-space:address:array:location <- copy 10:literal
  1:number <- copy 23:literal
  1:number/space:global <- copy 24:literal
]
+mem: storing 23 in location 12
+mem: storing 24 in location 22

//: to support it, create another special variable called global space
:(before "End Disqualified Reagents")
if (x.name == "global-space")
  x.initialized = true;
:(before "End is_special_name Cases")
if (s == "global-space") return true;

//: writes to this variable go to a field in the current routine
:(before "End routine Fields")
long long int global_space;
:(before "End routine Constructor")
global_space = 0;
:(after "void write_memory(reagent x, vector<double> data)")
  if (x.name == "global-space") {
    assert(scalar(data));
    if (Current_routine->global_space)
      raise << "routine already has a global-space; you can't over-write your globals";
    Current_routine->global_space = data.at(0);
    return;
  }

//: now marking variables as /space:global looks them up inside this field
:(after "long long int space_base(const reagent& x)")
  if (is_global(x)) {
    if (!Current_routine->global_space)
      raise << "routine has no global space\n" << die();
    return Current_routine->global_space;
  }

//: for now let's not bother giving global variables names.
//: don't want to make them too comfortable to use.

:(scenario global_space_with_names)
% Hide_warnings = true;
recipe main [
  global-space:address:array:location <- new location:type, 10:literal
  x:number <- copy 23:literal
  1:number/space:global <- copy 24:literal
]
# don't warn that we're mixing numeric addresses and names
$warn: 0

:(after "bool is_numeric_location(const reagent& x)")
  if (is_global(x)) return false;

//: helpers

:(code)
bool is_global(const reagent& x) {
//?   cerr << x.to_string() << '\n'; //? 1
  for (long long int i = /*skip name:type*/1; i < SIZE(x.properties); ++i) {
    if (x.properties.at(i).first == "space")
      return !x.properties.at(i).second.empty() && x.properties.at(i).second.at(0) == "global";
  }
  return false;
}