@@ -235,88 +235,85 @@ functionality, I/O operations, and performance-critical code written in C.
235235Native functions in C must follow this signature:
236236
237237``` c
238- tea_value_t your_function_name (tea_context_t * context, const tea_function_args_t * args)
238+ tea_val_t your_function_name (tea_ctx_t * context, const tea_fn_args_t * args)
239239```
240240
241241The function receives a context and a list of arguments, and must return a `tea_value_t`. Arguments are accessed by calling `tea_function_args_pop()` in a loop. Here's an example:
242242
243243```c
244244// Native function to print values (similar to built-in print)
245- static tea_value_t tea_print_values(tea_context_t * context, const tea_function_args_t * args) {
245+ static tea_val_t tea_print_values(tea_ctx_t * context, const tea_fn_args_t * args) {
246246 for (;;) {
247- tea_variable_t * arg = tea_function_args_pop (args);
247+ tea_var_t * arg = tea_fn_args_pop (args);
248248 if (!arg) {
249249 break; // No more arguments
250250 }
251251
252- const tea_value_t value = arg->value ;
252+ const tea_val_t value = arg->val ;
253253 switch (value.type) {
254- case TEA_VALUE_I32 :
254+ case TEA_V_I32 :
255255 printf("%d ", value.i32);
256256 break;
257- case TEA_VALUE_F32 :
257+ case TEA_V_F32 :
258258 printf("%f ", value.f32);
259259 break;
260- case TEA_VALUE_STRING:
261- printf("%s ", value.string);
262- break;
263- case TEA_VALUE_INSTANCE:
264- case TEA_VALUE_INVALID:
260+ case TEA_V_INST:
261+ case TEA_V_UNDEF:
265262 break;
266263 }
267264
268- tea_free_variable (context, arg);
265+ tea_free_var (context, arg);
269266 }
270267 printf("\n");
271268
272- return tea_value_invalid ();
269+ return tea_val_undef ();
273270}
274271
275272// Native function to add two numbers
276- static tea_value_t tea_add_numbers(tea_context_t * context, const tea_function_args_t * args) {
277- tea_variable_t * arg1 = tea_function_args_pop (args);
278- tea_variable_t * arg2 = tea_function_args_pop (args);
273+ static tea_val_t tea_add_numbers(tea_ctx_t * context, const tea_fn_args_t * args) {
274+ tea_var_t * arg1 = tea_fn_args_pop (args);
275+ tea_var_t * arg2 = tea_fn_args_pop (args);
279276
280277 if (!arg1 || !arg2) {
281278 // Handle error case - not enough arguments
282- if (arg1) tea_free_variable (context, arg1);
283- if (arg2) tea_free_variable (context, arg2);
284- return tea_value_invalid ();
279+ if (arg1) tea_free_var (context, arg1);
280+ if (arg2) tea_free_var (context, arg2);
281+ return tea_val_undef ();
285282 }
286283
287- if (arg1->value .type == TEA_VALUE_I32 && arg2->value .type == TEA_VALUE_I32 ) {
288- tea_value_t result = {0};
289- result.type = TEA_VALUE_I32 ;
290- result.i32 = arg1->value .i32 + arg2->value .i32;
284+ if (arg1->val .type == TEA_V_I32 && arg2->val .type == TEA_V_I32 ) {
285+ tea_val_t result = {0};
286+ result.type = TEA_V_I32 ;
287+ result.i32 = arg1->val .i32 + arg2->val .i32;
291288
292- tea_free_variable (context, arg1);
293- tea_free_variable (context, arg2);
289+ tea_free_var (context, arg1);
290+ tea_free_var (context, arg2);
294291 return result;
295292 }
296293
297- tea_free_variable (context, arg1);
298- tea_free_variable (context, arg2);
299- return tea_value_invalid ();
294+ tea_free_var (context, arg1);
295+ tea_free_var (context, arg2);
296+ return tea_val_undef ();
300297}
301298```
302299
303300### Binding Functions
304301
305- Register your native functions with the Tea context using ` tea_bind_native_function ` :
302+ Register your native functions with the Tea context using ` tea_bind_native_fn ` :
306303
307304``` c
308305int main () {
309- tea_context_t context;
310- tea_interpret_init (&context, "example.tea");
306+ tea_ctx_t context;
307+ tea_interp_init (&context, "example.tea");
311308
312309 // Bind native functions
313- tea_bind_native_function (&context, "print", tea_print);
314- tea_bind_native_function (&context, "add_numbers", tea_add_numbers);
315- tea_bind_native_function (&context, "print_values", tea_print_values);
310+ tea_bind_native_fn (&context, "print", tea_print);
311+ tea_bind_native_fn (&context, "add_numbers", tea_add_numbers);
312+ tea_bind_native_fn (&context, "print_values", tea_print_values);
316313
317314 // Execute Tea code...
318315
319- tea_interpret_cleanup (&context);
316+ tea_interp_cleanup (&context);
320317 return 0;
321318}
322319```
@@ -339,23 +336,23 @@ print_values('Result:', sum, 'Done');
339336
340337### Tea Value Types
341338
342- Native functions work with the ` tea_value_t ` type system:
339+ Native functions work with the ` tea_val_t ` type system:
343340
344- - ` TEA_VALUE_I32 ` - 32-bit signed integers
345- - ` TEA_VALUE_F32 ` - 32-bit floating-point numbers
346- - ` TEA_VALUE_STRING ` - Null-terminated strings
347- - ` TEA_VALUE_INSTANCE ` - Complex objects (structs)
348- - ` TEA_VALUE_INVALID ` - Uninitialized or error state
341+ - ` i32 ` (TEA_V_I32) - 32-bit signed integers
342+ - ` f32 ` (TEA_V_F32) - 32-bit floating-point numbers
343+ - ` string ` (TEA_V_INST) - Null-terminated strings wrapped as instances
344+ - ` instance ` (TEA_V_INST) - Complex objects (structs)
345+ - ` undef ` (TEA_V_UNDEF) - Uninitialized or error state
349346
350347### Best Practices
351348
352- 1 . ** Always validate arguments** : Use ` tea_function_args_pop ()` to safely access arguments and check for NULL
353- 2 . ** Handle errors gracefully** : Return ` tea_value_invalid ()` for error conditions
349+ 1 . ** Always validate arguments** : Use ` tea_fn_args_pop ()` to safely access arguments and check for NULL
350+ 2 . ** Handle errors gracefully** : Return ` tea_val_undef ()` for error conditions
3543513 . ** Memory management** :
355- - Always call ` tea_free_variable (context, arg)` for each argument you pop
356- - Strings returned from native functions should be allocated with ` rtl_malloc `
352+ - Always call ` tea_free_var (context, arg)` for each argument you pop
353+ - Strings returned from native functions should be allocated with ` tea_malloc `
3573544 . ** Performance** : Use native functions for computationally intensive operations
358- 5 . ** Argument handling** : Process arguments in the order they were passed by calling ` tea_function_args_pop ()` sequentially
355+ 5 . ** Argument handling** : Process arguments in the order they were passed by calling ` tea_fn_args_pop ()` sequentially
359356
360357## Building
361358
0 commit comments