Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| summerofcode2014:lualoader [2014/07/26 01:05] – PedroSouza | summerofcode2014:lualoader [2014/09/25 01:05] (current) – PedroSouza | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ===== Project description ===== | ===== Project description ===== | ||
| - | This project aims to make the Loader | + | The project aims to design and implement a modular interface for the loader |
| + | interpreter | ||
| + | |||
| + | Thus one can divide the project in two tasks: | ||
| + | * Design a modular interface | ||
| + | interpreters (**// | ||
| + | * Implement | ||
| + | scripts. | ||
| + | |||
| + | With this approach one want to provide a easy way to choose (at compile time) which\\ | ||
| + | interpreter the loader will use, and also provide a skeleton for adding others scripting\\ | ||
| + | languages. | ||
| ===== Approach to solving the problem ===== | ===== Approach to solving the problem ===== | ||
| - | Based on the interface | + | ==== Interface design ==== |
| - | * The already present Forth interpreter | + | // |
| - | * Implement | + | |
| - | * Incrementally add functionalities | + | < |
| - | * Handle | + | typedef void interp_init_t(void *ctx); |
| + | typedef int interp_run_t(void *ctx, const char *input); | ||
| + | typedef int interp_incl_t(void *ctx, const char *filename); | ||
| + | typedef int interp_load_def_t(void *ctx); | ||
| + | |||
| + | struct interp { | ||
| + | interp_init_t *init; | ||
| + | interp_run_t *run; | ||
| + | interp_incl_t *incl; | ||
| + | interp_load_def_t *load_configs; | ||
| + | void *context; | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | The above C code shows the interpreter | ||
| + | |||
| + | * **init** Initializes the interpreter. Should | ||
| + | |||
| + | * **run** Interpretes and runs the passed string. | ||
| + | |||
| + | * **incl** Reads the file contents to a string and run it. | ||
| + | |||
| + | * **load_configs** Loads the default boot configuration file. (loader.rc for Forth, loader.lua for Lua). | ||
| + | |||
| + | * **context** Pointer to interpreter/ | ||
| + | |||
| + | ==== Lua interp implementation ==== | ||
| + | |||
| + | The lua interpreter is written in C and it uses some standard C functions. To embedded\\ | ||
| + | Lua into to loader the missing standard C functions (not present in libstand) where added\\ | ||
| + | in // | ||
| + | |||
| + | With the Lua embedded into the loader the **interp** interface was implemented in \\ | ||
| + | // | ||
| + | |||
| + | ==== Lua scripts ==== | ||
| + | |||
| + | The scripts where implemented to match all the features | ||
| + | except for the PNP script (// | ||
| + | to its functions and I treated it as deprecated. | ||
| + | |||
| + | The scripts are located at // | ||
| + | which implements | ||
| + | |||
| + | * **loader.perform(string)** Perform a loader command. | ||
| + | * **loader.delay(time)** Delay function, time is passed in microsencods (1/1000 miliseconds). | ||
| + | * **loader.time()** Wrapper for C time function. | ||
| + | * **loader.include(filename)** Includes a lua script. Notice that it does not prevent multiple inclusion of the same file. | ||
| + | * **loader.getenv(name)** Returns the value of the given environment variable as string or nil if it does not exists. | ||
| + | * **io.getchar()** Wrapper for C getchar function. | ||
| + | * **io.ischar()** Wrapper for ischar C function. | ||
| + | * **io.gets()** Wrapper for gets C function. | ||
| + | * **io.open(filename)** Opens the given file. Returns a file (Lua user_data) variable or nil in case of failure. | ||
| + | * **io.close(file)** Closes the given file. | ||
| + | * **io.read(file, [size])** Returns S, R where S is a string containing | ||
| + | If size parameter is nil the function reads the whole file. | ||
| + | |||
| + | Besides these builtin functions all functions from Lua baselib and stringlib are provided. | ||
| + | |||
| + | List of lua scripts: | ||
| + | |||
| + | * **config.lua**: | ||
| + | * **core.lua**: | ||
| + | * **loader.lua**: | ||
| + | * **menu.lua**: | ||
| + | * **password.lua**: | ||
| + | * **screen.lua**: | ||
| ===== Deliverables ===== | ===== Deliverables ===== | ||
| Line 19: | Line 96: | ||
| * Lua interpreter module | * Lua interpreter module | ||
| * Lua scripts providing advanced boot options | * Lua scripts providing advanced boot options | ||
| - | * Lua parser for .conf and .rc files | + | * Lua parser for .conf files |
| ===== Milestones ===== | ===== Milestones ===== | ||
| - | | + | | Interpreter interface definition | **//DONE//** || |
| - | * 2 weeks - Port Lua interpreter | + | | Adapt existing interpretes to the interface | **//DONE//** || |
| - | * 1 week - Implement | + | | Lua interpreter working |
| - | * 5 weeks - Incrementally add Lua script functionalities | + | | Lua loader builtin functions || |
| - | * 1 week - Implement the .conf and .rc parser. | + | | loader.%%**%%%%**%% functions | **// |
| - | * 1 week - Write the documentation. | + | | Lua file io functions | **//DONE//** || |
| + | | Lua base library | **// | ||
| + | | Lua string library | **// | ||
| + | | Kernel loading functions | **// | ||
| + | | || | ||
| + | | Config file parsing | ||
| + | | Boot menu | **// | ||
| + | | < | ||
| + | |||
| + | ==== New milestones ==== | ||
| + | |||
| + | | Fix //drawer.isColorEnabled()// | ||
| + | | Fix // | ||
| + | | Merge //menu.options.alias// with //menu.options// | **// | ||
| + | | Fix //kernels// menu option logic | **//DONE//** || | ||
| + | | Add dynamic menu options ordering (boot simple/ | ||
| + | | Fix ANSI vs non-ANSI coloring | **//NEED TEST//** || | ||
| + | |||
| + | ===== Testing ===== | ||
| + | |||
| + | Checkout | ||
| + | |||
| + | < | ||
| + | $svn co https:// | ||
| + | </ | ||
| + | |||
| + | By default the Lua interpreter is enabled, to revert to the Forth interpreter | ||
| + | edit /// | ||
| + | |||
| + | < | ||
| + | WITH_FORTH=" | ||
| + | WITHOUT_LUA=" | ||
| + | </ | ||
| + | |||
| + | or if you want to disable both Lua and Forth and use the simple interpreter: | ||
| + | |||
| + | < | ||
| + | WITHOUT_FORTH=" | ||
| + | WITHOUT_LUA=" | ||
| + | </ | ||
| - | ===== Test Plan ===== | + | Then build and install the boot loader: |
| - | List of features integrated | + | |
| - | | Lua interpreter working with the loader | DONE || | + | < |
| - | | Lua loader functions (perform, set/get environment var, etc) | DONE || | + | $cd head/sys/boot |
| - | | Lua file handling and include functions | DONE || | + | $make |
| - | | Lua string library | DONE || | + | $su |
| - | | Kernel loading functions | DONE || | + | $make install |
| - | | Config file parsing and mudule loading | DONE || | + | </ |
| - | | Boot menu | BASIC || | + | |
| - | | %%PnP%% config & setup | TODO || | + | |
| ===== The Code ===== | ===== The Code ===== | ||