Skip to content
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

simplified klang #5

Merged
merged 7 commits into from
Oct 31, 2024
Merged
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
21 changes: 14 additions & 7 deletions examples/simple.k
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
fn wave(limb: string, joint: number, amount: number) : "Wave a hand back and forth" {
let pos = get_position(limb: limb, joint: joint);
let pos = set_position(limb: limb, joint: joint, pos: pos + amount);
let pos = set_position(limb: limb, joint: joint, pos: pos - amount);
return pos;
> wave [arm] arm {
> wave joint [joint] twice {
move joint [joint] on the [arm] arm to 90
move joint [joint] on the [arm] arm to 0
}

" wave joint [1] twice
" wave joint [2] twice
" wave joint [3] twice
}

fn main() : "Wave a hand back and forth a few times" {
wave(limb: "right_arm", joint: 0, amount: 45deg);
> wave both arms {
" wave [right] arm
" wave [left] arm
}

" wave both arms
5 changes: 4 additions & 1 deletion klang/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ fn main() {
config.enable_type_names();

config
.compile_protos(&["src/proto/ast.proto"], &["src/proto/"])
.compile_protos(
&["src/proto/ast.proto", "src/proto/ir.proto"],
&["src/proto/"],
)
.unwrap();
}
4 changes: 2 additions & 2 deletions klang/src/bin/kcompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use std::path::Path; // Import from the library
fn main() {
let args: Vec<String> = env::args().collect();
match args.len() {
2 => match compile_file_inplace(Path::new(&args[1])) {
2 => match compile_file_inplace(Path::new(&args[1]), false) {
Ok(_) => (),
Err(e) => {
eprintln!("{}", e);
std::process::exit(1);
}
},
3 => match compile_file(Path::new(&args[1]), Path::new(&args[2])) {
3 => match compile_file(Path::new(&args[1]), Path::new(&args[2]), false) {
Ok(_) => (),
Err(e) => {
eprintln!("{}", e);
Expand Down
8 changes: 4 additions & 4 deletions klang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::parser::errors::ParseError;
use crate::parser::{parse_file, write_program_to_file};
use std::path::Path;

pub fn compile_file(file_path: &Path, output_path: &Path) -> Result<(), ParseError> {
pub fn compile_file(file_path: &Path, output_path: &Path, binary: bool) -> Result<(), ParseError> {
match parse_file(file_path) {
Ok(program) => write_program_to_file(&program, output_path),
Ok(program) => write_program_to_file(&program, output_path, binary),
Err(e) => Err(e),
}
}

pub fn compile_file_inplace(file_path: &Path) -> Result<(), ParseError> {
compile_file(file_path, file_path.with_extension("ko").as_path())
pub fn compile_file_inplace(file_path: &Path, binary: bool) -> Result<(), ParseError> {
compile_file(file_path, file_path.with_extension("ko").as_path(), binary)
}
6 changes: 5 additions & 1 deletion klang/src/parser/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ impl ParseError {

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.message)
write!(
f,
"{} (line: {}, column: {})",
self.message, self.line, self.column
)
}
}

Expand Down
313 changes: 0 additions & 313 deletions klang/src/parser/expressions.rs

This file was deleted.

Loading
Loading