Skip to content

Commit

Permalink
Merge pull request #53 from sezna/alex/operator-exps
Browse files Browse the repository at this point in the history
Add "+" operator; remove stack return destination in codegen; associated Span fixes; VM test harness
  • Loading branch information
sezna authored Jun 28, 2024
2 parents 360ccea + d43e81c commit b02a1ea
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 227 deletions.
3 changes: 2 additions & 1 deletion pete/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ fn main() -> Result<(), error::PeteError> {
match target.to_lowercase().as_str() {
"vm" => {
let vm = Vm::new(instructions, data);
vm.run().expect("Failed to run vm");
let result = vm.run().expect("Failed to run vm");
println!("VM terminated with stack:\n{:#?}", result);
},
"native" => todo!(),
_ => {
Expand Down
6 changes: 4 additions & 2 deletions petr-ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,21 @@ impl std::fmt::Display for Intrinsic {
) -> std::fmt::Result {
match self {
Intrinsic::Puts => write!(f, "puts"),
Intrinsic::Add => write!(f, "add"),
}
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum Intrinsic {
/// intrinsic for `libc` puts
Puts,
Add,
}

#[derive(Clone)]
pub struct FunctionCall {
pub func_name: Identifier,
pub func_name: Path,
pub args: Box<[Expression]>,
// used for the formatter, primarily
pub args_were_parenthesized: bool,
Expand Down
6 changes: 3 additions & 3 deletions petr-ast/src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl PrettyPrint for Module {
interner: &SymbolInterner,
indentation: usize,
) -> String {
let mut buf = format!("{}module {} =\n", " ".repeat(indentation), interner.get_path(&self.name));
let mut buf = format!("{}module {} =\n", " ".repeat(indentation), interner.get_path(&self.name).join("."));
for node in &self.nodes {
buf.push_str(&node.pretty_print(interner, 0));
}
Expand All @@ -42,7 +42,7 @@ impl PrettyPrint for ImportStatement {
"{}{} {}",
" ".repeat(indentation),
if self.is_exported() { "export" } else { "import" },
self.path.identifiers.iter().map(|id| interner.get(id.id)).collect::<Vec<_>>().join("."),
self.path.iter().map(|id| interner.get(id.id)).collect::<Vec<_>>().join("."),
);
if let Some(alias) = self.alias {
buf.push_str(&format!(" as {}", interner.get(alias.id)));
Expand Down Expand Up @@ -224,7 +224,7 @@ impl PrettyPrint for FunctionCall {
format!(
"{}call {}({})",
" ".repeat(indentation),
interner.get(self.func_name.id),
interner.get_path(&self.func_name).join("."),
self.args
.iter()
.map(|arg| arg.pretty_print(interner, indentation))
Expand Down
2 changes: 1 addition & 1 deletion petr-bind/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Binder {
path: &Path,
) -> ScopeId {
let mut current_scope_id = self.current_scope_id();
for segment in path.identifiers.iter() {
for segment in path.iter() {
let next_scope = self.create_scope(ScopeKind::Module(*segment));
let module = Module {
root_scope: next_scope,
Expand Down
4 changes: 1 addition & 3 deletions petr-bind/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ impl Bind for ImportStatement {
};

// the alias, if any, or the last path element if there is no alias
let name = self
.alias
.unwrap_or_else(|| *self.path.identifiers.last().expect("should never be empty"));
let name = self.alias.unwrap_or_else(|| *self.path.iter().last().expect("should never be empty"));

binder.insert_into_current_scope(name.id, item.clone());

Expand Down
2 changes: 1 addition & 1 deletion petr-fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl Formattable for FunctionCall {
let mut lines = vec![];

buf.push('~');
buf.push_str(&ctx.interner.get(self.func_name.id));
buf.push_str(&ctx.interner.get_path(&self.func_name).join("."));
if self.args_were_parenthesized {
buf.push('(');
} else if !ctx.config.put_fn_args_on_new_lines() && !self.args.is_empty() {
Expand Down
Loading

0 comments on commit b02a1ea

Please sign in to comment.