Skip to content

Commit cc6efcd

Browse files
committed
fix: added ind type indicator & fixed some issues with the printf example
1 parent d8cbe49 commit cc6efcd

8 files changed

Lines changed: 56 additions & 17 deletions

File tree

examples/sample.qf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
static staticstr bobby = "Hellossssss"
1+
static staticstr bobby = "\nHellossssss %d"
22

3-
shadowfunc printf(ptr str_pointer)
3+
shadowfunc printf(ptr str_ptr) si32
44

5-
func main() {
6-
printf(bobby)
5+
func main() si32 {
6+
var si32 test = 65_si32
7+
8+
printf(bobby, test)
9+
10+
ret 0_si32
711
}

ir/src/conv/func.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn parse_ir_function_decl(ctx: &mut IRContext, node: Box<ASTTreeNode>) -> Po
6464
}
6565

6666
ctx.add_function(func_name.hash, func);
67-
67+
6868
return ctx.get_funtion(func_name.hash);
6969
}
7070

@@ -150,7 +150,20 @@ pub fn parse_ir_function_body_member(ctx: &IRContext, func: &mut IRFunction, nod
150150
parse_ir_function_call(ctx, &func.lctx, node, None, false)?;
151151

152152
return Ok(true)
153+
},
154+
155+
ASTTreeNode::ReturnStatement { val } => {
156+
if val.clone().is_none() || func.ret_type.is_none() {
157+
ctx.builder.build_return(None);
158+
159+
return Ok(true);
160+
}
153161

162+
let val = parse_ir_value(Some(&func.lctx), ctx, val.unwrap(), None, true)?;
163+
164+
ctx.builder.build_return(Some(&val.obtain(ctx)?.obtain().inner));
165+
166+
return Ok(true);
154167
}
155168

156169
ASTTreeNode::IfStatement { .. } => {

ir/src/conv/val.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ pub fn get_variable_ref(lctx: &IRLocalContext, ctx: &IRContext, hash: u64) -> Po
2222

2323
pub fn parse_ir_value<'a>(lctx: Option<&IRLocalContext>, ctx: &IRContext, node: Box<ASTTreeNode>, left: Option<IRPointer>, in_var: bool) -> PositionlessResult<IRValueRef> {
2424
match node.as_ref() {
25-
ASTTreeNode::IntegerLit(v) => {
26-
let t = ctx.type_storage.get(SIGNED64_TYPE_HASH);
27-
25+
ASTTreeNode::IntegerLit { val: v, hash} => {
26+
let t = ctx.type_storage.get(*hash);
27+
2828
if !t.is_some() {
29-
return Err(PositionlessError::new("Invalid type storage! si64 not found!"));
29+
return Err(PositionlessError::new("Invalid type storage! integer type indicator not found!"));
3030
}
3131

3232
return Ok(IRValueRef::from_val(IRValue::from_signed(ctx, t.unwrap(), *v as i128)?));

lexer/src/lexer.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,37 @@ fn parse_number_token(str: &String, ind: &mut usize, start_pos: Position) -> Lex
224224
}
225225

226226
let slice = &str[*ind..end];
227-
let num: i64 = match slice.parse() {
227+
let num: i128 = match slice.parse() {
228228
Ok(v) => v,
229229
Err(_) => return Err(LexerParsingError::new("Couldn't parse int lit!".to_string(), *ind)),
230230
};
231231

232232
*ind = end;
233233

234234
let endpos = start_pos.increment_by(end - start);
235-
return Ok(LexerToken::new(start_pos, endpos, LexerTokenType::IntLit(num)));
235+
236+
let mut hash = 7572830400006405400;
237+
238+
println!("{}", str.chars().nth(*ind + 1).unwrap());
239+
240+
if str.chars().nth(*ind).unwrap() == '_' {
241+
*ind += 1;
242+
243+
let tok = parse_keyword(str, ind, endpos.clone());
244+
let k = match tok.expects_keyword() {
245+
Ok(v) => v,
246+
Err(_) => return Err(LexerParsingError::new("Expected keyword as int type specifier".to_string(), *ind))
247+
};
248+
249+
println!("Hashee :{:?}", k);
250+
251+
hash = k.1;
252+
}
253+
254+
println!("{}", str.chars().nth(*ind).unwrap());
255+
256+
257+
return Ok(LexerToken::new(start_pos, endpos, LexerTokenType::IntLit(num, hash)));
236258
}
237259

238260
fn parse_string_token(str: &String, ind: &mut usize, start_pos: Position) -> LexerToken {

lexer/src/token.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum LexerTokenType {
5454
ArrayOpen,
5555
ArrayClose,
5656

57-
IntLit(i64),
57+
IntLit(i128, u64),
5858
StringLit(String),
5959

6060
AngelBracketOpen,
@@ -93,9 +93,9 @@ impl LexerToken {
9393
return Ok(true);
9494
}
9595

96-
pub fn expects_int_lit(&self) -> PositionedResult<i64> {
96+
pub fn expects_int_lit(&self) -> PositionedResult<(i128, u64)> {
9797
match &self.tok_type {
98-
LexerTokenType::IntLit(v) => return Ok(*v),
98+
LexerTokenType::IntLit(v, h) => return Ok((*v, *h)),
9999
_ => return Err(self.make_err("Expected int litteral here!"))
100100
};
101101
}

parser/src/ast/literals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn parse_integer_literal(tokens: &Vec<LexerToken>, ind: &mut usize) -> Posit
99
let val = tokens[*ind].expects_int_lit()?;
1010
*ind += 1;
1111

12-
return Ok(Box::new(ASTTreeNode::IntegerLit(val)));
12+
return Ok(Box::new(ASTTreeNode::IntegerLit { val: val.0, hash: val.1 }));
1313
}
1414

1515
pub fn parse_string_literal(tokens: &Vec<LexerToken>, ind: &mut usize) -> PositionedResult<Box<ASTTreeNode>> {

parser/src/ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn parse_ast_value(tokens: &Vec<LexerToken>, ind: &mut usize) -> PositionedR
154154
return Err(tokens[*ind].make_err(format!("Boolean negative requires either func or var access! Got {:#?}", ast).as_str()));
155155
},
156156

157-
LexerTokenType::IntLit(_) => {
157+
LexerTokenType::IntLit(_, _) => {
158158
let int = parse_integer_literal(tokens, ind);
159159
return parse_ast_value_post_l(tokens, ind, int, false);
160160
},

parser/src/ast/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl FunctionDeclarationArgument {
2020
/// The main AST node type in the AST parsing system.
2121
#[derive(Debug, PartialEq, Clone)]
2222
pub enum ASTTreeNode {
23-
IntegerLit(i64),
23+
IntegerLit { val: i128, hash: u64 },
2424
StringLit(String),
2525

2626
OperatorBasedConditionMember { lval: Box<ASTTreeNode>, rval: Box<ASTTreeNode>, operator: ComparingOperator },

0 commit comments

Comments
 (0)