Skip to content

objects.h

tanazd1 edited this page Apr 5, 2026 · 3 revisions

🧩 C Objects Language Specification

1. Introduction

1.1 Purpose

1.1.1 Overview

objects.h defines a macro-based system that enables structured object-like constructs in C.

1.1.2 Design Goal

  • Provide object-style abstraction
  • Remain compatible with standard C
  • Avoid dynamic allocation

2. Terminology

2.1 Object

2.1.1 Definition

An Object is a statically allocated structure containing:

  • Identifier (name)
  • Line storage
  • Key-value storage
  • Execution function

2.2 Line

2.2.1 Definition

A Line is a null-terminated string stored in a fixed buffer.


2.3 Key-Value Pair

2.3.1 Definition

A KV Pair is a mapping:

string → string

2.4 Command

2.4.1 Definition

A function pointer attached to an object, executed via runtime macros.


3. Object Model

3.1 Structure Layout

3.1.1 ObjKV

typedef struct ObjKV {
    char key[64];
    char value[256];
} ObjKV;

3.1.2 Obj

typedef struct Obj {
    char name[50];

    char lines[MAX_OBJ_LINES][MAX_LINE_LEN];
    int line_count;

    ObjKV kvs[MAX_OBJ_KV];
    int kv_count;

    void (*run)(struct Obj*, int argc, char** argv);
} Obj;

3.2 Memory Model

3.2.1 Allocation

  • Objects are statically allocated
  • No heap allocation

3.2.2 Lifetime

  • Exists for entire program duration

3.3 Capacity Constraints

3.3.1 Lines

  • Maximum: 1024
  • Max length: 256 chars

3.3.2 Key-Values

  • Maximum: 128

4. Syntax Specification


4.1 Object Declaration

4.1.1 Syntax

obj(name) {
    statements
}

4.1.2 Expansion

4.1.2.1 Generated Symbol
Obj obj_<name>;
4.1.2.2 Initialization
  • name set to string
  • counters initialized to zero
  • run pointer set to NULL

4.1.3 Execution Model

4.1.3.1 Macro Expansion Trick
for (Obj* _obj_ptr = &obj_<name>; _obj_ptr; _obj_ptr = NULL)
Behavior
  • Executes exactly once
  • Provides scoped pointer _obj_ptr

5. Statements


5.1 line()

5.1.1 Syntax

line("text");

5.1.2 Semantics

  • Copies string into lines[]
  • Increments line_count

5.1.3 Constraints

  • Must not exceed buffer size
  • Silent truncation possible

5.2 kvs()

5.2.1 Syntax

kvs("key", "value");

5.2.2 Semantics

  • Stores key-value pair
  • Increments kv_count

5.2.3 Data Type

string → string only

5.3 cmd()

5.3.1 Syntax

cmd(function);

5.3.2 Semantics

  • Assigns function pointer

5.3.3 Function Signature

void function(Obj* obj, int argc, char** argv);

6. Object Extension


6.1 objadd()

6.1.1 Syntax

objadd(name) {
    statements
}

6.1.2 Semantics

  • Reopens object
  • Appends data

7. Execution Model


7.1 objrune()

7.1.1 Syntax

objrune(name, "arg1", "arg2");

7.1.2 Semantics

  • Constructs argument array
  • Computes argc
  • Calls run function

7.2 objrunve()

7.2.1 Syntax

objrunve(name, argv);

7.2.2 Semantics

  • Passes argv directly
  • Sets argc = 0

7.2.3 Limitation

  • argc is not computed

7.3 Aliases

7.3.1 Mapping

objrunvp  → objrunve
objrunvpe → objrunve
objrunpe  → objrunve

8. Data Access Model


8.1 Line Access

o->lines[i]

8.2 KV Access

o->kvs[i].key
o->kvs[i].value

8.3 Lookup Strategy

8.3.1 Linear Search

for (...) {
    if (strcmp(...) == 0)
}

9. Error Handling

9.1 Behavior

  • No runtime error reporting
  • Silent failures possible

10. Safety Considerations

10.1 Buffer Overflow Risk

  • Limited protection via strncpy
  • No explicit null termination guarantee

10.2 Thread Safety

  • Not thread-safe

11. Limitations

11.1 Structural

  • Fixed-size buffers
  • No dynamic allocation

11.2 Type System

  • No type safety
  • Strings only

11.3 Execution

  • No scheduler
  • No async execution

12. Implementation Notes

12.1 Macro Expansion

  • All features implemented via macros
  • No runtime parsing

12.2 Compilation

  • Fully compatible with standard C compilers

13. Example

obj(test) {
    line("Hello");
    kvs("key", "value");
}

14. Summary

14.1 Definition

Object = Static Struct + Macro DSL + Function Pointer

15. Future Extensions (Non-normative)

15.1 Possible Enhancements

  • Typed KV system
  • Dynamic allocation
  • Object inheritance
  • Runtime loader

16. Navigation

Objects Tool

🧩 Objects Tool Wiki

Clone this wiki locally