Embedding Instructions
Getting Started
git clone https://github.com/uniot-io/uniot-lisp.git#include "libminilisp.h"
void printOut(const char *msg, int size) { fprintf(stdout, "OUT: %s\n", msg); } void printLog(const char *msg, int size) { fprintf(stdout, "LOG: %s\n", msg); } void printErr(const char *msg, int size) { fprintf(stderr, "ERR: %s\n", msg); }void *env_constructor[3]; void *root = NULL; Obj **genv; env_constructor[0] = root; env_constructor[1] = NULL; env_constructor[2] = ROOT_END; root = env_constructor; genv = (Obj **)(env_constructor + 1);// Initialize the interpreter with a specified memory size (e.g., 4096 bytes) lisp_create(4096); lisp_set_printers(printOut, printLog, printErr); // Create a global environment and define constants and primitives *genv = make_env(root, &Nil, &Nil); define_constants(root, genv); define_primitives(root, genv);const char *code = "(+ 1 2 3)"; if (lisp_eval(root, genv, code)) { // Evaluation succeeded } else { // Handle evaluation error }lisp_destroy();#include <stdio.h> #include "UniotLisp.h" void printOut(const char *msg, int size) { fprintf(stdout, "OUT: %s\n", msg); } void printLog(const char *msg, int size) { fprintf(stdout, "LOG: %s\n", msg); } void printErr(const char *msg, int size) { fprintf(stderr, "ERR: %s\n", msg); } int main() { void *env_constructor[3]; void *root = NULL; Obj **genv; env_constructor[0] = root; env_constructor[1] = NULL; env_constructor[2] = ROOT_END; root = env_constructor; genv = (Obj **)(env_constructor + 1); lisp_create(4096); lisp_set_printers(printOut, printLog, printErr); *genv = make_env(root, &Nil, &Nil); define_constants(root, genv); define_primitives(root, genv); const char *code = "(+ 1 2 3)"; if (lisp_eval(root, genv, code)) { // Evaluation succeeded } else { // Handle evaluation error } lisp_destroy(); return 0; }
Basic Concepts
Object Representation
Obj Structure
Type Tags
Memory Management and Garbage Collection
Copying Garbage Collector
Allocation Strategy
Parsing and Evaluation
Parsing
Evaluation
Adding New Primitives
Defining a Primitive Function
Registering the Primitive
Adding Constants
Registering the Constant
Error Handling
Error Function
Non-Local Exits
Common Error Scenarios
API Usage
Lifecycle Management
Evaluation Interface
Configuration
System Information
Conclusion
Last updated