From fe51b5bb71f7eadf6072a51c31c0ffee91c815c8 Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 23 Dec 2019 13:11:16 -0800 Subject: some bugfixes --- starts/meaning-vm/habit-starts/learning-parts.cpp | 17 +++++++++-------- starts/meaning-vm/level-0/baseref.hpp | 11 +++++++++++ starts/meaning-vm/level-2/sugar.hpp | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'starts') diff --git a/starts/meaning-vm/habit-starts/learning-parts.cpp b/starts/meaning-vm/habit-starts/learning-parts.cpp index 56c7ffa..85c92c9 100644 --- a/starts/meaning-vm/habit-starts/learning-parts.cpp +++ b/starts/meaning-vm/habit-starts/learning-parts.cpp @@ -64,12 +64,13 @@ static int __init = ([]()->int{ ahabit(unlink, ((source, s), (type, t), (target, dst, anything)), { if (dst == anything) { - result = s.unlink(t); + s.unlink(t); } else { - result = s.unlink(t, dst); + s.unlink(t, dst); } }); + decls(get, set); ahabit(get, ((source, s), (type, t)), { result = s.get(t); @@ -95,7 +96,7 @@ static int __init = ([]()->int{ if (c.linked(is, group)) { throw an(already-in-group).link (habit, self, - context, ctx, + "context", ctx, concept, c, group, g); } @@ -124,8 +125,8 @@ static int __init = ([]()->int{ // need args and result for sequence //ahabit(habit-sequence, (( - decls(list, nothing, next, previous); - decls(make, add, to, until, each, item, in, remove, from, somewhere); + decls(list, nothing, next, previous, first, last, entry); + decls(add, to, until, each, item, remove, from, somewhere); // list functiona are habits because ordered-behavior // would use a list @@ -182,7 +183,7 @@ static int __init = ([]()->int{ result = get(e, item); }); - ahabit(add-to-list, ((item, i), (list, l)), + ahabit(list-add, ((list, l), (item, i)), { ref prev = (list-last-item)(l); ref li = (know-is-list-entry)( @@ -203,11 +204,11 @@ static int __init = ([]()->int{ prev.set(next, li); } }); - ahabit(list-each-entry, ((list, l), (context, c), (action, a)), + ahabit(list-each-entry, ((list, l), (context, c), (action, act)), { ref cur = l.get(first-item); while (cur != nothing && result == nothing) { - result = a(cur, context); + result = act(cur, c); cur = cur.get(next); } }); diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp index d20b22a..9244492 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -68,6 +68,17 @@ public: concept*& ptr() { return p; } concept* const & ptr() const { return p; } + operator level0::ref const &() const { return *reinterpret_cast(this); } + operator level1::ref const &() const { return *reinterpret_cast(this); } + operator level2::ref const &() const { return *reinterpret_cast(this); } + operator level3::ref const &() const { return *reinterpret_cast(this); } + operator level4::ref const &() const { return *reinterpret_cast(this); } + operator level5::ref const &() const { return *reinterpret_cast(this); } + operator level6::ref const &() const { return *reinterpret_cast(this); } + operator level7::ref const &() const { return *reinterpret_cast(this); } + operator level8::ref const &() const { return *reinterpret_cast(this); } + operator level9::ref const &() const { return *reinterpret_cast(this); } + operator level0::ref &() { return *reinterpret_cast(this); } operator level1::ref &() { return *reinterpret_cast(this); } operator level2::ref &() { return *reinterpret_cast(this); } diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp index e6d9ea4..adedaa9 100644 --- a/starts/meaning-vm/level-2/sugar.hpp +++ b/starts/meaning-vm/level-2/sugar.hpp @@ -25,7 +25,7 @@ ref(#name), \ {_macro_call(_macro_for_each_parens, _macro_habit_argnameref, _macro_habit_commaargnameref _macro_comma_remove_parens(argnametoklist))}, \ (std::function) \ - [=](ref ctx) \ + [&](ref ctx) \ { \ { \ static int delay = (double(rand()) / RAND_MAX * 400000 + 200000); \ -- cgit v1.2.3