Browse Source

wip

master
Yuki Izumi 4 years ago
parent
commit
b84c2e2bce
No known key found for this signature in database GPG Key ID: 44A3D2C95E26BB14
3 changed files with 11 additions and 73 deletions
  1. +1
    -1
      lc/src/main.rs
  2. +0
    -69
      vm/main.c
  3. +10
    -3
      vm/src/main.rs

+ 1
- 1
lc/src/main.rs View File

@@ -6,8 +6,8 @@ extern crate getopts;

use std::io::Read;
use std::fs::File;
use getopts::Options;
use std::env;
use getopts::Options;

mod ast;
mod lexer;


+ 0
- 69
vm/main.c View File

@@ -1,69 +0,0 @@
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include "vm.h"

static void usage(int exit_code);
static int load_code(vm_process *p, char const *filename);

int main(int argc, char **argv) {
static struct option longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 },
};

int ch;
while ((ch = getopt_long(argc, argv, "h", longopts, NULL)) != -1) {
switch (ch) {
case 'h':
usage(0);
default:
usage(1);
}
}

argc -= optind;
argv += optind;
if (argc != 1)
usage(1);

vm_process *init = make_process();

if (!load_code(init, argv[0])) {
perror("failed to open file for reading");
return 1;
}

run(init);

printf("no processes: exiting\n");

return 0;
}

static void usage(int exit_code) {
printf(
"\n"
"Usage: vm [OPTIONS] PATH\n"
"\n"
" Run the lilac VM with the object\n"
" at PATH as the initial process.\n"
"\n"
"Options:\n"
" -h --help This help.\n"
"\n");
exit(exit_code);
}

static int load_code(vm_process *p, char const *filename) {
FILE *f = fopen(filename, "r");
if (!f)
return 0;
fseek(f, 0L, SEEK_END);
long pos = ftell(f);
fseek(f, 0L, SEEK_SET);
p->code = calloc(1, p->code_len = pos);
fread(p->code, pos, 1, f);
fclose(f);
return 1;
}

+ 10
- 3
vm/src/main.rs View File

@@ -1,7 +1,10 @@
extern crate getopts;
extern crate byteorder;

use getopts::Options;
use std::io::Read;
use std::fs::File;
use std::env;
use getopts::Options;

fn main() {
let args: Vec<String> = env::args().collect();
@@ -21,13 +24,17 @@ fn main() {
}

let input = if !matches.free.is_empty() {
matches.free[0].clone();
matches.free[0].clone()
} else {
print_usage(&program, opts);
return;
};

// ok
let mut s = Vec::new();
let mut f = File::open(input).unwrap();
f.read_to_end(&mut s).unwrap();


}

fn print_usage(program: &str, opts: Options) {


Loading…
Cancel
Save