Skip to content

Commit

Permalink
Use #import instead of @import
Browse files Browse the repository at this point in the history
  • Loading branch information
elimirks committed Dec 25, 2021
1 parent 5353a09 commit cab2526
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions assets/memory.b
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _heapEnd 0;

/**
* Allocates the given number of quads (64 bit values)
* TODO: Use the buddy allocation algorithm some day...
*/
malloc(count) {
extrn _heapBegin, _heapEnd;
Expand Down
6 changes: 2 additions & 4 deletions assets/stdlib.b
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "memory.b";
#import "memory.b";
/*
* Compares 2 strings. Return negative if "s1 < s2"
Expand Down Expand Up @@ -161,9 +161,7 @@ num2str(n) {
putnum(charIndex);
putchar('*n');
/* FIXME: Why doesn't shift by 3 work here? */
/* str[strIndex] =| *stackTop << (charIndex << 3); */
str[strIndex] =| *stackTop << (charIndex * 8);
str[strIndex] =| *stackTop << (charIndex << 3);
}
return(str);
}
6 changes: 3 additions & 3 deletions benchtest/base_garbage.b
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "../assets/stdlib.b";
@import "../assets/memory.b";
#import "../assets/stdlib.b";
#import "../assets/memory.b";

func1(xref) {
*xref = *xref + *xref;
Expand Down Expand Up @@ -174,4 +174,4 @@ func15() {
putchar('*n');
putnum(nums[2]);
putchar('*n');
}
}
2 changes: 1 addition & 1 deletion benchtest/generate_garbage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ for i in $(seq $GARBAGE_COUNT); do
done

for i in `seq 10000`; do
echo "@import \"garb_${i}.b\";"
echo "#import \"garb_${i}.b\";"
done > all_garbage.b

# Run b64 against "all_garbage.b" to benchmark
Expand Down
6 changes: 3 additions & 3 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn pop_tok(c: &mut ParseContext) -> Result<(Pos, Token), CompErr> {
match ch as char {
'\'' => get_tok_char(c),
'\"' => get_tok_str(c),
'@' => get_tok_meta(c),
'#' => get_tok_meta(c),
// Handle '=' differently because of the chaining rule
'=' => Ok(get_tok_equals(c)),
'_' | 'a'..='z' | 'A'..='Z' => get_tok_word(c),
Expand Down Expand Up @@ -170,7 +170,7 @@ fn get_tok_symbol(c: &mut ParseContext) -> Result<(Pos, Token), CompErr> {
}
}

// Assumes the @ token has been parsed
// Assumes the # token has been parsed
// Returns a metaprogramming token
fn get_tok_meta(c: &mut ParseContext) -> Result<(Pos, Token), CompErr> {
let pos = c.pos();
Expand All @@ -182,7 +182,7 @@ fn get_tok_meta(c: &mut ParseContext) -> Result<(Pos, Token), CompErr> {
Ok((c.pos(), Token::Import))
},
other => {
CompErr::err(&pos, format!("Invalid token: @{}", other))
CompErr::err(&pos, format!("Invalid token: #{}", other))
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/hello.b
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "../assets/stdlib.b";
@import "../assets/memory.b";
#import "../assets/stdlib.b";
#import "../assets/memory.b";

main() {
auto c 10, i 3;
Expand Down
2 changes: 1 addition & 1 deletion test/precedence.b
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "../assets/stdlib.b";
#import "../assets/stdlib.b";

main() {
auto x, y;
Expand Down
2 changes: 1 addition & 1 deletion test/strops.b
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "../assets/stdlib.b";
#import "../assets/stdlib.b";

show_strcmp() {
putstr("strcmp:*n");
Expand Down

0 comments on commit cab2526

Please sign in to comment.