public override void Emit(TranspilerStream stream) { // Declaration of a variable. var typeSpec = new SimpleTypeSpec(Value.TypeDecl.Id); var decl = new VarDecl(Block, Id, typeSpec, Mutable ? VarAccess.MutableLocal : VarAccess.ImmutableLocal); if (!Mutable) { stream.Write("const "); } decl.TypeSpec.Emit(stream); stream.Write(' '); stream.Write(decl.CName); stream.Write('='); Value.Emit(stream); stream.WriteLine(';'); Block.Vars[decl.Id.Text] = decl; }
public FnDecl(Block block, Token id, List <Param> parameters, TypeSpec?returnType, Block body) : base(block, id) { Params = parameters; ReturnType = returnType; Body = body; Body.ParentDecl = this; // Give the body of this function variable declarations for the parameters. foreach (var param in parameters) { // Verify the type for each parameter is defined now: Block.FindType(param.TypeSpec); VarAccess varAccess; switch (param.PassedBy) { case PassedBy.ImmutableBorrow: varAccess = VarAccess.ImmutableBorrow; break; case PassedBy.MutableBorrow: varAccess = VarAccess.MutableBorrow; break; case PassedBy.DynamicTake: varAccess = VarAccess.DynamicTake; break; default: throw new NotImplementedException(); } var varDecl = new VarDecl(Body, param.Id, param.TypeSpec, varAccess); Body.Vars.Add(varDecl.Id.Text, varDecl); } }