Пример #1
0
    ?>
;
}

<?php 
    $gContent .= ob_get_clean();
    ?>

//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'limits'), "complex" => false, "global_content" => $gContent, 'binary_operators' => ['+', '-', '*', '/', '%', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['integral', 'numeric', '_primative_'], 'describe_json' => DescribeJson('integer'), 'extras' => ['size.bytes' => 2]);
}
declareOperator('//', ['base::SMALLINT', 'base::SMALLINT'], function ($args) {
    $l = lookupType('base::SMALLINT');
    return ['kind' => 'OPERATOR', 'name' => '/', 'input' => [$l, $l], 'result' => $l, 'deterministic' => true];
});
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'INT', 'BIGINT', 'FLOAT', 'DOUBLE'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::SMALLINT');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'SMALLINT', [$fullType], $call);
}
declareSynonym("base::SMALL", "base::SMALLINT");
Пример #2
0
<?php 
    $functions[] = ['IsNull', ['@type'], 'BASE::BOOL', true, true];
    ?>
inline
bool IsNull( @type f ) {
    return isnan(f);
}

<?php 
    $gContent .= ob_get_clean();
    ?>
//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'cmath'), "complex" => false, "global_content" => $gContent, 'binary_operators' => ['+', '-', '*', '/', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['real', 'numeric', '_primative_'], 'describe_json' => DescribeJson('float'), 'extras' => ['size.bytes' => 8]);
}
//end of function
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'BIGINT', 'FLOAT', 'INT'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::DOUBLE');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'DOUBLE', [$fullType], $call);
}
Пример #3
0
<?php

// Copyright 2015, Tera Insights, LLC. All Rights Reserved.
declareFunctionGlobal('BASE', 'BOOL', ['BASE::NULL'], function () {
    $boolType = lookupType('BASE::BOOL');
    $nullType = lookupType('BASE::NULL');
    return ['kind' => 'FUNCTION', 'name' => 'bool_Null', 'input' => [$nullType], 'result' => $boolType, 'deterministic' => true];
});
?>

inline int ToString(bool b, char * buffer) {
	if (b)
		return 1 + sprintf(buffer, "true");
	else
		return 1 + sprintf(buffer, "false");
}

inline void FromString(bool & b, const char* buffer) {
	char first = *buffer;
	char upper = *buffer & 0xDF;
	if (first == '1' || upper == 'T' || upper == 'Y')
		b = true;
	else
		b = false;
}

namespace BASE {
	inline
	bool bool_Null(const GrokitNull& null) {
		return false;
	}
Пример #4
0
inline
bool IsNull( @type f ) {
    return isnan(f);
}

<?php 
    $gContents = ob_get_clean();
    ?>

//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'cmath', 'limits'), "complex" => false, 'binary_operators' => ['+', '-', '*', '/', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['real', 'numeric', '_primative_'], 'global_content' => $gContents, 'describe_json' => DescribeJson('float'), 'extras' => ['size.bytes' => 4]);
}
// end of function
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'BIGINT', 'INT', 'FLOAT', 'DOUBLE'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::FLOAT');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'FLOAT', [$fullType], $call);
}
?>

Пример #5
0
 public function __construct($hash, $name, $value, array $args, array $origArgs)
 {
     parent::__construct(InfoKind::T_TYPE, $hash, $name, $value, $args, $origArgs[0]);
     $iterator = 'ColumnIterator<' . $value . '>';
     if (array_key_exists('complex', $args)) {
         $iter = $args['complex'];
         if ($iter !== false) {
             $iterator = str_replace('@type', $this->value(), $iter);
         }
     }
     $this->iterator = $iterator;
     if (array_key_exists('destroy', $args)) {
         $destroy = $args['destroy'];
         if (is_bool($destroy)) {
             $this->destroy = $destroy;
         } else {
             grokit_error("Expected boolean value for 'destroy' attribute of datatype " . $this->value());
         }
     }
     if (array_key_exists('dictionary', $args)) {
         $this->dictionary = $args['dictionary'];
     }
     if (array_key_exists('fixed_size', $args)) {
         $this->fixedSize = $args['fixed_size'];
     }
     // Deal with operators defined by the type.
     if (array_key_exists('unary_operators', $args)) {
         foreach ($args['unary_operators'] as $op) {
             LibraryManager::AlphaOperator($op, 1, $this);
         }
     }
     if (array_key_exists('binary_operators', $args)) {
         foreach ($args['binary_operators'] as $op) {
             LibraryManager::AlphaOperator($op, 2, $this);
         }
     }
     if (array_key_exists('constructors', $args)) {
         foreach ($args['constructors'] as $cstr) {
             $cArgs = get_first_key($cstr, ['args', 0]);
             $cDet = get_first_key_default($cstr, ['deterministic', 1], true);
             $myType = $this->value();
             $myName = end(explode('::', $myType));
             $cName = get_first_key_default($cstr, ['c_name', 2], $myName);
             $callback = function ($args, $t_args = []) use($cArgs, $cDet, $myType, $cName) {
                 $myArgs = array_map('lookupType', $cArgs);
                 $myRet = lookupType($myType);
                 $retVal = ['kind' => 'FUNCTION', 'input' => $myArgs, 'result' => $myRet, 'deterministic' => $cDet];
                 if ($cName !== null) {
                     $retVal['name'] = $cName;
                 }
                 return $retVal;
             };
             declareFunctionGlobal('', $myType, $cArgs, $callback);
         }
     }
     if (array_key_exists('functions', $args)) {
         foreach ($args['functions'] as $fnct) {
             $fName = get_first_key($fnct, ['name', 0]);
             $fArgs = get_first_key($fnct, ['args', 1]);
             $fRet = get_first_key($fnct, ['result', 2]);
             $fDet = get_first_key_default($fnct, ['deterministic', 3], false);
             $fGlobal = get_first_key_default($fnct, ['global', 4], false);
             $cName = get_first_key_default($fnct, ['c_name', 5], null);
             foreach ($fArgs as &$arg) {
                 $arg = str_replace('@type', $this->value(), $arg);
             }
             $fRet = str_replace('@type', $this->value(), $fRet);
             $callback = function ($args, $t_args = []) use($fArgs, $fRet, $fDet, $cName, $fGlobal) {
                 $myArgs = array_map('lookupType', $fArgs);
                 $myRet = lookupType($fRet);
                 $retVal = ['kind' => 'FUNCTION', 'input' => $myArgs, 'result' => $myRet, 'deterministic' => $fDet, 'global' => $fGlobal];
                 if ($cName !== null) {
                     $retVal['name'] = $cName;
                 }
                 return $retVal;
             };
             $fNS = $fGlobal ? 'BASE' : LibraryManager::ExtractNamespace($this->value());
             $fName = LibraryManager::JoinNamespace($fNS, $fName);
             declareFunctionGlobal('', $fName, $fArgs, $callback);
         }
     }
     if (array_key_exists('methods', $args)) {
         foreach ($args['methods'] as $method) {
             $mName = get_first_key($method, ['name', 0]);
             $mArgs = get_first_key($method, ['args', 1]);
             $mRet = get_first_key($method, ['result', 2]);
             $mDet = get_first_key_default($method, ['deterministic', 3], false);
             if ($mRet == '@type') {
                 $mRet = $this->value();
             }
             foreach ($mArgs as &$mArg) {
                 if ($mArg == '@type') {
                     $mArg = $this->value();
                 }
             }
             //fwrite(STDERR, 'Defining method ' . $this->value() . '->' . $mName .
             //'(' . implode(', ', $mArgs ) . ') : ' . $mRet . PHP_EOL );
             $info = new MethodInfo($mName, $mArgs, $mRet, $mDet);
             if (!array_key_exists($mName, $this->methods)) {
                 $this->methods[$mName] = [$info];
             } else {
                 foreach ($this->methods[$mName] as $cm) {
                     if ($info == $cm) {
                         grokit_error('Attempting to multiply define method ' . $this->value() . '->' . $mName . '(' . implode(', ', $mArgs) . ')');
                     }
                 }
                 $this->methods[$mName][] = $info;
             }
         }
     }
     if (array_key_exists('describe_json', $args)) {
         $this->describers['json'] = $args['describe_json'];
     }
 }