Merge pull request #7 from JustJ3di/main

Added new built in function
This commit is contained in:
Francesco Cozzuto
2022-04-04 00:44:14 +02:00
committed by GitHub
+33
View File
@@ -88,6 +88,38 @@ static Object *bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, E
return Object_FromInt(ret,Runtime_GetHeap(runtime),error); 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) static Object *bin_count(Runtime *runtime, Object **argv, unsigned int argc, Error *error)
{ {
assert(argc == 1); assert(argc == 1);
@@ -284,6 +316,7 @@ const StaticMapSlot bins_basic[] = {
{ "type", SM_FUNCT, .as_funct = bin_type, .argc = 1 }, { "type", SM_FUNCT, .as_funct = bin_type, .argc = 1 },
{ "unicode", SM_FUNCT, .as_funct = bin_unicode, .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 }, { "print", SM_FUNCT, .as_funct = bin_print, .argc = -1 },
{ "input", SM_FUNCT, .as_funct = bin_input, .argc = 0 }, { "input", SM_FUNCT, .as_funct = bin_input, .argc = 0 },
{ "count", SM_FUNCT, .as_funct = bin_count, .argc = 1 }, { "count", SM_FUNCT, .as_funct = bin_count, .argc = 1 },