Skip to content
assyrianic edited this page Jul 23, 2018 · 60 revisions

Welcome to the Tagha Virtual Machine wiki! the Wiki is always being updated to account for iterative changes.

Purpose:

The purpose for Tagha's existence is to utilize C as an embeddable scripting language or, for better and accurate words, Tagha is a minimal runtime environment with embedding and scripting capabilities. You're probably thinking that C sounds too low level to be used for scripting, but to me there are some advantages in using C as a scripting language:

Tagha was designed to be used as a viable alternative to a C plugin architecture via dynamically loaded dll's, especially with the advantage of being able to run C code without having to recompile the dll's for different operating systems and ABIs.

Having C as a scripting language can also be useful as most programmers have knowledge of C-like languages, so there would be no need to learn a new language or syntax style. As a language, C is very minimal and has enough programmatic control to indirectly extend any sort of program with as much control as given to the scripter as possible.

Why?:

a few reasons why Tagha exists!

Reason 1: One could use a C interpreter and embed that but so far, the only C interpreters (that I currently know of) are CINT, PicoC, TCC [1] and Ch:

  • The problems with CINT is that it's old, clunky to use, outdated, and deprecated.
  • PicoC is ok but its problem is that it uses old-school interpreting (just runs literal code) instead of compiling to bytecode which would allow it to execute faster.
  • The problem with Ch is that, though it's embeddable and updated, it's proprietary and it's unknown how it interprets code; as the usual problem with proprietary code, you don't know what code it could contain and there's no telling what security issues Ch could possibly have; not to mention that proprietary code shuts out enthusiastic individuals or groups from contributing to the software. UPDATE: I read on the Ch's developers website that Ch also interprets source code directly, doesn't use a bytecode machine! Specifically, Ch uses an AST-walking interpreter that's combined with a JIT Compiler [2], that'll speed up things alot but reduces portability significantly. [3]
  • [1] - Tiny C Compiler, it can compile and run scripts for testing but it can't be embedded the same way a scripting system can be.
  • [2] - citation from Ch dev website
  • [3] - Embeddable Ch is NOT free, you must get a price quote for it and purchase it.

Reason 2: I've always wanted to create a useful, open-source piece of software for many to use and one of my particular interests happens to be computer languages, so why not make a scripting engine?

Reason 3: To learn from making a virtual machine and runtime environment from scratch. If polished good enough, Tagha can hopefully be used in education to teach about virtual machines, scripting engines, and/or embedding for educational use!

The goal for Tagha is to...

    1. be a new and modernly optimized piece of software.
    1. have the clear execution speed advantage bytecode machines have over more traditional interpreters.
    1. be open-source and open for anyone who wants to improve or use Tagha.
    1. be an example of how to create and design a minimal scripting system.
    1. be portable and embeddable for any program and platform.

Requirements:

  • C99 compliant C compiler.

Features

  • register-based virtual machine with 3 different addressing modes to tackle any kind of operation.
  • 22 general purpose registers + 3 reserved-use (stack pointers and instruction pointer) registers.12
  • self-contained.
  • has its own implementation of libc specially for TaghaVM.
  • floats and doubles are supported on the same floating point opcodes through addressing modes.
  • uses computed goto dispatches (the ones that use a void*) which is 20%-25% faster than a switch {citation}.
  • Tagha is "64-bit" as the registers and memory addresses are 64-bit. (will run slower on 32-bit systems/OSes)
  • Embeddable into host applications.
  • scripts can call host-defined functions (Native Interface).
  • host can give arguments and call script functions and retrieve return values, thus you can set up function event handling to scripts.
  • host can bind its own global variables to script-side global variables by name (the script-side global variable must be a pointer).
  • integer and float arithmetic, (un)conditional jumps, comparison operations, and stack and memory manipulations.
  • function call and return opcodes automatically execute function prologues and epilogues.
  • VM is little-endian format architecture.
  • very small. The runtime environment static library is only ~30kb.
  • Tagha is not natively threaded, this is by design, this is so any developer can thread Tagha in anyway you wish whether by having a single VM instance run multiple scripts in a multi-threaded, managed way OR have an array of Tagha VM instances each running their own scripts in a threaded manner.
  • Speed, tagha is very fast for a virtual machine that does not use a JIT.

VM Internals and Interaction

  • General rundown how a script gets made and then executed.

Clone this wiki locally