BGBScript


Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102

Deprecated: Non-static method MagicWord::get() should not be called statically, assuming $this from incompatible context in /nfs/c05/h02/mnt/69264/domains/vpri.org/html/fonc_wiki/includes/Parser.php on line 2102
From VpriWiki

Jump to: navigation, search

BGBScript is the personal project of Brendan G Bohannon (among several other projects, such as the BGBTech 3D Engine, ...). (Yes, uncreative naming-after-oneself going on.)

It is mostly a scripting language with a mostly similar design to JavaScript and ActionScript, and is for the most part an ECMAScript variant. Some other languages of influence include Self, Erlang, Scheme, Java, C#, and C.

It is presently s sub-project of the Silverfish VM sub-project of my main-project (which includes 3D stuff, ...).


Contents

Overview

The basic syntax is mostly similar to ActionScript. Its primary intended use is as a high-level scripting language mostly for C and C++ programs, and is generally loaded directly from source files.

See also:


Syntax Example:

var topx, topy; //toplevel variables
function topFoo() //toplevel function
    { return topx; }

package foo
{
    native import C.stdio; //import C stuff (1)

    var pkgx; //package-scoped variable
    function pkgFoo() //package-scoped function
        pkgx; //return and braces optional

    public class Bar
    {
        private var lx, ly; //instance variables

        public function Bar() //constructor
        {
            lx=3; ly=4;
        }
        public function get x() { return lx; } //getter
        public function set x(val) { lx=val; } //setter

        //method which uses types:
        public function doSomething(z:float):void
            { lx*=z; ly/=z; }
    }
}
topx={x: 3, y: 4}; //construct an object ex-nihilo
topy=new foo.Bar(); //and an object from a class (2)
var x2=topx.clone(); //clone topx

var arr=new byte[256]; //array of bytes
var arr2=[1, 2, 3, 4]UB; //literal array of unsigned bytes

So, as noted, declarations are allowed at all levels, and declarations may have types (the default type is "variant", which will accept any type of value).

Also note that the toplevel is executed from top-to-bottom, allowing for executable expressions in top-level declarations, but this is also potentially subject to ordering issues (it is possible to attempt to access a variable before its' binding has been assigned a variable, leading to potentially unpredictable results).

1: The C FFI basically imports databases created from headers, as well as associated libraries. At present (June 2011) this will make the entire known C toplevel visible, rather than selectively importing only the specific contents of the requested library. This may change in the future.

2: one can, of course, use import...


Differences From other ECMAScript Variants

At present, the default floating-point precision is flonum, which is currently only 28 bits (it is a modified/trimmed float), and requires the use of suffixes or casts to gain full double precision.

The scoping model differs in that the toplevel is implemented using an object, rather than part of the lexical scope. Likewise, anything contained within packages is also presently implemented using objects. In-fact, only functions and closures currently use lexical scope (apart from 'import' and similar, which is currently implemented via delegate variables in the lexical scope).

Similarly, the notable set of additional functionality, and absence of most extended JS functionality, may be considered a difference (however, ECMA-262 does not disallow extensions or require features such as DOM or E4X).

Unlike ActionScript, this does not implement any functionality related to the Flash/Flex/... runtime libraries, only many of its core syntax features. Similarly, 'eval()' retains the ability to evaluate arbitrary code fragments.


Additional Features

BGBScript has some additional features not generally present in other ECMAScript variants:

  • Locatives/References (currently via a C-like &x and *x syntax)
    • These are not pointers per-se, as they use objects and don't support pointer arithmetic
  • Arithmetic can offset strings and arrays (also like in C)
    • Although cosmetically similar, these are also not raw pointers
  • Lists and car/cdr/caar/cadr/...
  • Built-in Vector, Complex, and Quaternion math
  • Numeric tower includes 128 bit integer and float types
    • Along with other integer and float types (like in other Java or similar);
  • Also supports dynamic scope
  • Also supports free-form delegation
    • Nearly any variable can be used for delegation via the 'delegate' modifier
      • Yes, includes local variables and dynamic variables
      • Class instances can also use delegation
  • Can generally call directly into C functions
    • Can often make use of C structs (with some limitations)
    • C code can directly call script functions as callbacks
      • Not well tested
      • May not necessarily be available for future non-x86 targets
      • May be in cases subject to API funkiness (coercing dynamically typed function into C function pointer)
  • Can use Java style declaration syntax
  • Does tail-call optimization
    • Braces around single-line functions are optional
    • The last line in a function is in tail-position
      • The return statement is optional for expressions in tail position
        • Applies recursively, such as to if() and similar
  • Supports 'fun' for closures in addition to 'function'
  • etc...


Disadvantages

The implementation is still very immature (buggy and lacking in features), and not all features necessarily actually work.

Being a personal project, it lacks any of the real support, community, ... associated with more mainstream and commercially-supported languages.

...


Known Flaws

Here is a current list of known flaws:

  • The floating-point precision issue
    • No "good" solution at the moment
  • The public/private/protected modifiers don't presently work
    • Everything defaults to behaving as if it were public
      • Code should not depend on this behavior (likely to change later)
  • Getters/setters require proper objects to work
    • Don't work with ex-nihilo objects
    • Don't work with packages or environments
    • Can't safely add to objects with with() either.
  • Exceptions don't work
    • 'nuff said...
      • kinda need to fully implement them...
    • (Partial Change) Added exceptions
      • Not well tested
      • Don't cross language boundaries (status code in C land)
  • No real "standard library"
    • Most stuff either built in or accessed via C FFI
      • VM has not been tested with "non-trivial" levels of code
        • Creator is not certain that large class libraries will not break the VM or make GC go berserk or similar...
      • (Partial Change) Partly added a Java-like library (neither complete nor well tested)
  • VM lacks external ByteCode serialization
    • Brute-force loads everything at the moment
      • Need good selective-load mechanism
    • Code is always recompiled from source
      • Both slow and makes lots of garbage
      • Need to implement mechanism to load/save bytecode files
        • Worries about VM versioning issues
    • (Changed) Now has saved ByteCode
      • Exact format (specifics, ISA listings, ...) subject to change
        • It is based on a single large constant pool containing "everything"
        • Each function/method/block may have its own local "literal table"
        • Format is really just a raw data serialization format (MKV style TLV)
      • Not well tested
  • Switch is implemented stupidly
    • Internally uses if/else style logic
  • ...
Personal tools