about summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
* 5863Kartik Agaram2020-01-025-102/+25
| | | | | | | | | Just clarified for myself why `subx translate` and `subx run` need to share code: emulation supports the tests first and foremost. In the process we clean up our architecture for levels of layers. It's a good idea but unused once we reconceive of "level 1" as just part of the test harness.
* 5862Kartik Agaram2020-01-012-164/+172
| | | | | Deemphasize details of x86 addressing modes. I want people using SubX's syntax sugar now.
* 5861 - describe Mu language in the ReadmeKartik Agaram2020-01-013-987/+42
|
* 5860Kartik Agaram2020-01-011-0/+17
|
* 5859Kartik Agaram2020-01-013-6/+5
| | | | Move script to create a Linux-based boot image into a sub-directory.
* 5858Kartik Agaram2020-01-0197-10/+8
| | | | | | Move script to create a Soso boot image into a sub-directory. I'm trying to streamline newcomer attention to just a couple of use cases.
* 5857Kartik Agaram2020-01-012-26/+26
|
* 5856Kartik Agaram2020-01-0143-98/+89
|
* 5855Kartik Agaram2020-01-016-4664/+5051
|
* 5854Kartik Agaram2020-01-011-1/+1
|
* 5853Kartik Agaram2020-01-013-135/+0
|
* 5852Kartik Agaram2020-01-01232-3/+3
|
* 5851Kartik Agaram2020-01-0110-20/+22
| | | | | | | | | | | | Rename a few scripts to be more consistent. I'm also starting to feel the urge to bud off `subx run` into its own program, say tools/emulate_x86. It doesn't really rely on the SubX notation at all. And then I could rename `subx translate` to `translate_subx_bootstrap`. Only problem: the commands in the Readme get verbose. But the Readme is gonna need surgery soon anyway to put translate_mu front and center.
* 5850 - driver script for translating Mu programsKartik Agaram2020-01-013-0/+69
|
* 5849 - more integration testing of function callsKartik Agaram2020-01-012-7/+98
| | | | | | | | | | | | | | | | I can now run this program: fn main -> result/ebx: int { result <- do-add 3 4 } fn do-add a: int, b: int -> result/ebx: int { result <- copy a result <- add b } We still can't define local variables, but can write any programs involving ints by passing in enough arguments for temporaries.
* 5848Kartik Agaram2020-01-011-5/+5
|
* 5847 - literal inputsKartik Agaram2019-12-3116-1/+308
|
* 5846Kartik Agaram2019-12-301-10/+10
|
* 5845Kartik Agaram2019-12-301-0/+3
|
* 5844Kartik Agaram2019-12-301-3/+3
| | | | | Let's start putting r32 first in compare instructions that need it. Ordering there is quite subtle and of great import.
* 5843Kartik Agaram2019-12-291-1/+1
|
* 5842Kartik Agaram2019-12-291-0/+44
| | | | | | Extremely crappy syntax highlighting for Emacs. I just can't wrap my head around elisp, and I'm inclined to blame elisp. Checking this off my todo list and moving on.
* 5841 - rudimentary syntax highlighting for geditKartik Agaram2019-12-281-0/+29
|
* 5840 - syntax highlighting for nano (!!)Kartik Agaram2019-12-281-0/+16
|
* 5839 - colors for comments and string literalsKartik Agaram2019-12-282-1/+32
|
* 5838 - syntax highlighting for atomKartik Agaram2019-12-284-0/+63
|
* 5837 - better colors for trace browserKartik Agaram2019-12-281-10/+25
|
* 5836Kartik Agaram2019-12-281-1/+1
|
* 5835Kartik Agaram2019-12-2819-3787/+4858
|
* 5834Kartik Agaram2019-12-272-3/+4
| | | | Bugfix.
* 5833Kartik Agaram2019-12-271-1/+1
|
* 5832 - support for function outputsKartik Agaram2019-12-272-14/+138
| | | | | | | | | | | We haven't implemented it yet, but there's now a design for how we check whether a function has written its output correctly. Functions must write to each output at the top level at least once, and never overwrite an output register in the top-level once it's been defined. This is conservative (it can be perfectly reasonable for functions to write the output, reuse the register for a temporary, and then write the output again) but easy to check.
* 5831Kartik Agaram2019-12-272-27/+38
|
* 5830Kartik Agaram2019-12-262-1/+5
| | | | | Bugfix: statements defining a new register variable require an initializer instruction.
* 5829Kartik Agaram2019-12-261-5/+15
|
* 5828 - copy (mov) instructionsKartik Agaram2019-12-262-22/+144
|
* 5827 - give primitives one more bit of metadataKartik Agaram2019-12-262-4/+59
| | | | | Copy (mov) instructions are unlike instructions we've encoded so far, in that their destination is not read.
* 5826 - done with basic binary opsKartik Agaram2019-12-262-0/+197
|
* 5825 - code-generation for add opcodesKartik Agaram2019-12-262-26/+158
|
* 5824 - code-generation for all inc/dec opcodesKartik Agaram2019-12-262-2/+199
|
* 5823Kartik Agaram2019-12-222-0/+55
|
* 5822Kartik Agaram2019-12-222-3/+3
|
* 5821 - now translating function argumentsKartik Agaram2019-12-223-111/+157
| | | | See test-convert-function-with-arg-and-body.
* 5820Kartik Agaram2019-12-221-38/+177
| | | | | | | | | | | One test failing. It took enough debugging just to get to the expected failure that it seems worth saving this snapshot. Saw some signs that I have to remember to zero-out allocated memory. We need a scalable solution for this. I think parse-var-with-type needs to be rewritten. Just added a test and a hacky fix for now.
* 5819Kartik Agaram2019-12-223-3/+3
| | | | Minor tweaks to stop wasting horizontal space in the trace.
* 5818Kartik Agaram2019-12-224-16/+16
|
* 5817Kartik Agaram2019-12-221-1/+4
|
* 5816 - browse_trace bug fixedKartik Agaram2019-12-211-0/+1
|
* 5815Kartik Agaram2019-12-211-4/+4
|
* 5814Kartik Agaram2019-12-211-25/+25
|
s/leo/commit/leo.pl?h=v0.3.0&id=18c8216959dd817d4b6f0971773174fb6e937af0'>18c8216 ^
299d5ee ^
4648948 ^
1e63070 ^

34857c3 ^

61c874b ^
18c8216 ^
61c874b ^














1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149





                  
              


                                  





                                 

              
                                          
                                             
 
                              
                                     
 
                                                     

         


                                                                
 
                       
 


                                            
 
                                                                









                                                               
                                                             

                                                       
                         


                                                                     


                                                                   
            
                                                        
     

 
                                 
            
                            
                          
 
                            
                                                                       
               
                                                 
                                                

                                 



                                                                
 
                                                            


                                                                   
                        

                        


                                                               



                                                    
                                                                         
 
                                                                 


                                           



                                              

                                         

                                                     
 
 
                 
                                       
 







                                                                      



                                           
                                        
            
                                                  

             

 
 
                                               














                                                                   
#!/usr/bin/perl

use strict;
use warnings;
use feature 'say';

use IPC::Run3;
use Path::Tiny;
use Getopt::Long qw/ GetOptions /;

my %options = (
    encrypt => $ENV{LEO_ENCRYPT},
    sign => $ENV{LEO_SIGN},
    delete => $ENV{LEO_DELETE},
);

GetOptions(
    \%options,
    qw{ verbose encrypt sign delete help }
) or die "Error in command line arguments\n";

my $ymd = ymd(); # YYYY-MM-DD.
my $backup_dir = "/tmp/backups/$ymd";

path($backup_dir)->mkpath; # Create backup directory.
my $prof;

# Config file for leo.
my $config_file = $ENV{XDG_CONFIG_HOME} || "$ENV{HOME}/.config";
$config_file .= "/leo.pl";

require "$config_file";

my %profile = get_profile();
my $gpg_fingerprint = get_gpg_fingerprint();
my $gpg_bin = get_gpg_bin();

HelpMessage() and exit 0 if scalar @ARGV == 0 or $options{help};
foreach my $arg ( @ARGV ) {
    $prof = $arg; # Set $prof.
    if ( $profile{ $arg } ) {
        say "++++++++********++++++++";

        # No encryption for journal profile.
        my $tmp = $options{encrypt} and undef $options{encrypt}
            if $prof eq "journal" and $options{encrypt};

        # Deref the array here because we want flattened list.
        backup("$backup_dir/${arg}.tar", $profile{$arg}->@*);

        $options{encrypt} = $tmp if $prof eq "journal";
    } elsif ( -e $arg ) {
        # If the file/directory exist then create a new profile & run
        # backup.
        say "++++++++********++++++++";
        backup("$backup_dir/${arg}.tar",
               # backup() is expecting path relative to $ENV{HOME}.
               path($arg)->relative($ENV{HOME}));
    } else {
        warn "[WARN] leo: no such profile :: `$arg' \n";
    }
}

# User must pass $tar_file first.
sub backup {
    my $tar_file = shift @_;
    my @backup_paths = @_;

    say "Backup: $tar_file";
    warn "[WARN] $tar_file exists, might overwrite.\n" if -e $tar_file;
    print "\n";
    # All paths should be relative to $ENV{HOME}.
    tar_create($tar_file, "-C", $ENV{HOME}, @_);

    $? # tar returns 1 on errors.
        ? die "Backup creation failed :: $?\n"
        # Print absolute paths for all backup files/directories.
        : say path($_)->absolute($ENV{HOME}), " backed up."
        foreach @backup_paths;

    print "\n" and tar_list($tar_file) if $options{verbose};
    encrypt_sign($tar_file) if $options{encrypt} or $options{sign};
}

# Encrypt, Sign backups.
sub encrypt_sign() {
    my $file = shift @_;
    my @options = ();
    push @options, "--recipient", $gpg_fingerprint, "--encrypt"
        if $options{encrypt};
    push @options, "--sign" if $options{sign};
    push @options, "--verbose" if $options{verbose};

    say "\nEncrypt/Sign: $file";
    warn "[WARN] $file.gpg exists, might overwrite.\n" if -e "$file.gpg";

    run3 [$gpg_bin, "--yes", "-o", "$file.gpg", @options, $file];

    $? # We assume non-zero is an error.
        ? die "Encrypt/Sign failed :: $?\n"
        : print "\nOutput: $file.gpg";
    print " [Encrypted]" if $options{encrypt};
    print " [Signed]" if $options{sign};
    print "\n";

    unlink $file and say "$file deleted."
        or warn "[WARN] Could not delete $file: $!\n"
        if $options{delete};
}

sub HelpMessage {
    say qq{Backup files to $backup_dir.

Profile:};
    foreach my $prof (sort keys %profile) {
        next if substr($prof, 0, 1) eq "."; # Profiles starting with a
                                            # dot will have alias.
        print "    $prof\n";
        print "        $_\n" foreach $profile{$prof}->@*;
    }
    say qq{
Options:
    --encrypt
        Encrypt files with $gpg_fingerprint
    --sign
        Sign files with $gpg_fingerprint
    --delete
        Delete the tar file after running $gpg_bin
    --verbose
    --help};
}


sub tar_create { run3 ["/bin/tar", "cf", @_]; }
sub tar_list { run3 ["/bin/tar", "tvf", @_]; }

sub ymd {
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
        localtime(time);

    $year += 1900; # $year contains the number of years since 1900.

    # $mon the month in the range 0..11 , with 0 indicating January
    # and 11 indicating December.
    my @months = qw( 01 02 03 04 05 06 07 08 09 10 11 12 );
    my $month = $months[$mon];

    return "$year-$month-$mday";
}