diff --git a/src/builtins/basic.c b/src/builtins/basic.c index b803e26..eb3a099 100644 --- a/src/builtins/basic.c +++ b/src/builtins/basic.c @@ -88,6 +88,38 @@ static Object *bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, E return Object_FromInt(ret,Runtime_GetHeap(runtime),error); } +static Object *bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Error *error) +{ + + assert(argc == 1); + + + if(!Object_IsInt(argv[0])) + { + Error_Report(error, 0, "Argument #%d is not a integer", 1); + return NULL; + } + + + char buff[32]; + + int value = Object_ToInt(argv[0],error); + + if(error->occurred) + return NULL; + + + int k = utf8_sequence_from_utf32_codepoint(buff,sizeof(buff),value); + + if(k<0) + { + Error_Report(error, 0, "Argument #%d is not valid utf-32", 1); + return NULL; + } + + return Object_FromString(buff,k,Runtime_GetHeap(runtime),error); +} + static Object *bin_count(Runtime *runtime, Object **argv, unsigned int argc, Error *error) { assert(argc == 1); @@ -284,6 +316,7 @@ const StaticMapSlot bins_basic[] = { { "type", SM_FUNCT, .as_funct = bin_type, .argc = 1 }, { "unicode", SM_FUNCT, .as_funct = bin_unicode, .argc = 1 }, + { "chr", SM_FUNCT, .as_funct = bin_chr, .argc = 1 }, { "print", SM_FUNCT, .as_funct = bin_print, .argc = -1 }, { "input", SM_FUNCT, .as_funct = bin_input, .argc = 0 }, { "count", SM_FUNCT, .as_funct = bin_count, .argc = 1 },