Giter Club home page Giter Club logo

Comments (2)

hikarin avatar hikarin commented on August 18, 2024

make a new function:
void compileSymbolList(char* var, Cell* symbolList)
{
Cell tmp = malloc(sizeof(struct cell));
size_t len = strlen(var) + 1;
char* sym = malloc(len);

strcpy(sym, var);
car(tmp) = (Cell)sym;
cdr(tmp) = *symbolList;
*symbolList = tmp;

}

to use here:
while ((c = fgetc(fp)) != ')')
{
ungetc(c, fp);
char buf[LINESIZE];
char* var = readToken(buf, sizeof(buf), fp);
if (strcmp(var, ".") == 0)
{
var = readToken(buf, sizeof(buf), fp);
compileSymbolList(var, &symbolList);

        if (strcmp(var, ")") != 0)
        {
            AQ_PRINTF("Too much elements are given to dot list.\n");
            return;
        }

        index++;

        var = readToken(buf, sizeof(buf), fp);


        break;
    }
    else
    {
        var = readToken(buf, sizeof(buf), fp);
        compileSymbolList(var, &symbolList);

        index++;
    }
}

from aquario.

hikarin avatar hikarin commented on August 18, 2024

In execute(),

        case FUNCSM:
        {
            Cell l = popArg();
            int argNum = ivalue(stack[stack_top - 1]);
            int paramNum = ivalue(lambdaParamNum(l));
            if (paramNum > argNum)
            {
                AQ_PRINTF("param num is wrong: %d, %d\n", paramNum, argNum);
                ++pc;
                break;
            }

            popArg();
            int num = argNum - paramNum + 1;
            Cell lst = (Cell)AQ_NIL;
            for (i = 0; i < num; i++)
            {
                lst = pairCell(stack[stack_top - 1], lst);
                popArg();
            }
            pushArg(lst);
            pushArg(makeInteger(paramNum));

            int retAddr = pc + 1;
            pushArg(makeInteger(retAddr));
            updateOffsetReg();

            // jump
            int funcAddr = ivalue(lambdaAddr(l));
            pc = funcAddr;
        }

from aquario.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.