Esempio n. 1
0
int terra_initwithoptions(lua_State * L, terra_Options * options) {
    terra_State * T = (terra_State*) lua_newuserdata(L, sizeof(terra_State));
    terra_ongc(L, -1, terra_free);
    assert(T);
    memset(T,0,sizeof(terra_State)); //some of lua stuff expects pointers to be null on entry
    T->options = *options;
#ifdef __arm__
    T->options.usemcjit = true; //force MCJIT since old JIT is partially broken on ARM 
#endif
    T->numlivefunctions = 1;
    T->L = L;
    assert (T->L);
    lua_newtable(T->L);
    lua_insert(L, -2);
    lua_setfield(L, -2, "__terrastate"); //reference to our T object, so that we can load it from the lua state on other API calls
    
    lua_setfield(T->L,LUA_GLOBALSINDEX,"terra"); //create global terra object
    terra_kindsinit(T); //initialize lua mapping from T_Kind to/from string
    setterrahome(T->L); //find the location of support files such as the clang resource directory
    
    int err = terra_compilerinit(T);
    if(err) {
        return err;
    }
    err =    terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_strict,luaJIT_BC_strict_SIZE, "strict.lua")
          || terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_asdl,luaJIT_BC_asdl_SIZE, "asdl.lua")
#ifndef TERRA_EXTERNAL_TERRALIB
          || terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_terralib,luaJIT_BC_terralib_SIZE, "terralib.lua");
#else
          // make it possible to quickly iterate in terralib.lua when developing
          || luaL_loadfile(T->L,TERRA_EXTERNAL_TERRALIB)
Esempio n. 2
0
int terra_init(lua_State * L) {
    terra_State * T = (terra_State*) malloc(sizeof(terra_State));
    assert(T);
    memset(T,0,sizeof(terra_State)); //some of lua stuff expects pointers to be null on entry
    T->L = L;
    assert (T->L);
    lua_newtable(T->L);
    
    lua_pushlightuserdata(L, T);
    lua_setfield(L, -2, "__terrastate"); //reference to our T object, so that we can load it from the lua state on other API calls
    
    lua_setfield(T->L,LUA_GLOBALSINDEX,"terra"); //create global terra object
    terra_kindsinit(T); //initialize lua mapping from T_Kind to/from string
    


    int err =    terra_loadandrunbytecodes(T->L,luaJIT_BC_strict,luaJIT_BC_strict_SIZE, "strict.lua")
              || terra_loadandrunbytecodes(T->L,luaJIT_BC_terralib,luaJIT_BC_terralib_SIZE, "terralib.lua");
              
    if(err) {
        free(T);
        return err;
    }
    
    terra_cwrapperinit(T);
    
    lua_getfield(T->L,LUA_GLOBALSINDEX,"terra");

    lua_pushcfunction(T->L,terra_luaload);
    lua_setfield(T->L,-2,"load");
    lua_pushcfunction(T->L,terra_lualoadstring);
    lua_setfield(T->L,-2,"loadstring");
    lua_pushcfunction(T->L,terra_lualoadfile);
    lua_setfield(T->L,-2,"loadfile");
    
    lua_newtable(T->L);
    lua_setfield(T->L,-2,"_trees"); //to hold parser generated trees
    lua_pop(T->L,1);
    
    luaX_init(T);
    
    err = terra_compilerinit(T);
    if(err) {
        free(T);
        return err;
    }

    err = terra_cudainit(T); /* if cuda is not enabled, this does nothing */
    if(err) {
        free(T);
        return err;
    }

    return 0;   
}
Esempio n. 3
0
int terra_initwithoptions(lua_State * L, terra_Options * options) {
    terra_State * T = (terra_State*) lua_newuserdata(L, sizeof(terra_State));
    terra_ongc(L, -1, terra_free);
    assert(T);
    memset(T,0,sizeof(terra_State)); //some of lua stuff expects pointers to be null on entry
    T->options = *options;
#ifdef __arm__
    T->options.usemcjit = true; //force MCJIT since old JIT is partially broken on ARM 
#endif
    T->numlivefunctions = 1;
    T->L = L;
    assert (T->L);
    lua_newtable(T->L);
    lua_insert(L, -2);
    lua_setfield(L, -2, "__terrastate"); //reference to our T object, so that we can load it from the lua state on other API calls
    
    lua_setfield(T->L,LUA_GLOBALSINDEX,"terra"); //create global terra object
    terra_kindsinit(T); //initialize lua mapping from T_Kind to/from string
    setterrahome(T->L); //find the location of support files such as the clang resource directory
    
    int err = terra_compilerinit(T);
    if(err) {
        return err;
    }
    err =    terra_loadandrunbytecodes(T->L,luaJIT_BC_strict,luaJIT_BC_strict_SIZE, "strict.lua")
          || terra_loadandrunbytecodes(T->L,luaJIT_BC_terralib,luaJIT_BC_terralib_SIZE, "terralib.lua");
              
    if(err) {
        return err;
    }
    
    terra_cwrapperinit(T);
    
    lua_getfield(T->L,LUA_GLOBALSINDEX,"terra");

    lua_pushcfunction(T->L,terra_luaload);
    lua_setfield(T->L,-2,"load");
    lua_pushcfunction(T->L,terra_lualoadstring);
    lua_setfield(T->L,-2,"loadstring");
    lua_pushcfunction(T->L,terra_lualoadfile);
    lua_setfield(T->L,-2,"loadfile");
    
    lua_newtable(T->L);
    lua_setfield(T->L,-2,"_trees"); //to hold parser generated trees
    
    lua_pushinteger(L, T->options.verbose);
    lua_setfield(L, -2, "isverbose");
    lua_pushinteger(L, T->options.debug);
    lua_setfield(L, -2, "isdebug");
    
    terra_registerinternalizedfiles(L,-1);
    lua_pop(T->L,1); //'terra' global
    
    luaX_init(T);
    terra_debuginit(T);
    err = terra_cudainit(T); /* if cuda is not enabled, this does nothing */
    if(err) {
        return err;
    }
    return 0;   
}