コード例 #1
0
		public override void Accept (UseStatement useStmt)
		{
			string import = !useStmt.Relative ? useStmt.Module : Path.Combine (
				                Path.GetDirectoryName (useStmt.Location.File),
				                useStmt.Module);
			/*
			 * Implementation detail: The use statement in all reality is simply an 
			 * alias for the function require (); Here we translate the use statement
			 * into a call to the require function
			 */
			if (useStmt.Wildcard) {
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.LoadConst,
					module.DefineConstant (new IodineString (import)));
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.BuildTuple, 0);
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.LoadGlobal,
					module.DefineConstant (new IodineName ("require")));
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.Invoke, 2);
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.Pop);
			} else {
				IodineObject[] items = new IodineObject [useStmt.Imports.Count];

				module.Initializer.EmitInstruction (useStmt.Location, Opcode.LoadConst,
					module.DefineConstant (new IodineString (import)));
				if (items.Length > 0) {
					for (int i = 0; i < items.Length; i++) {
						items [i] = new IodineString (useStmt.Imports [i]);
						module.Initializer.EmitInstruction (useStmt.Location, Opcode.LoadConst,
							module.DefineConstant (new IodineString (useStmt.Imports [i])));
					}
					module.Initializer.EmitInstruction (useStmt.Location, Opcode.BuildTuple, items.Length);
				}
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.LoadGlobal,
					module.DefineConstant (new IodineName ("require")));
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.Invoke,
					items.Length == 0 ? 1 : 2);
				module.Initializer.EmitInstruction (useStmt.Location, Opcode.Pop);
			}
			
		}
コード例 #2
0
		public override void Accept (UseStatement useStmt)
		{
			
		}
コード例 #3
0
ファイル: FunctionCompiler.cs プロジェクト: iwatakeshi/Iodine
 public void Accept(UseStatement useStmt)
 {
 }
コード例 #4
0
ファイル: ModuleCompiler.cs プロジェクト: iwatakeshi/Iodine
        public void Accept(UseStatement useStmt)
        {
            module.Imports.Add (useStmt.Module);

            string import = !useStmt.Relative ? useStmt.Module : Path.Combine (
                                Path.GetDirectoryName (useStmt.Location.File),
                                useStmt.Module);

            if (useStmt.Wildcard) {
                module.Initializer.EmitInstruction (Opcode.LoadConst, module.DefineConstant (
                    new IodineString (import)));
                module.Initializer.EmitInstruction (Opcode.BuildTuple, 0);
                module.Initializer.EmitInstruction (Opcode.LoadGlobal, module.DefineConstant (
                    new IodineName ("require")));
                module.Initializer.EmitInstruction (Opcode.Invoke, 2);
                module.Initializer.EmitInstruction (Opcode.Pop);
            } else {
                IodineObject[] items = new IodineObject [useStmt.Imports.Count];

                module.Initializer.EmitInstruction (Opcode.LoadConst, module.DefineConstant (
                    new IodineString (import)));
                if (items.Length > 0) {
                    for (int i = 0; i < items.Length; i++) {
                        items [i] = new IodineString (useStmt.Imports [i]);
                        module.Initializer.EmitInstruction (Opcode.LoadConst, module.DefineConstant (
                            new IodineString (useStmt.Imports [i])));
                    }
                    module.Initializer.EmitInstruction (Opcode.BuildTuple, items.Length);
                }
                module.Initializer.EmitInstruction (Opcode.LoadGlobal, module.DefineConstant (
                    new IodineName ("require")));
                module.Initializer.EmitInstruction (Opcode.Invoke, items.Length == 0 ? 1 : 2);
                module.Initializer.EmitInstruction (Opcode.Pop);
            }
        }
コード例 #5
0
		public override void Accept (UseStatement useStmt)
		{
			errorLog.AddError (ErrorType.ParserError, useStmt.Location,
				"statement can not exist inside pattern!");
		}
コード例 #6
0
 public virtual void Accept(UseStatement useStmt)
 {
 }
コード例 #7
0
ファイル: FunctionAnalyser.cs プロジェクト: iwatakeshi/Iodine
 public void Accept(UseStatement useStmt)
 {
     errorLog.AddError (ErrorType.ParserError, useStmt.Location,
         "use statement not valid inside function body!");
 }