Skip to content

Bc to program #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions runtest.raku
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env raku
use Test;
use JSON::Fast;
use fatal;

my @specs = from-json(slurp 'test/run/spec.json');
for @specs -> % (:$name, :$is-error, :$skip, :@dependencies) {
Expand All @@ -21,20 +22,21 @@ for @specs -> % (:$name, :$is-error, :$skip, :@dependencies) {
$proc.stderr.tap({ $error ~= $_ });

try {
await $proc.start;
my $r = await $proc.start;

if $is-error {
fail "Expected error.";
} else {
is @output.join("\n"), $expected-output, $name;
}

CATCH {
if $is-error {
is $error, $expected-output, $name;
if $r.exitcode {
ok $error ~~ /$expected-output/, $name;
} else {
say "ERRORS:\n" ~ $error.lines.map("ERR: " ~ *).join("\n").indent(2) if $error;
flunk "Expected error in $name";
}
} else {
if $r.exitcode {
diag "ERRORS:\n" ~ $error.lines.map("ERR: " ~ *).join("\n").indent(2);
flunk $name;
}

is @output.join("\n"), $expected-output, $name;
}
}
}
48 changes: 48 additions & 0 deletions src/bc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
#[serde()]
pub struct ModuleName {
pub module: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "tag", content = "contents")]
pub enum RawInstruction {
PushInt(i64),
PushString(usize),
LoadLocal(usize),
StoreLocal(usize),
LoadName(ModuleName, String),
LoadGlobal(String),
Unless(usize),
Jump(usize),
Call(usize),
Instantiate(ModuleName, String, String),
IsVariant(ModuleName, String, String),
Field(ModuleName, String, String, String),
}

#[derive(Serialize, Deserialize)]
pub struct ADTVariant {
pub name: String,
pub elements: Vec<String>,
}

#[derive(Serialize, Deserialize)]
pub struct ExpectedADT {
pub module: Vec<String>,
pub name: String,
pub variants: Vec<ADTVariant>,
}

#[derive(Serialize, Deserialize)]
pub struct Module {
pub name: Vec<String>,
pub strings: Vec<String>,
pub functions: HashMap<String, Vec<RawInstruction>>,
pub dependencies: Vec<Vec<String>>,
pub adts: HashMap<String, Vec<ADTVariant>>,
pub expected_adts: Vec<ExpectedADT>,
}
30 changes: 0 additions & 30 deletions src/context.rs

This file was deleted.

4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod context;
pub mod vm;
pub mod bc;
pub mod program;

extern crate serde;
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use lib::vm::Module;
use std::{collections::HashMap, env, fs::File, io::Read};
use std::{env, fs::File, io::Read};
use lib::{bc, vm};

extern crate lib;

fn load_module(path: String) -> Result<Module, String> {
fn load_module(path: String) -> Result<bc::Module, String> {
let mut content = String::new();
if path == "-" {
std::io::stdin()
Expand All @@ -19,7 +19,7 @@ fn load_module(path: String) -> Result<Module, String> {

fn main() {
let mut main: Vec<String> = Vec::new();
let mut modules: HashMap<Vec<String>, Module> = HashMap::new();
let mut modules: Vec<bc::Module> = Vec::new();

// XXX this means `./undo-frontend` just errors, instead of behaving like `./undo-frontend -`
for arg in env::args().skip(1) {
Expand All @@ -30,8 +30,8 @@ fn main() {
if main.is_empty() {
main = module_name.clone();
}
modules.insert(module_name, module);
modules.push(module);
}

lib::vm::run(main, modules);
vm::run(main, modules);
}
Loading