コード例 #1
0
ファイル: eval.c プロジェクト: gvvaughan/luajit-zile
static le *
evaluateBranch (le * trybranch)
{
  le *keyword;
  fentry * func;

  if (trybranch == NULL)
    return NULL;

  if (trybranch->branch)
    keyword = evaluateBranch (trybranch->branch);
  else
    keyword = leNew (trybranch->data);

  if (keyword->data == NULL)
    {
      leWipe (keyword);
      return leNIL;
    }

  func = get_fentry (keyword->data);
  leWipe (keyword);
  if (func)
    return func->func (1, false, trybranch);

  return NULL;
}
コード例 #2
0
ファイル: eval.c プロジェクト: iPodLinux-Community/podzillaz
le * evaluateNode( lithp_burrito * lb, le * node)
{
    le * temp;
    le * value;

    if (node->branch) {
        if( node->quoted ) {
            value = leDup( node->branch );
        } else {
            value = evaluateBranch( lb, node->branch );
        }
    } else {
        temp = variableGet( lb->defunList, node->data );

        if (temp) {
            value = evaluateDefun( lb, temp, node->list_next );
        } else {
            temp = variableGet( lb->mainVarList, node->data );
            if (temp) {
                value = leDup( temp );
            } else {
                value = leNew( node->data );
            }
        }
    }

    return( value );
}
コード例 #3
0
ファイル: eval.c プロジェクト: iPodLinux-Community/podzillaz
le * evaluateBranch( lithp_burrito *lb, le * trybranch)
{
    le * keyword;
    int tryit = 0;
    if (!trybranch) return( NULL );

    if (trybranch->branch) {
        keyword = evaluateBranch(lb, trybranch->branch);
    } else
        keyword = leNew( trybranch->data );

    if (!keyword->data) {
        leWipe( keyword );
        return( leNew( "NIL" ));
    }

    for ( tryit=0 ; evalTable[tryit].word ; tryit++) {
        if (!strcmp(evalTable[tryit].word, keyword->data)) {
            leWipe( keyword );
            return( evalTable[tryit].callback(
                        lb,
                        countNodes( trybranch ),
                        trybranch) );
        }
    }

    leWipe( keyword );
    return( evaluateNode( lb, trybranch ));
}
コード例 #4
0
ファイル: eval.c プロジェクト: iPodLinux-Community/podzillaz
le * evaluateDefun( lithp_burrito *lb, le * fcn, le * params )
{
    le * function;
    le * thisparam;
    le * result;
    int count;

    /* make sure both lists exist */
    if (!fcn)  return( leNew( "NIL" ));

    /* check for the correct number of parameters */
    if (countNodes(fcn->branch) > countNodes(params))
        return( leNew( "NIL" ));

    /* allocate another function definition, since we're gonna hack it */
    function = leDup(fcn);

    /* pass 1:  tag each node properly.
    	    for each parameter: (fcn)
    	    - look for it in the tree, tag those with the value
    */
    count = 0;
    thisparam = fcn->branch;
    while (thisparam)
    {
        leTagData(function, thisparam->data, count);
        thisparam = thisparam->list_next;
        count++;
    }

    /* pass 2:  replace
    	    for each parameter: (param)
    	    - evaluate the passed in value
    	    - replace it in the tree
    */
    count = 0;
    thisparam = params;
    while (thisparam)
    {
        result = evaluateNode( lb, thisparam );
        leTagReplace(function, count, result);
        thisparam = thisparam->list_next;
        leWipe(result);
        count++;
    }

    /* then evaluate the resulting tree */
    result = evaluateBranch( lb, function->list_next );

    /* free any space allocated */
    leWipe( function );

    /* return the evaluation */
    return( result );
}
コード例 #5
0
ファイル: eval.c プロジェクト: iPodLinux-Community/podzillaz
le * eval_cb_eval( lithp_burrito * lb, const int argc, le * branch )
{
    le * temp;
    le * retval;
    if (!branch || argc != 2 ) return( leNew( "NIL" ));

    temp = evaluateNode(lb, branch->list_next);
    retval = evaluateBranch(lb, temp);
    leWipe( temp );
    return( retval );
}
コード例 #6
0
ファイル: eval.c プロジェクト: gvvaughan/luajit-zile
static le *
evaluateNode (le * node)
{
  le *value;

  if (node == NULL)
    return leNIL;

  if (node->branch != NULL)
    {
      if (node->quoted)
        value = leDup (node->branch);
      else
        value = evaluateBranch (node->branch);
    }
  else
    {
      const char *s = get_variable (node->data);
      value = leNew (s ? s : node->data);
    }

  return value;
}