summaryrefslogtreecommitdiff
path: root/starts/meaning-vm
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-20 09:01:21 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-20 09:01:21 -0800
commitdb94af675ccfb34885000e3d97947557cebb66f3 (patch)
tree39b00bbae4a215d8a5ca7736f13ecfb76daac5ee /starts/meaning-vm
parent98998d74f7a2cebb1d54cd5a7f0cf1b7da66b829 (diff)
downloadstandingwithresilience-db94af675ccfb34885000e3d97947557cebb66f3.tar.gz
standingwithresilience-db94af675ccfb34885000e3d97947557cebb66f3.zip
habit macros can use default arguments now
Diffstat (limited to 'starts/meaning-vm')
-rw-r--r--starts/meaning-vm/habit-starts/rhythm.cpp8
-rw-r--r--starts/meaning-vm/level-2/funcs.hpp1
-rw-r--r--starts/meaning-vm/level-2/sugar.hpp14
3 files changed, 15 insertions, 8 deletions
diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp
index c476006..72626d6 100644
--- a/starts/meaning-vm/habit-starts/rhythm.cpp
+++ b/starts/meaning-vm/habit-starts/rhythm.cpp
@@ -52,12 +52,12 @@ int main()
}
});
- ahabit(start-beat, (),
+ ahabit(start-beat, ((wait-habit, w, wait-habit), (beat-habit, b, beat-habit)),
{
ctx.vset(beat, int(0));
- self.set(next, wait-habit);
- (beat-habit).set(next, wait-habit);
- (wait-habit).set(next, beat-habit);
+ self.set(next, w);
+ (b).set(next, w);
+ (w).set(next, b);
});
ahabit(beat-habit, (),
{
diff --git a/starts/meaning-vm/level-2/funcs.hpp b/starts/meaning-vm/level-2/funcs.hpp
index 85e1af8..65290fb 100644
--- a/starts/meaning-vm/level-2/funcs.hpp
+++ b/starts/meaning-vm/level-2/funcs.hpp
@@ -9,6 +9,7 @@ namespace intellect {
namespace level2 {
ref & context();
+// TODO: pass default argument values to makehabit?
ref makehabit(ref name, std::initializer_list<ref> argnames, std::function<void(ref)> code);
ref dohabit(ref habit, std::initializer_list<ref> args);
ref dohabit(ref habit, std::initializer_list<std::initializer_list<ref>> args = {});
diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp
index b44b282..9065a20 100644
--- a/starts/meaning-vm/level-2/sugar.hpp
+++ b/starts/meaning-vm/level-2/sugar.hpp
@@ -37,12 +37,18 @@
__VA_ARGS__ \
if (result != ref("nothing")) { ctx.link(ref("result"), result); } \
});
- #define _macro_habit_argnameref(name, tok) \
+ #define _macro_habit_argnameref(name, tok, ...) \
ref(#name)
- #define _macro_habit_commaargnameref(name, tok) \
+ #define _macro_habit_commaargnameref(name, tok, ...) \
, ref(#name)
- #define _macro_habit_set_posarg(name, tok) \
- ref tok = ctx[ref(#name)];
+ #define _macro_habit_set_posarg(name, tok, ...) \
+ if ((#__VA_ARGS__)[0] == 0 && !ctx.linked(ref(#name))) { \
+ throw an(ref("habit-context-missing-information")).link \
+ (ref("habit"), self, \
+ ref("context"), ctx, \
+ ref("missing-information"), ref(#name)); \
+ } \
+ ref tok = ctx.linked(ref(#name)) ? ctx[ref(#name)] : ref(#__VA_ARGS__);
// seed random number generator statically, for habit delay
namespace _macro_habit {