@@ -11,6 +11,7 @@ use crate::desugar::state::State;
1111use crate :: desugar:: ty:: desugar_type;
1212use crate :: parser:: ast:: Node ;
1313use crate :: parser:: ast:: AST ;
14+ use crate :: type_checker:: context:: ty:: concrete:: concrete_to_python;
1415
1516// TODO return imports instead of modifying mutable reference
1617pub fn desugar_node ( ast : & AST , imp : & mut Imports , state : & State ) -> DesugarResult {
@@ -48,6 +49,7 @@ pub fn desugar_node(ast: &AST, imp: &mut Imports, state: &State) -> DesugarResul
4849 num : num. clone ( ) ,
4950 exp : if exp. is_empty ( ) { String :: from ( "0" ) } else { exp. clone ( ) }
5051 } ,
52+ Node :: DocStr { lit } => Core :: DocStr { _str : lit. clone ( ) } ,
5153 Node :: Str { lit, expressions } =>
5254 if expressions. is_empty ( ) {
5355 Core :: Str { _str : lit. clone ( ) }
@@ -70,7 +72,9 @@ pub fn desugar_node(ast: &AST, imp: &mut Imports, state: &State) -> DesugarResul
7072
7173 Node :: Undefined => Core :: None ,
7274 Node :: IdType { .. } => desugar_type ( ast, imp, state) ?,
73- Node :: Id { lit } => Core :: Id { lit : lit. clone ( ) } ,
75+ Node :: Id { lit } => Core :: Id {
76+ lit : if state. is_constructor { concrete_to_python ( lit) } else { lit. clone ( ) }
77+ } ,
7478 Node :: _Self => Core :: Id { lit : String :: from ( "self" ) } ,
7579 Node :: Init => Core :: Id { lit : String :: from ( "init" ) } ,
7680 Node :: Bool { lit } => Core :: Bool { _bool : * lit } ,
@@ -215,7 +219,8 @@ pub fn desugar_node(ast: &AST, imp: &mut Imports, state: &State) -> DesugarResul
215219 }
216220 } ,
217221
218- Node :: FunctionCall { .. } | Node :: PropertyCall { .. } => desugar_call ( ast, imp, state) ?,
222+ Node :: FunctionCall { .. } | Node :: PropertyCall { .. } | Node :: ConstructorCall { .. } =>
223+ desugar_call ( ast, imp, state) ?,
219224
220225 Node :: AnonFun { args, body } => Core :: AnonFun {
221226 args : desugar_vec ( args, imp, & state. expand_ty ( false ) ) ?,
@@ -249,12 +254,9 @@ pub fn desugar_node(ast: &AST, imp: &mut Imports, state: &State) -> DesugarResul
249254 } ,
250255 Node :: Script { statements } =>
251256 Core :: Block { statements : desugar_vec ( statements, imp, state) ? } ,
252- Node :: File { modules, imports, .. } => {
253- let mut imports = desugar_vec ( imports, imp, state) ?;
257+ Node :: File { modules, .. } => {
254258 let mut modules = desugar_vec ( modules, imp, state) ?;
255- imports. append ( & mut imp. imports . clone ( ) . into_iter ( ) . collect ( ) ) ;
256-
257- let mut statements = imports;
259+ let mut statements = imp. imports . clone ( ) ;
258260 statements. append ( & mut modules) ;
259261 Core :: Block { statements }
260262 }
@@ -290,7 +292,6 @@ pub fn desugar_node(ast: &AST, imp: &mut Imports, state: &State) -> DesugarResul
290292 Node :: Step { .. } => panic ! ( "Step cannot be top level." ) ,
291293 Node :: Raises { expr_or_stmt, .. } => desugar_node ( expr_or_stmt, imp, state) ?,
292294 Node :: Raise { error } => Core :: Raise { error : Box :: from ( desugar_node ( error, imp, state) ?) } ,
293- Node :: Retry { .. } => return Err ( UnimplementedErr :: new ( ast, "retry" ) ) ,
294295
295296 Node :: Handle { expr_or_stmt, cases } => {
296297 let assign_to = if let Node :: VariableDef { id_maybe_type, .. } = & expr_or_stmt. node {
@@ -351,7 +352,7 @@ pub fn desugar_node(ast: &AST, imp: &mut Imports, state: &State) -> DesugarResul
351352 let core = if let Some ( assign_to) = assign_to {
352353 match core {
353354 Core :: Block { .. } | Core :: Return { .. } => core,
354- expr => Core :: Assign { left : Box :: from ( assign_to) , right : Box :: from ( expr. clone ( ) ) }
355+ expr => Core :: Assign { left : Box :: from ( assign_to) , right : Box :: from ( expr) }
355356 }
356357 } else {
357358 core
0 commit comments