summaryrefslogtreecommitdiff
path: root/starts/meaning-vm
diff options
context:
space:
mode:
Diffstat (limited to 'starts/meaning-vm')
-rw-r--r--starts/meaning-vm/level-1/baseref.hpp2
-rw-r--r--starts/meaning-vm/level-1/common.hpp2
-rw-r--r--starts/meaning-vm/level-1/concepts.cpp10
-rw-r--r--starts/meaning-vm/level-1/concepts.hpp17
-rw-r--r--starts/meaning-vm/level-2/concepts.hpp1
-rw-r--r--starts/meaning-vm/level-2/habits.cpp18
-rw-r--r--starts/meaning-vm/level-2/habits.hpp2
-rw-r--r--starts/meaning-vm/level-2/sugar.hpp21
-rw-r--r--starts/meaning-vm/level2.cpp29
9 files changed, 53 insertions, 49 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp
index 59550dd..93e18ae 100644
--- a/starts/meaning-vm/level-1/baseref.hpp
+++ b/starts/meaning-vm/level-1/baseref.hpp
@@ -58,7 +58,7 @@ private:
{
std::initializer_list<ref const *>({&args...});
f(args...);
- return concepts::nothing;
+ return "nothing";
};
}
};
diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp
index 9e19760..73de3b4 100644
--- a/starts/meaning-vm/level-1/common.hpp
+++ b/starts/meaning-vm/level-1/common.hpp
@@ -10,7 +10,5 @@ using level0::concept;
template <typename T> struct baseref;
struct ref;
-namespace concepts { extern ref nothing; extern ref name; }
-
}
}
diff --git a/starts/meaning-vm/level-1/concepts.cpp b/starts/meaning-vm/level-1/concepts.cpp
index be643a9..08d645a 100644
--- a/starts/meaning-vm/level-1/concepts.cpp
+++ b/starts/meaning-vm/level-1/concepts.cpp
@@ -14,16 +14,6 @@ static struct init { init() {
givename(intellect::level0::concepts::level0allocations(), "level0-allocations");
} } __init;
-ref level1("level1"), allocations("allocations");
-ref is("is", level1-allocations);
-ref name("name", level1-allocations);
-ref nothing("nothing", level1-allocations);
-ref anonymous("anonymous", level1-allocations);
-ref link("link", level1-allocations);
-ref level0("level0", level1-allocations) , level2("level2", level1-allocations) , level3("level3", level1-allocations) , level4("level4", level1-allocations) , level5("level5", level1-allocations) , level6("level6", level1-allocations) , level7("level7", level1-allocations) , level8("level8", level1-allocations) , level9("level9", level1-allocations);
-ref allocator("allocator"), allocates("allocates");
-
-ref _false("false", level1-allocations), _true("true", level1-allocations);
}
}
diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp
index cd92f26..2b460d6 100644
--- a/starts/meaning-vm/level-1/concepts.hpp
+++ b/starts/meaning-vm/level-1/concepts.hpp
@@ -7,13 +7,16 @@ namespace level1 {
namespace concepts {
-extern ref nothing; // default value of a ref
-extern ref name; // used as the link to value<std::string> naming each concept
-extern ref is; // a link to define group relationships, links to the more general class
-extern ref anonymous; // a group given concepts with generated names
-extern ref link; // TODO: for concepts that are links, link them with is=link
-extern ref level0, level1, level2, level3, level4, level5, level6, level7, level8, level9, level10;
-extern ref allocator, allocates, allocations;
+static ref level1("level1"), allocations("allocations");
+static ref is("is", level1-allocations); // a link to define group relationships, links to the more general class
+static ref name("name", level1-allocations); // used as the link to value<std::string> naming each concept
+static ref nothing("nothing", level1-allocations); // default value of a ref
+static ref anonymous("anonymous", level1-allocations); // a group given concepts with generated names
+static ref link("link", level1-allocations); // TODO: for concepts that are links, link them with is=link
+static ref level0("level0", level1-allocations) , level2("level2", level1-allocations) , level3("level3", level1-allocations) , level4("level4", level1-allocations) , level5("level5", level1-allocations) , level6("level6", level1-allocations) , level7("level7", level1-allocations) , level8("level8", level1-allocations) , level9("level9", level1-allocations);
+static ref allocator("allocator"), allocates("allocates");
+
+static ref _false("false", level1-allocations), _true("true", level1-allocations);
//extern ref true, false; <-- casting provides as if these were declared
diff --git a/starts/meaning-vm/level-2/concepts.hpp b/starts/meaning-vm/level-2/concepts.hpp
index 57f5adb..c511906 100644
--- a/starts/meaning-vm/level-2/concepts.hpp
+++ b/starts/meaning-vm/level-2/concepts.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "ref.hpp"
+#include "../level-1/concepts.hpp"
namespace intellect {
namespace level2 {
diff --git a/starts/meaning-vm/level-2/habits.cpp b/starts/meaning-vm/level-2/habits.cpp
index f0ef9b8..1891ec5 100644
--- a/starts/meaning-vm/level-2/habits.cpp
+++ b/starts/meaning-vm/level-2/habits.cpp
@@ -46,7 +46,7 @@ void contextmapinto(ref c1, ref m, ref c2)
}
}
-int createhabits()
+void createhabits()
{
// making new information should delay, for learning with good curve.
decls(link, source, type, target);
@@ -413,6 +413,7 @@ int createhabits()
});
decls(order, steps);
+ // make steps doesn't allow for name, and isn't used in level2.cpp <====
ahabit(make-steps, ((information-order, io, nothing)),
{
result = makeconcept();
@@ -514,7 +515,7 @@ int createhabits()
// because this sets active-state's next-step instead of calling something,
// a subcontext is not opened for the steps unless they have one.
ref next = nothing;
- if (!linked(steps, cond)) {
+ if (!steps.linked(cond)) {
if (linked(steps, "anything")) {
next = steps["anything"];
} else {
@@ -742,16 +743,15 @@ int createhabits()
// STUB acts on acts with actctx straight
});
*/
- return 0;
}
-void ensurehabitscreated()
-{
- static int sentinel = createhabits();
- (void)(sentinel);
-}
+//void createhabits()
+//{
+// static int sentinel = createhabits();
+// (void)(sentinel);
+//}
-static int sentinel = (ensurehabitscreated(), 1);
+//static int sentinel = (ensurehabitscreated(), 1);
}
}
diff --git a/starts/meaning-vm/level-2/habits.hpp b/starts/meaning-vm/level-2/habits.hpp
index dfc83b2..8e2f65c 100644
--- a/starts/meaning-vm/level-2/habits.hpp
+++ b/starts/meaning-vm/level-2/habits.hpp
@@ -7,7 +7,7 @@
namespace intellect {
namespace level2 {
-void ensurehabitscreated(); // for running from static code, for construction order
+void createhabits();
namespace concepts {
diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp
index f8cb61f..dee42c3 100644
--- a/starts/meaning-vm/level-2/sugar.hpp
+++ b/starts/meaning-vm/level-2/sugar.hpp
@@ -2,6 +2,8 @@
#undef self
+#include <iostream>
+
namespace intellect {
namespace level2 {
@@ -29,12 +31,12 @@ namespace sugar {
#define everyone_already_cares_deeply_about_everyone_else_so_caring_talk_is_more_efficient_than_anything_else 0
#endif
-#define ahabit(name, argnametoklist, ...) \
+#define ahabit(nam, argnametoklist, ...) \
intellect::level2::makehabit( \
- ref(#name), \
+ ref(#nam), \
{_macro_call(_macro_for_each_parens, _macro_habit_argnameref, _macro_habit_commaargnameref _macro_comma_remove_parens(argnametoklist))}, \
(std::function<void(ref)>) \
- [&](ref ctx) \
+ [=](ref ctx) mutable \
{ \
{ \
if (!everyone_already_cares_deeply_about_everyone_else_so_caring_talk_is_more_efficient_than_anything_else) { \
@@ -44,26 +46,29 @@ namespace sugar {
} \
ref self = ctx.get(ref("self")); (void)self; \
ref result("nothing"); (void)result; \
+ std::cerr << self.name(); \
_macro_call(_macro_for_each_parens, _macro_habit_set_posarg, _macro_habit_set_posarg _macro_comma_remove_parens(argnametoklist)); \
+ std::cerr << std::endl; \
__VA_ARGS__ \
if (result != ref("nothing")) { ctx.link(ref("result"), result); } \
}); \
{ \
- ref _macro_habit_name(#name); \
+ ref _macro_habit_name(#nam); \
_macro_call(_macro_for_each_parens, _macro_habit_assume, _macro_habit_assume _macro_comma_remove_parens(argnametoklist)) \
}
#define _macro_habit_argnameref(name, tok, ...) \
ref(#name)
#define _macro_habit_commaargnameref(name, tok, ...) \
, ref(#name)
- #define _macro_habit_set_posarg(name, tok, ...) \
- if ((#__VA_ARGS__)[0] == 0 && !ctx.linked(ref(#name))) { \
+ #define _macro_habit_set_posarg(nam, tok, ...) \
+ if ((#__VA_ARGS__)[0] == 0 && !ctx.linked(ref(#nam))) { \
throw an(ref("habit-context-missing-information")).link \
(ref("habit"), self, \
ref("context"), ctx, \
- ref("missing-information"), ref(#name)); \
+ ref("missing-information"), ref(#nam)); \
} \
- ref tok = ctx.linked(ref(#name)) ? ctx[ref(#name)] : ref(#__VA_ARGS__);
+ ref tok = ctx.linked(ref(#nam)) ? ctx[ref(#nam)] : ref(#__VA_ARGS__); \
+ std::cerr << " " << #nam << ":" << tok.name();
#define _macro_habit_assume(info, tok, ...) \
if ((#__VA_ARGS__)[0] != 0) { intellect::level2::habitassume(_macro_habit_name, ref(#info), ref(#__VA_ARGS__)); }
diff --git a/starts/meaning-vm/level2.cpp b/starts/meaning-vm/level2.cpp
index 386a116..e2dd8b9 100644
--- a/starts/meaning-vm/level2.cpp
+++ b/starts/meaning-vm/level2.cpp
@@ -34,7 +34,7 @@ ref makelist(std::initializer_list<ref> items)
// order here matters not. continue.
// helper function for making a codeline
-ref makestep(ref habit, ref result, std::initializer_list<ref> ins)
+ref makestep(ref habit, std::initializer_list<ref> resultandins)
{
// build needed-information-map, made-information-map, action
// then pass to make-context-action.
@@ -44,7 +44,8 @@ ref makestep(ref habit, ref result, std::initializer_list<ref> ins)
(make-next-list-entry)(mim, (make-map-item)("result", result));
}
ref infn = habit.get(information-needed);
- for (ref in : ins) {
+ bool gotresult = false;
+ for (ref in : resultandins) {
infn = infn.get(next-information);
std::string n = (name-of)(in).val<std::string>();
if (n.c_str()[0] == '`') {
@@ -73,16 +74,21 @@ ref knowisactionlist(ref src, std::initializer_list<ref> steps)
#define symboltostr(sym) #sym
#define commasymboltostr(sym) , #sym
-ref makestep(ref last, ref action, ref result, std::initializer_list<char const *> ins)
+ref makestep(ref last, ref action, std::initializer_list<char const *> resultandins)
{
ref lits = (make-concept)();
ref vars = (make-concept)();
ref outs = (make-concept)();
- if (result != nothing) {
- outs.set("result", result);
- }
ref infn = action.get(information-needed);
- for (auto str : ins) {
+ bool processedresult = false;
+ for (auto str : resultandins) {
+ if (!processedresult) {
+ if (ref(str) != nothing) {
+ outs.set("result", str);
+ }
+ processedresult = true;
+ continue;
+ }
infn = infn.get(next-information);
// need to walk needed-information
if (str[0] == '`') {
@@ -102,14 +108,14 @@ ref makestep(ref last, ref action, ref result, std::initializer_list<char const
// make functions and macros to make behaviors
#define begin(name) { ref BEHAVIOR(#name); ref last = BEHAVIOR;
#define end(nam) assert(BEHAVIOR.name() == #nam); }
-#define rewire(name) last = name
+#define rewire(name) last = name; last.unlink("next-step");
#define wire(name) last.set("next-step", name)
#define label(name) ref name =
-#define step(action, ...) last = makestep(last, ref(#action), ref("nothing"), { symbolstostrs(__VA_ARGS__) })
-#define assign(result, action, ...) last = makestep(last, ref(#action), ref(#result), { symbolstostrs(__VA_ARGS__) })
+#define step(action, ...) last = makestep(last, ref(#action), { symbolstostrs(nothing,##__VA_ARGS__) })
+#define assign(result, action, ...) last = makestep(last, ref(#action), { symbolstostrs(result,##__VA_ARGS__) })
#define jmpeq(var, cnst, label) last = ref("make-condition-action")(last, ref(#var), ref("make-concept")().link(ref(#cnst), label, ref("anything"), ref("nothing"))
#define jmpne(var, cnst, label) last = ref("make-condition-action")(last, ref(#var), ref("make-concept")().link(ref(#cnst), ref("nothing"), ref("anything"), label)
-#define cond(var) last = nothing; ref("make-condition-action")(last, ref(#var), ref("make-concept")().link(ref("anything"), ref("nothing")))
+#define cond(var) last = ref("make-condition-action")(last, ref(#var), ref("make-concept")().link(ref("anything"), ref("nothing")))
#define condadd(cond, val, step) ref("condition-action-add")(cond, ref(#val), step)
//#define ifelse(var, cnst, ifcond, elsecond)
// make sequence for ifcond
@@ -138,6 +144,7 @@ ref makestep(ref last, ref action, ref result, std::initializer_list<char const
int main()
{
+ createhabits();
decls(dump, name, of, is, nothing);
ahabit(name-of, ((concept, c)),
{