We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6567ce6 commit 4704859Copy full SHA for 4704859
src/ast.rs
@@ -9,7 +9,7 @@ pub struct Expr {
9
}
10
11
#[derive(Clone, Debug, PartialEq)]
12
-pub struct Ident(String);
+pub struct Ident(pub String);
13
14
impl From<Ident> for String {
15
fn from(ident: Ident) -> Self {
@@ -37,9 +37,9 @@ pub enum ExprKind {
37
Unop(String, Box<Expr>),
38
Access(Box<Expr>, Ident),
39
Ident(Ident),
40
- Function(Option<String>, Vec<String>, Box<Expr>),
+ Function(Option<Ident>, Vec<Ident>, Box<Expr>),
41
Class(String, Box<Expr>, Option<Box<Expr>>),
42
- Lambda(Vec<String>, Box<Expr>),
+ Lambda(Vec<Ident>, Box<Expr>),
43
Match(Box<Expr>, Vec<(Box<Expr>, Box<Expr>)>, Option<Box<Expr>>),
44
If(Box<Expr>, Box<Expr>, Option<Box<Expr>>),
45
ConstInt(i64),
src/codegen.rs
@@ -654,9 +654,9 @@ impl Context {
654
655
pub fn compile_function(
656
&mut self,
657
- params: &[String],
+ params: &[Ident],
658
e: &Box<Expr>,
659
- vname: Option<String>,
+ vname: Option<Ident>,
660
) -> u32 {
661
let mut ctx = Context {
662
g: self.g.clone(),
@@ -681,15 +681,15 @@ impl Context {
681
ctx.stack += 1;
682
let r = ctx.new_reg();
683
ctx.write(Instruction::Pop(r));
684
- ctx.locals.insert(p.to_owned(), r as _);
+ ctx.locals.insert(String::from(p.to_owned()), r as _);
685
686
687
let gid = ctx.g.borrow().table.len();
688
if vname.is_some() {
689
- ctx.g
690
- .borrow_mut()
691
- .globals
692
- .insert(Global::Var(vname.as_ref().unwrap().to_owned()), gid as i32);
+ ctx.g.borrow_mut().globals.insert(
+ Global::Var(String::from(vname.as_ref().unwrap().to_owned())),
+ gid as i32,
+ );
693
694
ctx.g.borrow_mut().table.push(Global::Func(gid as i32, -1));
695
let r = ctx.compile(e, true);
@@ -704,7 +704,9 @@ impl Context {
704
ctx.pos.clone(),
705
gid as i32,
706
params.len() as i32,
707
- vname.unwrap_or(String::from("<anonymous>")),
+ vname
708
+ .map(String::from)
709
+ .unwrap_or(String::from("<anonymous>")),
710
));
711
712
if ctx.nenv > 0 {
src/parser.rs
@@ -176,9 +176,9 @@ fn parse_function_param<'b>(i: Span) -> Result<String, MsgWithPos> {
176
177
fn parse_function<'b>(i: Span) -> EResult {
178
let fn_arg_sep = tag(",");
179
- let fn_arg = expect_identifier;
+ let fn_arg = map(expect_identifier, Ident);
180
let tup = tuple((
181
- opt(expect_identifier),
+ opt(map(expect_identifier, Ident)),
182
tag("("),
183
separated_list(fn_arg_sep, fn_arg),
184
tag(")"),
@@ -447,7 +447,7 @@ fn advance_token(/*&mut self*/) -> Result<Token, MsgWithPos> {
447
448
fn parse_lambda<'b>(i: Span) -> EResult {
449
450
451
452
tag("|"),
453
0 commit comments