mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-26 05:07:41 +00:00 
			
		
		
		
	Update copyright to 2018. Add string methods.
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| # Copyright (c) 2017 Calvin Rose | # Copyright (c) 2018 Calvin Rose | ||||||
| #  | #  | ||||||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| # of this software and associated documentation files (the "Software"), to | # of this software and associated documentation files (the "Software"), to | ||||||
| @@ -67,10 +67,10 @@ src/core/value.c | |||||||
| src/core/vm.c | src/core/vm.c | ||||||
| src/core/wrap.c | src/core/wrap.c | ||||||
|  |  | ||||||
| src/core/gc.h |  | ||||||
| src/core/fiber.h | src/core/fiber.h | ||||||
| src/core/symcache.h | src/core/gc.h | ||||||
| src/core/state.h | src/core/state.h | ||||||
|  | src/core/symcache.h | ||||||
| src/core/util.h | src/core/util.h | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -104,9 +104,9 @@ src/include/dst/dst.h | |||||||
| src/include/dst/dstasm.h | src/include/dst/dstasm.h | ||||||
| src/include/dst/dstcompile.h | src/include/dst/dstcompile.h | ||||||
| src/include/dst/dstconfig.h | src/include/dst/dstconfig.h | ||||||
|  | src/include/dst/dstcorelib.h | ||||||
| src/include/dst/dstopcodes.h | src/include/dst/dstopcodes.h | ||||||
| src/include/dst/dstparse.h | src/include/dst/dstparse.h | ||||||
| src/include/dst/dstcorelib.h |  | ||||||
| src/include/dst/dsttypes.h | src/include/dst/dsttypes.h | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| Copyright (c) 2017 Calvin Rose | Copyright (c) 2018 Calvin Rose | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||||||
| this software and associated documentation files (the "Software"), to deal in | this software and associated documentation files (the "Software"), to deal in | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -56,7 +56,6 @@ static const DstReg cfuns[] = { | |||||||
|     {"type", dst_core_type}, |     {"type", dst_core_type}, | ||||||
|     {"next", dst_core_next}, |     {"next", dst_core_next}, | ||||||
|     {"hash", dst_core_hash}, |     {"hash", dst_core_hash}, | ||||||
|     {"string.slice", dst_core_string_slice}, |  | ||||||
|     {NULL, NULL} |     {NULL, NULL} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -104,6 +103,7 @@ DstTable *dst_stl_env(int flags) { | |||||||
|         dst_lib_parse(args); |         dst_lib_parse(args); | ||||||
|         dst_lib_compile(args); |         dst_lib_compile(args); | ||||||
|         dst_lib_asm(args); |         dst_lib_asm(args); | ||||||
|  |         dst_lib_string(args); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* Allow references to the environment */ |     /* Allow references to the environment */ | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include "gc.h" | #include "gc.h" | ||||||
|  |  | ||||||
| /* Initializes an array */ | /* Initializes an array */ | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include "gc.h" | #include "gc.h" | ||||||
|  |  | ||||||
| /* Initialize a buffer */ | /* Initialize a buffer */ | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -305,36 +305,3 @@ int dst_core_hash(DstArgs args) { | |||||||
|     DST_FIXARITY(args, 1); |     DST_FIXARITY(args, 1); | ||||||
|     DST_RETURN_INTEGER(args, dst_hash(args.v[0])); |     DST_RETURN_INTEGER(args, dst_hash(args.v[0])); | ||||||
| } | } | ||||||
|  |  | ||||||
| int dst_core_string_slice(DstArgs args) { |  | ||||||
|     const uint8_t *data; |  | ||||||
|     int32_t len, start, end; |  | ||||||
|     const uint8_t *ret; |  | ||||||
|     DST_MINARITY(args, 1); |  | ||||||
|     DST_MAXARITY(args, 3); |  | ||||||
|     DST_ARG_BYTES(data, len, args, 0); |  | ||||||
|     /* Get start */ |  | ||||||
|     if (args.n < 2) { |  | ||||||
|         start = 0; |  | ||||||
|     } else if (dst_checktype(args.v[1], DST_INTEGER)) { |  | ||||||
|         start = dst_unwrap_integer(args.v[1]); |  | ||||||
|     } else { |  | ||||||
|         DST_THROW(args, "expected integer"); |  | ||||||
|     } |  | ||||||
|     /* Get end */ |  | ||||||
|     if (args.n < 3) { |  | ||||||
|         end = -1; |  | ||||||
|     } else if (dst_checktype(args.v[2], DST_INTEGER)) { |  | ||||||
|         end = dst_unwrap_integer(args.v[2]); |  | ||||||
|     } else { |  | ||||||
|         DST_THROW(args, "expected integer"); |  | ||||||
|     } |  | ||||||
|     if (start < 0) start = len + start; |  | ||||||
|     if (end < 0) end = len + end + 1; |  | ||||||
|     if (end >= start) { |  | ||||||
|         ret = dst_string(data + start, end - start); |  | ||||||
|     } else { |  | ||||||
|         ret = dst_cstring(""); |  | ||||||
|     } |  | ||||||
|     DST_RETURN_STRING(args, ret); |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -22,6 +22,7 @@ | |||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
| #include <dst/dstopcodes.h> | #include <dst/dstopcodes.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include "fiber.h" | #include "fiber.h" | ||||||
| #include "gc.h" | #include "gc.h" | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include <errno.h> | #include <errno.h> | ||||||
|  |  | ||||||
| #define IO_WRITE 1 | #define IO_WRITE 1 | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include <math.h> | #include <math.h> | ||||||
|  |  | ||||||
| /* Get a random number */ | /* Get a random number */ | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
|  |  | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <time.h> | #include <time.h> | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include "gc.h" | #include "gc.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
|  |  | ||||||
| @@ -501,3 +502,158 @@ void dst_puts(const uint8_t *str) { | |||||||
|         putc(str[i], stdout); |         putc(str[i], stdout); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* CFuns */ | ||||||
|  |  | ||||||
|  | static int cfun_slice(DstArgs args) { | ||||||
|  |     const uint8_t *data; | ||||||
|  |     int32_t len, start, end; | ||||||
|  |     const uint8_t *ret; | ||||||
|  |     DST_MINARITY(args, 1); | ||||||
|  |     DST_MAXARITY(args, 3); | ||||||
|  |     DST_ARG_BYTES(data, len, args, 0); | ||||||
|  |     /* Get start */ | ||||||
|  |     if (args.n < 2) { | ||||||
|  |         start = 0; | ||||||
|  |     } else if (dst_checktype(args.v[1], DST_INTEGER)) { | ||||||
|  |         start = dst_unwrap_integer(args.v[1]); | ||||||
|  |     } else { | ||||||
|  |         DST_THROW(args, "expected integer"); | ||||||
|  |     } | ||||||
|  |     /* Get end */ | ||||||
|  |     if (args.n < 3) { | ||||||
|  |         end = -1; | ||||||
|  |     } else if (dst_checktype(args.v[2], DST_INTEGER)) { | ||||||
|  |         end = dst_unwrap_integer(args.v[2]); | ||||||
|  |     } else { | ||||||
|  |         DST_THROW(args, "expected integer"); | ||||||
|  |     } | ||||||
|  |     if (start < 0) start = len + start; | ||||||
|  |     if (end < 0) end = len + end + 1; | ||||||
|  |     if (end >= start) { | ||||||
|  |         ret = dst_string(data + start, end - start); | ||||||
|  |     } else { | ||||||
|  |         ret = dst_cstring(""); | ||||||
|  |     } | ||||||
|  |     DST_RETURN_STRING(args, ret); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int cfun_repeat(DstArgs args) { | ||||||
|  |     const uint8_t *data; | ||||||
|  |     uint8_t *newbuf, *p, *end; | ||||||
|  |     int32_t len, rep; | ||||||
|  |     int64_t mulres; | ||||||
|  |     DST_FIXARITY(args, 2); | ||||||
|  |     DST_ARG_BYTES(data, len, args, 0); | ||||||
|  |     DST_ARG_INTEGER(rep, args, 1); | ||||||
|  |     if (rep < 0) { | ||||||
|  |         DST_THROW(args, "expected non-negative number of repetitions"); | ||||||
|  |     } else if (rep == 0) { | ||||||
|  |         DST_RETURN_CSTRING(args, ""); | ||||||
|  |     } | ||||||
|  |     mulres = (int64_t) rep * len; | ||||||
|  |     if (mulres > INT32_MAX) { | ||||||
|  |         DST_THROW(args, "result string is too long"); | ||||||
|  |     } | ||||||
|  |     newbuf = dst_string_begin((int32_t) mulres); | ||||||
|  |     end = newbuf + mulres; | ||||||
|  |     for (p = newbuf; p < end; p += len) { | ||||||
|  |         memcpy(p, data, len); | ||||||
|  |     } | ||||||
|  |     DST_RETURN_STRING(args, dst_string_end(newbuf)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int cfun_bytes(DstArgs args) { | ||||||
|  |     const uint8_t *str; | ||||||
|  |     int32_t strlen, i; | ||||||
|  |     Dst *tup; | ||||||
|  |     DST_FIXARITY(args, 1); | ||||||
|  |     DST_ARG_BYTES(str, strlen, args, 0); | ||||||
|  |     tup = dst_tuple_begin(strlen); | ||||||
|  |     for (i = 0; i < strlen; i++) { | ||||||
|  |         tup[i] = dst_wrap_integer((int32_t) str[i]); | ||||||
|  |     } | ||||||
|  |     DST_RETURN_TUPLE(args, dst_tuple_end(tup)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int cfun_frombytes(DstArgs args) { | ||||||
|  |     int32_t i; | ||||||
|  |     uint8_t *buf; | ||||||
|  |     for (i = 0; i < args.n; i++) { | ||||||
|  |         DST_CHECK(args, i, DST_INTEGER); | ||||||
|  |     } | ||||||
|  |     buf = dst_string_begin(args.n); | ||||||
|  |     for (i = 0; i < args.n; i++) { | ||||||
|  |         int32_t c; | ||||||
|  |         DST_ARG_INTEGER(c, args, i); | ||||||
|  |         buf[i] = c & 0xFF; | ||||||
|  |     } | ||||||
|  |     DST_RETURN_STRING(args, dst_string_end(buf)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int cfun_asciilower(DstArgs args) { | ||||||
|  |     const uint8_t *str; | ||||||
|  |     uint8_t *buf; | ||||||
|  |     int32_t len, i; | ||||||
|  |     DST_FIXARITY(args, 1); | ||||||
|  |     DST_ARG_BYTES(str, len, args, 0); | ||||||
|  |     buf = dst_string_begin(len); | ||||||
|  |     for (i = 0; i < len; i++) { | ||||||
|  |         uint8_t c = str[i]; | ||||||
|  |         if (c >= 65 && c <= 90) { | ||||||
|  |             buf[i] = c + 32; | ||||||
|  |         } else { | ||||||
|  |             buf[i] = c; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     DST_RETURN_STRING(args, dst_string_end(buf)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int cfun_asciiupper(DstArgs args) { | ||||||
|  |     const uint8_t *str; | ||||||
|  |     uint8_t *buf; | ||||||
|  |     int32_t len, i; | ||||||
|  |     DST_FIXARITY(args, 1); | ||||||
|  |     DST_ARG_BYTES(str, len, args, 0); | ||||||
|  |     buf = dst_string_begin(len); | ||||||
|  |     for (i = 0; i < len; i++) { | ||||||
|  |         uint8_t c = str[i]; | ||||||
|  |         if (c >= 97 && c <= 122) { | ||||||
|  |             buf[i] = c - 32; | ||||||
|  |         } else { | ||||||
|  |             buf[i] = c; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     DST_RETURN_STRING(args, dst_string_end(buf)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int cfun_reverse(DstArgs args) { | ||||||
|  |     const uint8_t *str; | ||||||
|  |     uint8_t *buf; | ||||||
|  |     int32_t len, i, j; | ||||||
|  |     DST_FIXARITY(args, 1); | ||||||
|  |     DST_ARG_BYTES(str, len, args, 0); | ||||||
|  |     buf = dst_string_begin(len); | ||||||
|  |     for (i = 0, j = len - 1; i < len; i++, j--) { | ||||||
|  |         buf[i] = str[j]; | ||||||
|  |     } | ||||||
|  |     DST_RETURN_STRING(args, dst_string_end(buf)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static const DstReg cfuns[] = { | ||||||
|  |     {"string.slice", cfun_slice}, | ||||||
|  |     {"string.repeat", cfun_repeat}, | ||||||
|  |     {"string.bytes", cfun_bytes}, | ||||||
|  |     {"string.from-bytes", cfun_frombytes}, | ||||||
|  |     {"string.ascii-lower", cfun_asciilower}, | ||||||
|  |     {"string.ascii-upper", cfun_asciiupper}, | ||||||
|  |     {"string.reverse", cfun_reverse}, | ||||||
|  |     {NULL, NULL} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | /* Module entry point */ | ||||||
|  | int dst_lib_string(DstArgs args) { | ||||||
|  |     DstTable *env = dst_env_arg(args); | ||||||
|  |     dst_env_cfuns(env, cfuns); | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include "gc.h" | #include "gc.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -21,6 +21,7 @@ | |||||||
| */ | */ | ||||||
|  |  | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
|  | #include <dst/dstcorelib.h> | ||||||
| #include "symcache.h" | #include "symcache.h" | ||||||
| #include "gc.h" | #include "gc.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
| @@ -42,18 +42,6 @@ int dst_divide(DstArgs args); | |||||||
| int dst_modulo(DstArgs args); | int dst_modulo(DstArgs args); | ||||||
| int dst_rand(DstArgs args); | int dst_rand(DstArgs args); | ||||||
| int dst_srand(DstArgs args); | int dst_srand(DstArgs args); | ||||||
| int dst_strict_equal(DstArgs args); |  | ||||||
| int dst_strict_notequal(DstArgs args); |  | ||||||
| int dst_ascending(DstArgs args); |  | ||||||
| int dst_descending(DstArgs args); |  | ||||||
| int dst_notdescending(DstArgs args); |  | ||||||
| int dst_notascending(DstArgs args); |  | ||||||
| int dst_numeric_eq(DstArgs args); |  | ||||||
| int dst_numeric_neq(DstArgs args); |  | ||||||
| int dst_numeric_gt(DstArgs args); |  | ||||||
| int dst_numeric_lt(DstArgs args); |  | ||||||
| int dst_numeric_gte(DstArgs args); |  | ||||||
| int dst_numeric_lte(DstArgs args); |  | ||||||
| int dst_bor(DstArgs args); | int dst_bor(DstArgs args); | ||||||
| int dst_band(DstArgs args); | int dst_band(DstArgs args); | ||||||
| int dst_bxor(DstArgs args); | int dst_bxor(DstArgs args); | ||||||
| @@ -61,7 +49,6 @@ int dst_bnot(DstArgs args); | |||||||
| int dst_lshift(DstArgs args); | int dst_lshift(DstArgs args); | ||||||
| int dst_rshift(DstArgs args); | int dst_rshift(DstArgs args); | ||||||
| int dst_lshiftu(DstArgs args); | int dst_lshiftu(DstArgs args); | ||||||
| int dst_not(DstArgs args); |  | ||||||
|  |  | ||||||
| /* Math */ | /* Math */ | ||||||
| int dst_cos(DstArgs args); | int dst_cos(DstArgs args); | ||||||
| @@ -100,7 +87,6 @@ int dst_core_put(DstArgs args); | |||||||
| int dst_core_type(DstArgs args); | int dst_core_type(DstArgs args); | ||||||
| int dst_core_next(DstArgs args); | int dst_core_next(DstArgs args); | ||||||
| int dst_core_hash(DstArgs args); | int dst_core_hash(DstArgs args); | ||||||
| int dst_core_string_slice(DstArgs args); |  | ||||||
|  |  | ||||||
| /* GC */ | /* GC */ | ||||||
| int dst_core_gccollect(DstArgs args); | int dst_core_gccollect(DstArgs args); | ||||||
| @@ -116,6 +102,7 @@ int dst_lib_buffer(DstArgs args); | |||||||
| int dst_lib_table(DstArgs args); | int dst_lib_table(DstArgs args); | ||||||
| int dst_lib_fiber(DstArgs args); | int dst_lib_fiber(DstArgs args); | ||||||
| int dst_lib_os(DstArgs args); | int dst_lib_os(DstArgs args); | ||||||
|  | int dst_lib_string(DstArgs args); | ||||||
|  |  | ||||||
| /* Useful for compiler */ | /* Useful for compiler */ | ||||||
| Dst dst_op_add(Dst lhs, Dst rhs); | Dst dst_op_add(Dst lhs, Dst rhs); | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,3 +1,5 @@ | |||||||
|  | # Copyright 2017-2018 (C) Calvin Rose | ||||||
|  |  | ||||||
| (do | (do | ||||||
|  |  | ||||||
| (var *should-repl* :private false) | (var *should-repl* :private false) | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
| * Copyright (c) 2017 Calvin Rose | * Copyright (c) 2018 Calvin Rose | ||||||
| * | * | ||||||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| * of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| # Copyright (c) 2017 Calvin Rose | # Copyright (c) 2018 Calvin Rose | ||||||
| # | # | ||||||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| # of this software and associated documentation files (the "Software"), to | # of this software and associated documentation files (the "Software"), to | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| # Copyright (c) 2017 Calvin Rose | # Copyright (c) 2018 Calvin Rose | ||||||
|  |  | ||||||
| # |  | ||||||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| # of this software and associated documentation files (the "Software"), to | # of this software and associated documentation files (the "Software"), to | ||||||
| # deal in the Software without restriction, including without limitation the | # deal in the Software without restriction, including without limitation the | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose