Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Data and Execution

kevinlawler edited this page · 26 revisions

Data

typedef struct k0{I c,t,n;struct k0*k[1];}*K; //main K object

c is the reference count, the number of references pointing to the object.
t is the type of data stored, in [-4,7]
n is the number of elements stored
k is the array. It is initially typed for pointers to other K objects but accessors will cast it as an array of the proper type.

Each K object is allocated as a single contiguous block of memory. K pointers actually point to arbitrarily sized blocks of memory and not fixed sized chunks as the struct might otherwise suggest. The array being positioned at the end of the struct lets you index into arrays of arbitrary size and type. You can ignore the starting size of the array and index into the memory as far as necessary, relying on the product of n and the size of the type to indicate the bound. K objects of type 3 and -3 have a terminating null byte after the n-th byte. The just-allocated integer vector consisting of 7 8 9 is stored contiguously in memory as the 48 byte structure [1,-1,3,7,8,9]. Each number represents a 64-bit or 8-byte integer.

Type 7

Verbs, functions, and other executable forms of data are stored with type 7. All type 7’s have the same fixed size, TYPE_SEVEN_SIZE. The n field is instead used to store the subtype. The type 7 array is a series of void pointers to the following elements.

enum TYPE_SEVEN_MEMBERS {CONTEXT,CODE,LOCALS,PARAMS,CONJ,TYPE_SEVEN_SIZE};
Name Type Explanation
CONTEXT interned string (sp()) Where verb was created on K-Tree
CODE (see subtype table) Various executable data
LOCALS dictionary References for function constants, 1 in (1+/)
PARAMS dictionary Track a b c in {[a;b] c:a+b}
CONJ type-7 or type-0 with allowed nulls Attached values for projections, 2 in +[2;]
n Subtype CODE type
0 unexecuted types, wd() -4
1 verb/derived verb 1+\ -4
2 dynamically loaded function -4 (always size 3)
3 brace function {x} -3
4 :[] -4
5 if[] -4
6 while[] -4
7 do[] -4
Something went wrong with that request. Please try again.