Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ SRCS = src/kernel/cogdiod_kernel.c \
packages/not_link/not_link_pkg.c \
packages/equivalence_link/equivalence_link_pkg.c \
packages/list_link/list_link_pkg.c \
packages/bind_link/bind_link_pkg.c
packages/bind_link/bind_link_pkg.c \
packages/execution_link/execution_link_pkg.c \
packages/context_link/context_link_pkg.c \
packages/predictive_implication_link/predictive_implication_link_pkg.c \
packages/at_time_link/at_time_link_pkg.c \
packages/time_node/time_node_pkg.c \
packages/grounded_schema_node/grounded_schema_node_pkg.c \
packages/grounded_predicate_node/grounded_predicate_node_pkg.c

TEST_SRC = tests/test_cogdiod.c
UNIT_TESTS = tests/test_pln.c tests/test_elm_loader.c \
Expand Down
11 changes: 11 additions & 0 deletions include/elbo_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@
* Returns NULL on allocation failure.
*/
ElmPackage* elbo_compile(const char* source, const char* type_name);

/*
* elbo_compile_file — compile an Elbo source file to an .elm package file.
* (Phase 4.6)
*
* Reads source from src_path, compiles it with elbo_compile(), and writes
* the resulting package to out_path using elm_save().
*
* Returns 0 on success, -1 on failure.
*/
int elbo_compile_file(const char* src_path, const char* out_path);
1 change: 1 addition & 0 deletions include/elm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ typedef struct {

ElmPackage* elm_build_stub(const ElmStubDef* def);
int elm_save(const ElmPackage* pkg, const char* path);
ElmPackage* elm_load_file(const char* path);
int elm_exec_init(AtomIsolate* a);
int elm_exec_msg(AtomIsolate* a, const CogMessage* msg);
62 changes: 62 additions & 0 deletions packages/at_time_link/at_time_link_pkg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* at_time_link_pkg.c — C stub package for AtTimeLink (Phase 2.13)
*
* AtTimeLink represents an event at a specific timestamp.
* Structure: AtTimeLink(Event, TimeNode)
* The timestamp is stored in the TimeNode; LTI encodes temporal decay.
*
* Behaviour:
* init: Initialize with current timestamp
* on-message: MSG_QUERY returns time-stamped event; MSG_SOURCE_CHANGED propagates
* on-gc: Cleanup temporal data
*/

#include "cogdiod.h"
#include "elm_types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ── Bytecode sequences ───────────────────────────────────────────────── */

static const uint8_t at_time_init_bc[] = {
OP_GET_TV,
OP_SET_TV,
/* Set LTI based on timestamp recency */
OP_GET_STI,
OP_HALT
};

/*
* on-message:
* - MSG_QUERY: Return the event with its timestamp
* - MSG_SOURCE_CHANGED: Update temporal relevance
*/
static const uint8_t at_time_msg_bc[] = {
OP_GET_TV,
/* Temporal decay based on distance from current time */
OP_PLN_REV, /* Revise with temporal decay */
OP_SET_TV,
OP_ECAN_SP,
OP_HALT
};

static const uint8_t at_time_gc_bc[] = {
OP_NOP,
OP_HALT
};

/* ── Package builder ──────────────────────────────────────────────────── */

ElmPackage* at_time_link_build_package(void) {
ElmStubDef def = {
.type_name = "AtTimeLink",
.init_bc = at_time_init_bc,
.init_bc_len = sizeof(at_time_init_bc),
.msg_bc = at_time_msg_bc,
.msg_bc_len = sizeof(at_time_msg_bc),
.gc_bc = at_time_gc_bc,
.gc_bc_len = sizeof(at_time_gc_bc),
};
return elm_build_stub(&def);
}
61 changes: 61 additions & 0 deletions packages/context_link/context_link_pkg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* context_link_pkg.c — C stub package for ContextLink (Phase 2.11)
*
* ContextLink provides scoped evaluation context. It wraps a child link
* with a context atom that defines the evaluation environment.
* Structure: ContextLink(ContextAtom, ChildLink)
*
* Behaviour:
* init: Initialize context bindings
* on-message: MSG_INFER evaluates child in context; MSG_SOURCE_CHANGED propagates
* on-gc: Cleanup context
*/

#include "cogdiod.h"
#include "elm_types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ── Bytecode sequences ───────────────────────────────────────────────── */

static const uint8_t context_init_bc[] = {
OP_GET_TV,
OP_SET_TV,
OP_HALT
};

/*
* on-message:
* - MSG_INFER: Evaluate the child link in the context defined by context atom
* - MSG_SOURCE_CHANGED: Propagate changes with context-modified TV
*/
static const uint8_t context_msg_bc[] = {
OP_GET_TV,
/* Get context TV from first outgoing (context atom) */
/* Combine with child TV from second outgoing */
OP_PLN_REV, /* Context-weighted revision */
OP_SET_TV,
OP_ECAN_SP,
OP_HALT
};

static const uint8_t context_gc_bc[] = {
OP_NOP,
OP_HALT
};

/* ── Package builder ──────────────────────────────────────────────────── */

ElmPackage* context_link_build_package(void) {
ElmStubDef def = {
.type_name = "ContextLink",
.init_bc = context_init_bc,
.init_bc_len = sizeof(context_init_bc),
.msg_bc = context_msg_bc,
.msg_bc_len = sizeof(context_msg_bc),
.gc_bc = context_gc_bc,
.gc_bc_len = sizeof(context_gc_bc),
};
return elm_build_stub(&def);
}
58 changes: 58 additions & 0 deletions packages/execution_link/execution_link_pkg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* execution_link_pkg.c — C stub package for ExecutionLink (Phase 2.10)
*
* ExecutionLink triggers GroundedSchemaNode.execute() on MSG_INFER.
* Structure: ExecutionLink(GroundedSchemaNode, ListLink of arguments)
*
* Behaviour:
* init: Initialize execution context
* on-message: MSG_INFER triggers schema execution; MSG_SOURCE_CHANGED propagates
* on-gc: Cleanup any execution context
*/

#include "cogdiod.h"
#include "elm_types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ── Bytecode sequences ───────────────────────────────────────────────── */

static const uint8_t execution_init_bc[] = {
OP_GET_TV,
OP_SET_TV,
OP_HALT
};

/*
* on-message:
* - On MSG_INFER (0x03): Send MSG_INFER to the GroundedSchemaNode (first outgoing)
* - On MSG_SOURCE_CHANGED: Re-spread attention and propagate
*/
static const uint8_t execution_msg_bc[] = {
/* Check message type and trigger execution */
OP_GET_TV,
OP_SEND, /* Send to schema node to trigger execution */
OP_ECAN_SP, /* Spread attention */
OP_HALT
};

static const uint8_t execution_gc_bc[] = {
OP_NOP,
OP_HALT
};

/* ── Package builder ──────────────────────────────────────────────────── */

ElmPackage* execution_link_build_package(void) {
ElmStubDef def = {
.type_name = "ExecutionLink",
.init_bc = execution_init_bc,
.init_bc_len = sizeof(execution_init_bc),
.msg_bc = execution_msg_bc,
.msg_bc_len = sizeof(execution_msg_bc),
.gc_bc = execution_gc_bc,
.gc_bc_len = sizeof(execution_gc_bc),
};
return elm_build_stub(&def);
}
60 changes: 60 additions & 0 deletions packages/grounded_predicate_node/grounded_predicate_node_pkg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* grounded_predicate_node_pkg.c — C stub package for GroundedPredicateNode (Phase 2.15)
*
* GroundedPredicateNode is a callable atom that evaluates external predicates.
* Similar to GroundedSchemaNode but returns a boolean/TV result.
*
* Behaviour:
* init: Register predicate function pointer
* on-message: MSG_INFER evaluates predicate and returns TV result
* on-gc: Unregister from predicate table
*/

#include "cogdiod.h"
#include "elm_types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ── Bytecode sequences ───────────────────────────────────────────────── */

static const uint8_t predicate_gnd_init_bc[] = {
OP_GET_TV,
OP_SET_TV,
OP_HALT
};

/*
* on-message:
* - MSG_INFER: Evaluate the grounded predicate
* Returns TV where strength indicates truth value (0.0 = false, 1.0 = true)
* and confidence indicates certainty of evaluation
*/
static const uint8_t predicate_gnd_msg_bc[] = {
OP_GET_TV,
/* Predicate evaluation would happen here */
OP_NOP, /* Placeholder for CALL to grounded predicate */
OP_SET_TV, /* Store evaluation result */
OP_SEND, /* Send result to caller */
OP_HALT
};

static const uint8_t predicate_gnd_gc_bc[] = {
OP_NOP,
OP_HALT
};

/* ── Package builder ──────────────────────────────────────────────────── */

ElmPackage* grounded_predicate_node_build_package(void) {
ElmStubDef def = {
.type_name = "GroundedPredicateNode",
.init_bc = predicate_gnd_init_bc,
.init_bc_len = sizeof(predicate_gnd_init_bc),
.msg_bc = predicate_gnd_msg_bc,
.msg_bc_len = sizeof(predicate_gnd_msg_bc),
.gc_bc = predicate_gnd_gc_bc,
.gc_bc_len = sizeof(predicate_gnd_gc_bc),
};
return elm_build_stub(&def);
}
67 changes: 67 additions & 0 deletions packages/grounded_schema_node/grounded_schema_node_pkg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* grounded_schema_node_pkg.c — C stub package for GroundedSchemaNode (Phase 2.15)
*
* GroundedSchemaNode is a callable atom that executes external code.
* It stores a function pointer (via kernel_ref) and a registration table entry.
*
* The ep_init stores the function reference; ep_on_message dispatches
* MSG_INFER to execute the grounded schema with its arguments.
*
* Behaviour:
* init: Register function pointer in kernel's schema table
* on-message: MSG_INFER executes the schema, returns result TV
* on-gc: Unregister from schema table
*/

#include "cogdiod.h"
#include "elm_types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ── Bytecode sequences ───────────────────────────────────────────────── */

static const uint8_t schema_init_bc[] = {
OP_GET_TV,
OP_SET_TV,
/* kernel_ref would be set to function pointer by spawn caller */
OP_HALT
};

/*
* on-message:
* - MSG_INFER: Execute the grounded schema
* In a real implementation, this would:
* 1. Load arguments from the incoming ExecutionLink
* 2. Call the registered C function via kernel_ref
* 3. Store result in regs and return as TV
*/
static const uint8_t schema_msg_bc[] = {
OP_GET_TV,
/* Execution would happen here via kernel callback */
OP_NOP, /* Placeholder for CALL to grounded function */
OP_SET_TV, /* Store execution result */
OP_SEND, /* Send result to caller */
OP_HALT
};

static const uint8_t schema_gc_bc[] = {
/* Unregister from schema table */
OP_NOP,
OP_HALT
};

/* ── Package builder ──────────────────────────────────────────────────── */

ElmPackage* grounded_schema_node_build_package(void) {
ElmStubDef def = {
.type_name = "GroundedSchemaNode",
.init_bc = schema_init_bc,
.init_bc_len = sizeof(schema_init_bc),
.msg_bc = schema_msg_bc,
.msg_bc_len = sizeof(schema_msg_bc),
.gc_bc = schema_gc_bc,
.gc_bc_len = sizeof(schema_gc_bc),
};
return elm_build_stub(&def);
}
Loading
Loading