Skip to content

Commit

Permalink
simplified klang (#5)
Browse files Browse the repository at this point in the history
* simplified klang

* work in progress...

* some stuff

* things kind of work

* v0.0.1

* format

* lint again
  • Loading branch information
codekansas authored Oct 31, 2024
1 parent f04302f commit e858f84
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 921 deletions.
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

0 comments on commit e858f84

Please sign in to comment.