diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-15 15:33:47 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-15 15:33:47 -0400 |
| commit | e422079fcced744e3a6247aeb12a09a658989072 (patch) | |
| tree | 393d5e52ba67dcc822ccfa9a812198edda5e735d /environment.c | |
| parent | 259c7efcf8c3808d8151d8e15f1167ad2b6f2ca7 (diff) | |
Add a Byte datatype
Diffstat (limited to 'environment.c')
| -rw-r--r-- | environment.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/environment.c b/environment.c index c0c85388..e0781468 100644 --- a/environment.c +++ b/environment.c @@ -88,6 +88,11 @@ env_t *new_compilation_unit(CORD *libname) {"from_text", "Bool$from_text", "func(text:Text)->Bool?"}, {"random", "Bool$random", "func(p=0.5)->Bool"}, )}, + {"Byte", Type(ByteType), "Byte_t", "Byte$info", TypedArray(ns_entry_t, + {"max", "Byte$max", "Byte"}, + {"min", "Byte$min", "Byte"}, + {"random", "Byte$random", "func(min=Byte.min, max=Byte.max)->Byte"}, + )}, {"Int", Type(BigIntType), "Int_t", "Int$info", TypedArray(ns_entry_t, {"abs", "Int$abs", "func(x:Int)->Int"}, {"bit_and", "Int$bit_and", "func(x:Int,y:Int)->Int"}, @@ -129,8 +134,9 @@ env_t *new_compilation_unit(CORD *libname) {"modulo", "Int64$modulo", "func(x:Int64,y:Int64)->Int64"}, {"modulo1", "Int64$modulo1", "func(x:Int64,y:Int64)->Int64"}, {"octal", "Int64$octal", "func(i:Int64, digits=0, prefix=yes)->Text"}, - {"random", "Int64$random", "func(min=-0x8000000000000000_i64, max=0x7FFFFFFFFFFFFFFF_i64)->Int64"}, {"to", "Int64$to", "func(from:Int64,to:Int64)->Range"}, + // Must be defined after min/max: + {"random", "Int64$random", "func(min=Int64.min, max=Int64.max)->Int64"}, )}, {"Int32", Type(IntType, .bits=TYPE_IBITS32), "Int32_t", "Int32$info", TypedArray(ns_entry_t, {"abs", "abs", "func(i:Int32)->Int32"}, @@ -145,8 +151,9 @@ env_t *new_compilation_unit(CORD *libname) {"modulo", "Int32$modulo", "func(x:Int32,y:Int32)->Int32"}, {"modulo1", "Int32$modulo1", "func(x:Int32,y:Int32)->Int32"}, {"octal", "Int32$octal", "func(i:Int32, digits=0, prefix=yes)->Text"}, - {"random", "Int32$random", "func(min=-0x80000000_i32, max=0x7FFFFFFF_i32)->Int32"}, {"to", "Int32$to", "func(from:Int32,to:Int32)->Range"}, + // Must be defined after min/max: + {"random", "Int32$random", "func(min=Int32.min, max=Int32.max)->Int32"}, )}, {"Int16", Type(IntType, .bits=TYPE_IBITS16), "Int16_t", "Int16$info", TypedArray(ns_entry_t, {"abs", "abs", "func(i:Int16)->Int16"}, @@ -161,8 +168,9 @@ env_t *new_compilation_unit(CORD *libname) {"modulo", "Int16$modulo", "func(x:Int16,y:Int16)->Int16"}, {"modulo1", "Int16$modulo1", "func(x:Int16,y:Int16)->Int16"}, {"octal", "Int16$octal", "func(i:Int16, digits=0, prefix=yes)->Text"}, - {"random", "Int16$random", "func(min=-0x8000_i16, max=0x7FFF_i16)->Int16"}, {"to", "Int16$to", "func(from:Int16,to:Int16)->Range"}, + // Must be defined after min/max: + {"random", "Int16$random", "func(min=Int16.min, max=Int16.max)->Int16"}, )}, {"Int8", Type(IntType, .bits=TYPE_IBITS8), "Int8_t", "Int8$info", TypedArray(ns_entry_t, {"abs", "abs", "func(i:Int8)->Int8"}, @@ -177,8 +185,9 @@ env_t *new_compilation_unit(CORD *libname) {"modulo", "Int8$modulo", "func(x:Int8,y:Int8)->Int8"}, {"modulo1", "Int8$modulo1", "func(x:Int8,y:Int8)->Int8"}, {"octal", "Int8$octal", "func(i:Int8, digits=0, prefix=yes)->Text"}, - {"random", "Int8$random", "func(min=-0x80_i8, max=0x7F_i8)->Int8"}, {"to", "Int8$to", "func(from:Int8,to:Int8)->Range"}, + // Must be defined after min/max: + {"random", "Int8$random", "func(min=Int8.min, max=Int8.max)->Int8"}, )}, #define C(name) {#name, "M_"#name, "Num"} #define F(name) {#name, #name, "func(n:Num)->Num"} @@ -250,11 +259,12 @@ env_t *new_compilation_unit(CORD *libname) {"escape_text", "Pattern$escape_text", "func(text:Text)->Pattern"}, )}, {"Path", Type(TextType, .lang="Path", .env=namespace_env(env, "Path")), "Text_t", "Text$info", TypedArray(ns_entry_t, - {"append", "Path$append", "func(path:Path, text:Text, permissions=0o644_i32)"}, + {"append", "Path$append", "func(path:Path, text:Text, permissions=0o644[32])"}, + {"append_bytes", "Path$append_bytes", "func(path:Path, bytes:[Byte], permissions=0o644[32])"}, {"base_name", "Path$base_name", "func(path:Path)->Text"}, {"by_line", "Path$by_line", "func(path:Path)->func()->Text?"}, {"children", "Path$children", "func(path:Path, include_hidden=no)->[Path]"}, - {"create_directory", "Path$create_directory", "func(path:Path, permissions=0o644_i32)"}, + {"create_directory", "Path$create_directory", "func(path:Path, permissions=0o644[32])"}, {"escape_int", "Int$value_as_text", "func(i:Int)->Path"}, {"escape_path", "Path$escape_path", "func(path:Path)->Path"}, {"escape_text", "Path$escape_text", "func(text:Text)->Path"}, @@ -268,13 +278,16 @@ env_t *new_compilation_unit(CORD *libname) {"is_symlink", "Path$is_symlink", "func(path:Path)->Bool"}, {"parent", "Path$parent", "func(path:Path)->Path"}, {"read", "Path$read", "func(path:Path)->Text"}, + {"read_bytes", "Path$read_bytes", "func(path:Path)->[Byte]"}, {"relative", "Path$relative", "func(path:Path, relative_to=(./))->Path"}, {"remove", "Path$remove", "func(path:Path, ignore_missing=no)"}, {"resolved", "Path$resolved", "func(path:Path, relative_to=(./))->Path"}, {"subdirectories", "Path$children", "func(path:Path, include_hidden=no)->[Path]"}, {"unique_directory", "Path$unique_directory", "func(path:Path)->Path"}, - {"write", "Path$write", "func(path:Path, text:Text, permissions=0o644_i32)"}, + {"write", "Path$write", "func(path:Path, text:Text, permissions=0o644[32])"}, + {"write_bytes", "Path$write_bytes", "func(path:Path, bytes:[Byte], permissions=0o644[32])"}, {"write_unique", "Path$write_unique", "func(path:Path, text:Text)->Path"}, + {"write_unique_bytes", "Path$write_unique_bytes", "func(path:Path, bytes:[Byte])->Path"}, )}, {"Shell", Type(TextType, .lang="Shell", .env=namespace_env(env, "Shell")), "Shell_t", "Shell$info", TypedArray(ns_entry_t, {"escape_int", "Int$value_as_text", "func(i:Int)->Shell"}, @@ -287,7 +300,7 @@ env_t *new_compilation_unit(CORD *libname) {"ends_with", "Text$ends_with", "func(text:Text, suffix:Text)->Bool"}, {"find", "Text$find", "func(text:Text, pattern:Pattern, start=1, length=!&Int64)->Int"}, {"find_all", "Text$find_all", "func(text:Text, pattern:Pattern)->[Text]"}, - {"from_bytes", "Text$from_bytes", "func(bytes:[Int8])->Text"}, + {"from_bytes", "Text$from_bytes", "func(bytes:[Byte])->Text"}, {"from_c_string", "Text$from_str", "func(str:CString)->Text"}, {"from_codepoint_names", "Text$from_codepoint_names", "func(codepoint_names:[Text])->Text"}, {"from_codepoints", "Text$from_codepoints", "func(codepoints:[Int32])->Text"}, @@ -309,7 +322,7 @@ env_t *new_compilation_unit(CORD *libname) {"trim", "Text$trim", "func(text:Text, pattern=$/{whitespace}/, trim_left=yes, trim_right=yes)->Text"}, {"upper", "Text$upper", "func(text:Text)->Text"}, {"utf32_codepoints", "Text$utf32_codepoints", "func(text:Text)->[Int32]"}, - {"utf8_bytes", "Text$utf8_bytes", "func(text:Text)->[Int8]"}, + {"utf8_bytes", "Text$utf8_bytes", "func(text:Text)->[Byte]"}, )}, {"Thread", THREAD_TYPE, "pthread_t*", "Thread", TypedArray(ns_entry_t, {"new", "Thread$new", "func(fn:func())->Thread"}, |
