Skip to content

Tagha API Reference

assyrianic edited this page Jun 17, 2018 · 64 revisions

Contents

Structs

struct NativeInfo {
	const char *Name;
	void (*NativeCFunc)(struct Tagha *, union Value *, size_t, union Value []);
};

struct Tagha {
	union Value Regs[regsize];
	struct Hashmap Natives;
	union Value
		ScriptHdr,
		FuncTable,
		GVarTable
	;
	bool CondFlag : 1; // conditional flag for conditional jumps!
};

Unions

Unions in dsc.h

Enums

enum ScriptFlags {
	FlagSafeMode =0x01,
	FlagDebug =0x02,
	FlagAllocMem =0x04, // allows malloc calls (for systems with healthy amounts of memory.)
};

enum RegID {
	regAlaf, regBeth, regVeth, regGamal, regGhamal,
	regDalath, regDhalath, regHeh, regWaw, regZain,
	regHeth, regTeth, regYodh, regKaf, regKhaf, regLamad,
	regMeem, regNoon, regSemkath, reg_Eh,
	// Peh is start of first reg param, Thaw is last.
	regPeh, regFeh, regSade, regQof, regReesh,
	regSheen, regTaw, regThaw,
	// Syriac alphabet makes great register names!
	regStk, regBase, regInstr,
	regsize
};

enum AddrMode {
	Immediate	= 1, /* interpret as immediate/constant value */
	Register	= 2, /* interpret as register id */
	RegIndirect	= 4, /* interpret register id's contents as a memory address. */
	Unsign = 8, /* interpret as unsigned data. */
	Byte		= 16, /* use data as (u)int8_t * */
	TwoBytes	= 32, /* use data as (u)int16_t * */
	FourBytes	= 64, /* use data as (u)int32_t * */
	EightBytes	= 128, /* use data as (u)int64_t * */
};

API Functions/Methods

void Tagha_Init(struct Tagha *vm, void *script);
  • intializes the Tagha VM with a script pointer.
void Tagha_Del(struct Tagha *vm);
  • frees the native's hashmap of the tagha vm and zeroes out its data.
struct Tagha *Tagha_New(void *script);
  • allocates, inits, and returns a pointer to a new Tagha system instance. Automatically calls Tagha_Init if the instance isn't NULL.
void Tagha_Free(struct Tagha **vmref);
  • takes a reference to a Tagha VM pointer and frees the entire Tagha vm and sets the vm reference to NULL.
void Tagha_RunScript(struct Tagha *vm, int32_t args, char *argvector[]);
  • executes a script loaded on the vm until the script halts, returns on empty stack, or an error occurs.
bool Tagha_RegisterNatives(struct Tagha *vm, struct NativeInfo natives[]);
  • registers an array of natives to Tagha's native map. returns true on success, false on failure. false can occur if vm or natives is NULL, or Natives Hashmap methods returns false.
int32_t Tagha_CallFunc(struct Tagha *vm, const char *funcname, size_t args, union Value values[]);
  • matches strFunc in a script's function table to invoke the function's instructions.
void TaghaDebug_PrintRegisters(const struct Tagha *vm);
  • prints all the data in the VM's registers.
void *Tagha_GetGlobalVarByName(struct Tagha *vm, const char *varname);
  • matches varname in a script's var table to retrieve the address of the global variable and returns it as a void * pointer. Returns NULL if the variable doesn't exist.
union Value Tagha_GetReturnValue(struct Tagha *vm);
  • pops the value of the VM's Alaf register.

Clone this wiki locally