Langphilia! /
KL1 /
KLIC-3.003 /
KLIC-C, 2001-10-23
the KLIC-C Language
Inline C, Generic Object, KLIC 翻訳系の出力などで使われる
KLIC-C 言語特有の仕様について説明する。
include/klic/*.h は複数回展開の防止を行なっていないので、
同一のファイルを直接間接に複数回 include してはならない。
前提
- sizeof(long) == sizeof(void*)
- long は任意のポインタの情報を失わずに保持できること。
klic/predinfo
- 型 struct predinfo, modinfo
klic/asyncio.h
- 型 enum sigiotype
- 定数 enum sigiotype KLIC_SIGIO_IN, KLIC_SIGIO_OUT,
KLIC_SIGIO_INOUT, KLIC_SIGIO_NONE
klic/schedule.h
- 関数 struct prioqrec* more_prioqrec(void)
- [runtime/sched.c] more_priorec は誤り。優先度キューを割り当てる。
- 関数 module topsucceed(struct global_variables* glbl, struct goalrec* qp,
q* allocp, const struct predicate* toppred)
- [runtime/kmain.c]
- 関数 struct goalrec* enqueue_goal(struct goalrec* qp, long prio,
struct goalrec* gp, struct global_variables* glbl)
- 関数 struct goalrec* enqueue_after_waiting(struct goalrec* qp, q prio,
struct goalrec* gp, q* allocp, int is_relative)
- 関数 struct goalrec* enqueue_throw_goal(q penum, struct goalrec* gp,
struct goalrec* qp, q* allocp)
- 関数 struct goalrec* get_top_priority_queue(void)
- 関数 void put_top_priority_queue(struct goalrec* qp, long prio)
- [runtime/sched.c]
klic/timing.h
- 型 timerstruct
- 変数 int gctimes, gcums, gssms, measure_gc
- 関数 field_diff(field)
- 関数 long diff_usec(field)
- 関数 long tick2msec(long n)
- 関数 measure(x)
klic/timer.h
- 型 struct klic_timer_wait_rec
- 定数 int Million
- 関数 int TimeIsZero(struct timeval x),
NotLaterThan(struct timeval x,y)
- 関数 void TimeSet(struct timeval x, long s,u)
- 関数 void TimeAdd(struct timeval x,y, struct timeval& z)
- 関数 void klic_gettod(), call_at_specified_time(),
call_after_specified_interval(), call_at_time_intervals(),
init_virtualized_timer()
klic/sighndl.h
- 副作用
- 複数回展開防止されている。
- 型 struct klic_sgnl_flags
- 定数 int NSIG
- long signal_flags[]
- int (* signal_handlers[])()
- long signal_done
- 変数 struct klic_sgnl_flags my_klic_sgnl_flags, *klic_sgnl_flags
klic/options.h
- 型 enum argtype, struct opttable, union all_type
- 定数 enum argtype ARG_DOUBLE, ARG_SIZE,
ARG_RESET, ARG_SET, ARG_STRING, ARG_NOT_USED
- 定数 struct opttable opttable[]
- 変数 static double max_a_ratio
- 変数 static unsigned long h_size, max_h_size, inc_size
- 変数 static int verbose, start_tracing, count_suspension
- 関数 char* parse_opts()
- 関数 int ARG_SHOULD_NOT_COPY(enum argtype X)
- 関数 enum argtype ARG_NOT_COPIED(enum argtype X)
- 関数 enum argtype ARG_ORIGINAL_TYPE(enum argtype X)
klic/susp.h
- 型 struct hook, struct susprec, struct generator_susp,
struct suspended_goal_rec, union goal_or_consumer
- 定数 int CONSUMER_HOOK_TAG, GENERATOR_OBJECT_TAG
- 関数 int is_consumer_hook(union goal_or_consumer u),
is_generator_susp(long u)
- 関数 (struct consumer_object*) tag_consumer_hook, untag_consumer_hook
(union goal_or_consumer obj)
- 関数 (struct generator_object*) tag_generator_susp, untag_generator_susp
(long obj)
- 関数 struct susprec* suspp(q x)
- 関数 void allocnewsusp(var, srec), makenewsusp(var, srec, allocp),
initnewsusp(tmp, var, srec)
- 関数 void allocnewgensusp(var, gsusp),
initnewgensusp(tmp, var, gsusp)
- 関数 void allochook(oldhook, newhook),
addhook(oldhook, newhook, allocp), initnewhook(oldhook, newhook)
- 関数 struct generator_suspp* generator_suspp(void* susp)
klic/atomstuffs.h
- 前提
- klic/functorstuffs.h, klic/struct.h を include すること。
- 定数 const int ATOMNUMBERBASE
- 内緒:[ ] と ./2 は特別扱いで定数なので、
atomname の添字は ATOMNUMBERBASE から始まる。
- 変数 unsigned char** atomname
- [runtime/atom.c] 記号アトムの文字列表現を並べた配列。
- 関数 unsigned char* functoratomname(f)
- import functoratom, ATOMNUMBERBASE
- ファンクタ f の主ファンクタ(アトム)の文字列表現を返す。
- 関数 unsigned char* namestringof(a)
- import symval, ATOMNUMBERBASE
- アトム a の文字列表現を返す。
klic/functorstuffs.h
- 前提
- klic/newatom.h を include してはならない。
- 定数 const int FUNCTORNUMBERBASE
- 変数 (unsigned long*) functors, arities
- [runtime/funct.c] 主ファンクタ(アトム), 引数の個数を並べた配列。
- 関数 unsigned long functoratom, arityof (q f)
- import functors/arities, symval, FUNCTORNUMBERBASE
- ファンクタ f の主ファンクタ(アトム), 引数の個数を返す。
klic/newatom.h
- 前提
- klic/functorstuffs.h を include してはならない。
- 型 struct atomhashtable
- 型 struct functorhashtable
- 定数 int FUNCTORNUMBERBASE
- 変数 unsigned char** atomname
- [runtime/atom.c]
- 変数 (unsigned long*) functors, arities
- [runtime/funct.c]
- 定数 int Hashsize, Namesize, Atomsize, Functorsize
- 定数 int YET, DONE
- 定数 int AtomError
- 変数 static int init_atom, init_functor
- 定数 const unsigned long initial_atoms
- [runtime/atom.c]
- 定数 const unsigned long initial_functors
- [runtime/funct.c]
- 変数 unsigned long numberOfAtoms, numberOfFunctors
- 変数 struct atomhashtable atomhtable, *atomhp
- 変数 struct functorhashtable functhtable, *functhp
- 変数 (static long*) nextatom, nextfunctor
- 変数 (unsigned char*) namearea, nameareap
- 関数 unsigned long functoratom, arityof (q f)
klic/klichdr.h
- 副作用
- klic/{ basic, struct, primitives, unify, index, gb, bb,
generic, g_string, g_vector, g_float, gmodule }.h が include される。
klic/index.h
- 関数 void deref_and_switch(q& x, susp, atomic, cons, funct)
- x を手繰ってラベル susp, atomic, cons, funct のいずれかへ飛ぶ。
- 関数 void deref_and_test(q& x, susp)
- x を手繰って未定義ならばラベル susp へ飛ぶ。
- 関数 void deref_and_jump(q& x, loop)
- x を手繰って未定義でなければラベル loop へ飛ぶ。
- 関数 not_cons(q x), not_functor(), not_atomic()
- 前提:tag。
klic/unify.h
- 前提
- klic/struct.h を include すること。
- 関数 (q*) do_unify(allocp, x, y), do_unify2(allocp, x, y, z, w),
do_unify3(allocp, x, y, z, w, s, t), do_unify4(allocp, x, y, z, w, s, t, u, v),
do_unify_value(allocp, x, y), do_unify_value2(allocp, x, y, z, w),
do_unify_value3(allocp, x, y, z, w, s, t),
do_unify_value4(allocp, x, y, z, w, s, t, u, v)
- 関数 void unify(x, y), unify2(x, y, z, w),
unify3(x, y, z, w, s, t), unify4(x, y, z, w, s, t, u, v),
unify_value(x, y), unify_value2(x, y, z, w),
unify_value3(x, y, z, w, s, t), unify_value4(x, y, z, w, s, t, u, v)
- 前提:q* allocp。x, y, z, w, s, t, u, v は q 型。
klic/bb.h
- 関数 q bblt_plus_2, bblt_minus_2, bblt_complement_2, bblt_fix_2 (q x)
- 関数 q bblt_add_3, bblt_sub_3, bblt_mult_3, bblt_div_3, bblt_mod_3,
bblt_and_3, bblt_or_3, bblt_exclusive_or_3,
bblt_rshift_3, bblt_lshift_3 (q x, q y)
- [runtime/bb.c]
- 文 bblt_complement, bblt_complement_no_check (q x, q z)
- 文 bblt_plus, bblt_plus_no_check (q x, q z)
- 文 bblt_minus, bblt_minus_no_check (q x, q z)
- 文 bblt_fix(q x, q z)
- 文 bblt_add, bblt_add_no_check,
bblt_add_no_check_x, bblt_add_no_check_y (q x, q y, q z)
- 文 bblt_sub, bblt_sub_no_check,
bblt_sub_no_check_x, bblt_sub_no_check_y (q x, q y, q z)
- 文 bblt_mult, bblt_mult_no_check,
bblt_mult_no_check_x, bblt_mult_no_check_y (q x, q y, q z)
- 文 bblt_div, bblt_div_no_check,
bblt_div_no_check_x, bblt_div_no_check_y (q x, q y, q z)
- 文 bblt_mod, bblt_mod_no_check,
bblt_mod_no_check_x, bblt_mod_no_check_y (q x, q y, q z)
- 文 bblt_and, bblt_and_no_check,
bblt_and_no_check_x, bblt_and_no_check_y (q x, q y, q z)
- 文 bblt_or, bblt_or_no_check,
bblt_or_no_check_x, bblt_or_no_check_y (q x, q y, q z)
- 文 bblt_exclusive_or, bblt_exclusive_or_no_check,
bblt_exclusive_or_no_check_x, bblt_exclusive_or_no_check_y (q x, q y, q z)
- 文 bblt_rshift, bblt_rshift_no_check,
bblt_rshift_no_check_x, bblt_rshift_no_check_y (q x, q y, q z)
- 文 bblt_lshift, bblt_lshift_no_check,
bblt_lshift_no_check_x, bblt_lshift_no_check_y (q x, q y, q z)
- export z
- import bblt_*_?
klic/gb.h
- 関数 q builtin_compare_terms(q x, q y)
-
- 関数 q builtin_hash_term(q x, long l)
- [runtime/cmphsh.c]
- 文 gblt_compare(q x, q y, q r, ラベル fail)
- export r, reasonp
- import isref, builtin_compare_terms
- x, y を比較して結果が未定義ならば fail へ飛ぶ。
- 関数 q gblt_hash(q x, q r, ラベル fail)
- export r
- import builtin_hash_term
- x のハッシュ値を得る。
- 文 gblt_deep_hash(x, q l, q r, ラベル fail)
- export r, reasonp
- import isref, intval, builtin_hash_term
- x のハッシュ値を計算して結果が未定義ならば fail へ飛ぶ。
- 関数 q gblt_current_prio(q p, ラベル fail)
- export p
- import makeint, current_prio
- 現在の優先度を得る。
- マクロ gblt_wait(q x, ラベル susp)
- マクロ gblt_list, gblt_atom, gblt_integer,
gblt_atomic, gblt_float (q x, ラベル fail)
- 文 gblt_greater, gblt_greater_or_eq,
gblt_less, gblt_less_or_eq, gblt_eq (long x,y, ラベル fail)
- 文 gblt_and, gblt_or, gblt_exclusive_or, gblt_rshift, gblt_lshift,
gblt_add, gblt_subtract, gblt_multiply, gblt_divide, gblt_modulo
(q x, q y, q z, ラベル fail)
- export z
- import INT, intval, makeint
- 文 gblt_complement, gblt_plus, gblt_minus,
gblt_fix (q x, q z, ラベル fail)
- export z
- import ATAGBITS, INT, makeint, float_value
- 文 gblt_pfunctor(q x, q f, ラベル fail)
- export f
- import PERIODATOM, isatomic, iscons, isref,
functorp, makesym, functoratom
- 文 gblt_arity(q x, q a, ラベル fail)
- export a
- import isatomic, iscons, isref, functorp, makeint, arityof
- 文 gblt_arg(q n, q x, q a, ラベル fail)
- export a
- import isatomic, iscons, isref,
functorp, intval, makeint, car_of, cdr_of, arityof, arg
- 変数 TableName(x)
- struct data_object_method_table `x'_g_data_method_table
- 文 jump_if_not_in_class(q x, クラス class, ラベル label)
- import TableName, isgobj, functor_of
- 文 gblt_element_of_vector(q v, q k, q e, ラベル fail)
- export e
- import element_of_vector
- 文 gblt_is_string(q s, ラベル fail)
- import byte__string, jump_if_not_in_class
- 文 gblt_size_of_string(q v, q s, ラベル fail)
- export s
- import size_of_string
- 文 gblt_element_size_of_string(q v, q es, ラベル fail)
- export es
- import makeint
- 文 gblt_element_of_string(q v, q k, q e, ラベル fail)
- export e
- import element_of_string
- 関数 q eq_terms_body(q x, q y)
- 文 if_not_equal(q x, q y, ラベル fail)
- export reasonp
- import isref, eq_terms_body
- 文 otherwise(ラベル)
- import reasonp, reasons
- 文 alternative(ラベル)
- export allocp
- import reasonp, reasons, heapp, check_stack_for_alternatively
- 文 gblt_assign(q x, q y, ラベル fail)
- export x
- 文 gblt_not_eq, gblt_diff (q x, q y, ラベル fail)
- import isatomic, iscons, isfunctor, functor_of
- 文 gblt_display_consol(w, ラベル fail)
- import printl
- 関数 q gblt_tag, gblt_value (q x, q y, ラベル fail)
- export y
- import ATAGBITS, ptagof, makeint
klic/primitives.h
- 副作用
- klic/alloc.h, klic/control.h が include される。
klic/alloc.h
- 関数 q* klic_interrupt()
- 文 heapalloc, revalloc (q s, q* words, q (*maketype)(q*))
- export s, heapbottom, heaplimit, real_heaplimit
- import interrupt_off
klic/control.h
- 前提
- klic/struct.h を include していること。
- 定数 const q EXTEVENT, FAILURE
- import makeint
- 中断の原因
- 関数 q* interrupt_goal(q* allocp, struct predicate* pred, q* reasonp)
- 関数 int check_stack_for_alternatively(q* allocp, q* reasonp)
- [runtime/faisus.c]
- 文 enqueue_at_priority, enqueue_at_lower_priority
(p, q0, struct goalrec* q)
- export qp
- import allocp, enqueue_after_waiting
- 文 enqueue_at_priority_no_check(q prio, q0, struct goalrec* q)
- export qp
- import glbl, intval, enqueue_goal
- 文 enqueue_at_lower_priority_no_check(q prio, q0, struct goalrec* q)
- export qp
- import glbl, intval, enqueue_goal, current_prio
- switch_on_pred()
- import toppred
- 文 case_pred, last_case_pred (p, label)
- 文 loop_within_module(module (*f)())
- export qp, allocp, toppred, heapp, heaplimit, current_queue
- import klic_interrupt, ラベル module_top
- 文 execute(label)
- import allocp, heaplimit
- 文 proceed(void)
- import ラベル proceed_label
- 文 throw_goal(node, oldqp, goal)
- export qp
- import allocp, enqueue_throw_goal
klic/basic.h
- 副作用
- klic/config.h が include される。
- 記憶クラス Extern
- runtime/kmain.c では空、それ以外では extern。
- マクロ Init(x)
- runtime/kmain.c では `= x'、それ以外では空。
- マクロ Size(size)
- runtime/kmain.c では size、それ以外では空。
- 型修飾 Const
- 不要。ANSI C ならば const、でなければ空。
- 型修飾 Volatile
- 不要。ANSI C ならば volatile、でなければ空。
- Inline
- 不要。GNU C ならば __inline__、でなければ空。
- 型修飾 NoReturn
- GNU C ならば volatile、でなければ空。
- マクロ PARALLEL
- マクロ DIST または SHM が定義されていれば定義される。
- 型 void voidfn()
- 関数 NoReturn void fatal(char* message), fatalf(char* format, long a0-a7),
fatalp(char* where, char* format, long a0-a7)
- 関数 void debug_fprintf(FILE* out, char* format, long a0-ab)
- 関数 void klic_fprintf(FILE* out, char* format, long a0-ab)
- [runtime/debug.c]
- 関数 int klic_getc(), klic_fread(),
klic_putc(), klic_fwrite(), klic_fflush()
- 関数 int klic_local_fprintf(FILE* stream, const char* format ..)
- C の fprintf を使わず、こちらを使うべし。
klic/config.h
- マクロ SPARC, ALPHA, INTEL, Unknown_cpu
- 環境によっていずれか1つが定義される。
- 定数 (const char*)
KLICBIN, KLICLIB, KLICINCLUDE, KLIC_COMPILER, KLIC_DBMAKER
- それぞれ bin, lib, include ディレクトリ、KLIC 翻訳器 (lib/klic/kl1cmp)、
名前DB (lib/klic/klicdb) を表す文字列。
- 定数 (const char*) CC, LD, RANLIB
- cc, ld, ranlib? コマンドを表す文字列。
- 定数 const char* UOPTFLAGS
- cc の最適化フラグを表す文字列。
- 定数 (const char*) LIBRARIES, LIBRARIES_T, LIBRARIES_D, LIBRARIES_S,
KLIC_CC_OPTIONS, KLIC_LD_OPTIONS
- KLIC 実行系, トレース版, 分散版, 共有版、
cc, ld のオプションを表す文字列
- マクロ ASYNCIO, STRINGH, STDDEFH, SETLINBUF, USELOCKF, USESIG,
GETRUSAGE, USEUSLEEP, USEULIMIT, USEGETDTABLESIZE, USETIMER,
NRAND48, ISASTREAM, USESTREAMINCLUDEDIR, USEPROCBIND,
USESELECT, XTERM, DECL_SYS_ERRLIST, DECL_FPRINTF
- 環境によって定義されたりされなかったりする。
- 関数 int BCMP(void* x, void* y, int len)
- memcmp または bcmp。
- 関数 void* BCOPY(void* from, void* to, int len)
- memcpy または bcopy。
- 関数 void BZERO(void* from, int len)
- memset または bzero。
- 関数 char* STRCHR(char* s, char c)
- strchr または index。
- マクロ CROSS
- クロスコンパイラなら定義される。
- 文 DIST_COMPILER_FLAG, DIST_LINKAGE_FLAG (char* name, char* ext)
- export char* bufp
- import char* klic_incdir
klic/struct.h
- 副作用
- klic/param.h が include される。
- 型 struct gazonk* q
- セル。KLIC-KL1 のデータ構造の単位。
gazonk は架空の型なので、q の値を手繰ると翻訳時エラーとなる。
- 定数 long VALUEMASK, ADDRESSMASK
- q 型の値からタグを取り除くマスク。
- 定数 long PTAGBITS, PTAGMASK, ATAGBITS, ATAGMASK
- ポインタタグ, 原子値タグのビット数, マスク。
- 定数 long INT, SYM
- 整数, 記号アトムのタグ値。
- 定数 long VARREF, CONS, ATOMIC, FUNCTOR,
STRUCT, FUNCTNOTCONS, ATOMNOTREF
- ref, cons, atomic, functor のタグ値、
{cons, functor}, functor-cons, atomic-ref のタグ値。
- 関数 unsigned long ptagof(q x), addressof(q x)
- x のポインタタグ, アドレスを取り出す。
- 関数 int isatomic(q x), iscons(q x), isfunctor(q x), isref(q x)
- x が atomic, cons, functor, ref か否かを返す。
- 関数 unsigned long isstruct(q x), functnotcons(q x), atomicnotref(q x)
- x が {cons, functor}, functor-cons, atomic-ref か否かを返す。
- 関数 unsigned long atagof(q x)
- x の原子値タグを取り出す。
- 関数 int isint(q x), issym(q x)
- x が整数, 記号アトムか否かを返す。
- 型 struct functor
- ファンクタ構造体
- 関数 q functor_of(q s), arg(q s, int k)
- s の主ファンクタ(アトム), k = [0,*) 番目の引数を返す。
- 型 struct cons
- コンスセル
- 関数 q car_of(q x), cdr_of(q x)
- x の car, cdr を返す。
- 関数 q pcar_of(q x), pcdr_of(q x)
- x の car, cdr を指す ref を返す。
- 型 char* (* module)()
- モジュール
- 型 struct predicate
- 述語構造体
- 型 struct arginfo
- 述語引数のモード情報
- 型 struct goalrec
- ゴール構造体(リスト)
- 型 struct prioqrec
- 優先度キュー構造体(優先順ゴールリストのリスト)
- 関数 q* refp(q x)
- 関数 struct cons* consp(q x)
- 関数 struct functor* functorp(q x)
- 関数 struct goalrec* goalp(q x)
- 関数 struct predicate* predp(q x)
- {ref, cons, functor, goal, predicate} x のポインタ部分を返す。
- 関数 q makeref(void* x), derefone(q x)
- {アドレス, ref} x に相当する {ref, ポインタ} を返す。
- 関数 long intval(q x)
- 関数 unsigned long symval(q x)
- 整数, 記号アトム x に相当する C の表現を返す。
- 関数 q makeint(q n), makesym(q n)
- C の表現に対応する整数, 記号アトムを返す。
- 関数 long makecint(q n)
- C の表現に対応する C の整数を返す。
- 関数 int eqatom(q x, q y)
- x, y が同じアトムか否かを返す。
- 関数 q makeatomic(long adr)
- adr に atomic タグを付ける。
- 関数 q makepf(q x)
- C の表現に対応する主ファンクタ(アトム)を返す。
- 関数 q makecons(long x), makefunctor(long x)
- x に cons, functor タグを付ける。
- 変数 struct funcdesc functab[]
- ファンクタ表
- 型 struct ext_atom, ext_funct, ext_pred
- atom, functor, predicate と文字列表現の対応
- 定数 q NILATOM, PERIODATOM
- 特別なアトム [], ./2
- 変数 long higher_priority_goal
- ヒープの外のメモリブロック?
- 変数 q suspension_reason, rest_of_stream
- mutableオブジェクトのための変数?
- 変数 struct global_variables globals
- 変数 struct global_variables* My_glbl = &globals
- グローバル変数の寄せ集め。
- 宣言 declare_globals
- struct global_variables* glbl = My_glbl
- 変数 (struct goalrec*) current_queue, resumed_goals
- 変数 struct prioqrec prioq
- 変数 unsigned long current_prio, top_prio
- 変数 (q*) heapp, heaptop, heaplimit, real_heaplimit, heapbottom
- 変数 unsigned long heapsize, maxheapsize,
real_heapbytesize, incrementsize
- 変数 double maxactiveratio
- 変数 (q*) new_space_top, old_space_top
- 変数 unsigned long new_space_size, old_space_size, this_more_space
- 変数 (q**) gcstack, gcsp, gcmax
- 変数 unsigned long gcstack_size
- 変数 long interrupt_off
- 変数 char* program_name, int command_argc, char** command_argv
- 変数 q* (** gc_hook_table)(), q* (** after_gc_hook_table)()
- 変数 int gc_hooktab_size, num_gc_hooks,
after_gc_hooktab_size, num_after_gc_hooks
- 変数 unsigned long suspensions, resumes, copied_susp,
cum_susps, cum_resumps
- 変数 struct suspended_goal_rec* suspended_goal_list
- 変数 const struct predicate* postmortem_pred, 変数 q postmortem_args
- 変数 long generic_argc, 変数 q generic_arg[MAXGENERICARGS]
- 変数 q reasons[MAXSUSPENSION]
- 前提:declare_globals していること。
klic/param.h
- 定数 int MAXSTDARGS
- トレーサが扱う引数の最大個数
- 定数 int MAXGENERICARGS
- ジェネリックメソッドの引数の最大個数
- 定数 int PRIOQRECBULK
- 一度に割り当てる優先度キューの個数
- 定数 long HEAPSIZE
- デフォルトヒープサイズ ワード単位
- 定数 long INCREMENTSIZE
- 予約ヒープサイズ? ワード単位
- 定数 long MAXSUSPENSION
- 中断原因の最大個数
- 定数 long MAXKLICINT, MINKLICINT
- KLIC-KL1 整数の最大・最小値
- 定数 long HIGHESTPRIO
- 優先度の最高値
- 定数 long GCSTACKSIZE
- GCスタックの初期サイズ
Copyright 2001, TAKAGI Yusuke.