Skip to content

Commit 288ac8b

Browse files
committed
[main] Add base64-encoding function.
1 parent 2eee024 commit 288ac8b

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

lib/rt.ch

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,61 @@
916916
res @] map;
917917
,,
918918

919+
(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
920+
a b c d e f g h i j k l m n o p q r s t u v w x y z
921+
0 1 2 3 4 5 6 7 8 9 + /) _b64a var!;
922+
923+
: b64a _b64a @; swap; get; ,,
924+
: b64m0 18 >>; 0x3f unhex; &; b64a; ,,
925+
: b64m1 12 >>; 0x3f unhex; &; b64a; ,,
926+
: b64m2 6 >>; 0x3f unhex; &; b64a; ,,
927+
: b64m3 0x3f unhex; &; b64a; ,,
928+
929+
:~ b64e 1 1
930+
drop;
931+
input var!;
932+
begin;
933+
0 num var!;
934+
input @;
935+
shift;
936+
dup; is-null; if;
937+
drop;
938+
leave;
939+
then;
940+
int; 16 <<; num @; +; num !;
941+
942+
input @;
943+
shift;
944+
dup; is-null; if;
945+
drop;
946+
num @; b64m0; yield;
947+
num @; b64m1; yield;
948+
= yield;
949+
= yield;
950+
leave;
951+
then;
952+
int; 8 <<; num @; +; num !;
953+
954+
input @;
955+
shift;
956+
dup; is-null; if;
957+
drop;
958+
num @; b64m0; yield;
959+
num @; b64m1; yield;
960+
num @; b64m2; yield;
961+
= yield;
962+
leave;
963+
then;
964+
int; num @; +; num !;
965+
966+
num @; b64m0; yield;
967+
num @; b64m1; yield;
968+
num @; b64m2; yield;
969+
num @; b64m3; yield;
970+
971+
0 until;
972+
,,
973+
919974
# Common commands and aliases.
920975
: vim depth; 0 =; if; vim exec; else; "vim {}" exec; then; drop; ,,
921976
: ssh "ssh {}" fmtq; exec; drop; ,,

src/vm/vm_digest.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use crate::chunk::Value;
66
use crate::vm::*;
77

88
impl VM {
9+
/// The basic functionality is common to each function, and should
10+
/// be refactored so as to avoid the repetition.
11+
912
/// Takes a string as its single argument. Hashes the string
1013
/// using the MD5 algorithm and adds the result to the stack.
1114
pub fn core_md5(&mut self) -> i32 {

0 commit comments

Comments
 (0)