Exemple #1
0
 public void Initialize()
 {
     _interpreter.AddWord(new PrimitiveWord(_interpreter, "?", PrintIndirectAction));
     _interpreter.AddWord(new PrimitiveWord(_interpreter, ".F", PrintFloatingPointStackAction));
     _interpreter.AddWord(new PrimitiveWord(_interpreter, ".O", PrintObjectStackAction));
     _interpreter.AddWord(new PrimitiveWord(_interpreter, ".S", PrintStackAction));
     _interpreter.AddWord(new PrimitiveWord(_interpreter, "WORDS", WordsAction));
 }
Exemple #2
0
        // FCONSTANT word-name
        // (F: f -- )
        private int FConstantAction()
        {
            _interpreter.FStackExpect(1);

            _interpreter.BeginNewWordCompilation();
            _interpreter.AddWord(new FloatingPointConstantWord(_interpreter, _interpreter.ParseWord(), _interpreter.FPop()));
            _interpreter.EndNewWordCompilation();

            return(1);
        }
Exemple #3
0
        // 2CONSTANT word-name
        // (n1 n2 -- )
        private int TwoConstantAction()
        {
            _interpreter.StackExpect(2);

            _interpreter.BeginNewWordCompilation();
            var n2 = _interpreter.Pop();

            _interpreter.AddWord(new DoubleCellConstantWord(_interpreter, _interpreter.ParseWord(), _interpreter.Pop(), n2));
            _interpreter.EndNewWordCompilation();

            return(1);
        }
Exemple #4
0
        /// <summary>
        /// Adds a constant word to the words list.
        /// </summary>
        /// <param name="interpreter">An IInterpreter instance.</param>
        /// <param name="name">A new word name.</param>
        /// <param name="n">A value.</param>
        public static void AddConstantWord(this IInterpreter interpreter, string name, int n)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("A word name expected.");
            }

            interpreter.AddWord(new ConstantWord(interpreter, name.ToUpperInvariant(), n));
        }
Exemple #5
0
        public void Initialize()
        {
            _interpreter.AddImmediateWord(".(", DotParenAction);
            _interpreter.AddPrimitiveWord("0<>", ZeroNotEqualsAction);
            _interpreter.AddPrimitiveWord("0>", ZeroGreaterAction);
            _interpreter.AddPrimitiveWord("2>R", TwoToRAction);
            _interpreter.AddPrimitiveWord("2R>", TwoRFromAction);
            _interpreter.AddPrimitiveWord("2R@", TwoRFetchAction);
            _interpreter.AddPrimitiveWord(":NONAME", NonameAction);
            _interpreter.AddImmediateWord(";", SemicolonAction);  // Extended version.
            _interpreter.AddPrimitiveWord("<>", NotEqualsAction);
            _interpreter.AddImmediateWord("?DO", QuestionDoAction);
            _interpreter.AddImmediateWord("AGAIN", AgainAction);
            _interpreter.AddPrimitiveWord("HEX", HexAction);
            _interpreter.AddPrimitiveWord("NIP", NipAction);
            _interpreter.AddPrimitiveWord("PICK", PickAction);
            _interpreter.AddPrimitiveWord("ROLL", RollAction);
            _interpreter.AddImmediateWord("S\\\"", SBackslashQuoteAction);  // S\" ..."
            _interpreter.AddPrimitiveWord("TO", ToAction);
            _interpreter.AddPrimitiveWord("TUCK", TuckAction);
            _interpreter.AddPrimitiveWord("VALUE", ValueAction);
            _interpreter.AddWord(new WithinWord(_interpreter));
            _interpreter.AddPrimitiveWord("\\", BackslashAction);


            _interpreter.AddConstantWord("FALSE", 0);
            _interpreter.AddConstantWord("TRUE", -1);

            _interpreter.AddPrimitiveWord("B!", BStoreAction);
            _interpreter.AddPrimitiveWord("B,", BCommaAction);
            _interpreter.AddPrimitiveWord("B@", BFetchAction);
            _interpreter.AddPrimitiveWord("BYTE+", BytePlusAction);
            _interpreter.AddPrimitiveWord("BYTES", BytesAction);

            _interpreter.AddPrimitiveWord("-ROLL", MinusRollAction);
            _interpreter.AddPrimitiveWord("-ROT", MinusRotAction);
            _interpreter.AddPrimitiveWord("2+", TwoPlusAction);
            _interpreter.AddPrimitiveWord("2-", TwoMinusAction);
            _interpreter.AddPrimitiveWord("2NIP", TwoNipAction);
            _interpreter.AddPrimitiveWord("2TUCK", TwoTuckAction);
            _interpreter.AddPrimitiveWord("<=", LessOrEqualsAction);
            _interpreter.AddPrimitiveWord(">=", GreaterOrEqualsAction);
            _interpreter.AddPrimitiveWord("CLEAR", ClearAction);
        }
Exemple #6
0
        /// <summary>
        /// Adds an immediate word to the words list.
        /// </summary>
        /// <param name="interpreter">An IInterpreter instance.</param>
        /// <param name="name">A new word name.</param>
        /// <param name="action">An action, this word is doing.</param>
        public static void AddImmediateWord(this IInterpreter interpreter, string name, Func <int> action)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("A word name expected.");
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            interpreter.AddWord(new ImmediateWord(interpreter, name.ToUpperInvariant(), action));
        }
Exemple #7
0
 public void Initialize()
 {
     _interpreter.AddWord(new StoreWord(_interpreter));             // !
     _interpreter.AddWord(new NumberSignWord(_interpreter));        // #
     _interpreter.AddWord(new NumberSignGreaterWord(_interpreter)); // #>
     _interpreter.AddWord(new NumberSignSWord(_interpreter));       // #S
     _interpreter.AddWord(new TickWord(_interpreter));              // '
     _interpreter.AddWord(new ParenWord(_interpreter));             // (
     _interpreter.AddWord(new StarWord(_interpreter));              // *
     _interpreter.AddWord(new StarSlashWord(_interpreter));         // */
     _interpreter.AddWord(new StarSlashModWord(_interpreter));      // */MOD
     _interpreter.AddWord(new PlusWord(_interpreter));              // +
     _interpreter.AddWord(new PlusStoreWord(_interpreter));         // +!
     _interpreter.AddWord(new PlusLoopWord(_interpreter));          // +LOOP
     _interpreter.AddWord(new CommaWord(_interpreter));             // ,
     _interpreter.AddWord(new MinusWord(_interpreter));             // -
     _interpreter.AddWord(new DotWord(_interpreter));               // .
     _interpreter.AddWord(new DotQuoteWord(_interpreter));          // ."
     _interpreter.AddPrimitiveWord("/", SlashAction);
     _interpreter.AddWord(new SlashModWord(_interpreter));          // /MOD
     _interpreter.AddPrimitiveWord("0<", ZeroLessAction);
     _interpreter.AddPrimitiveWord("0=", ZeroEqualsAction);
     _interpreter.AddPrimitiveWord("1+", OnePlusAction);
     _interpreter.AddPrimitiveWord("1-", OneMinusAction);
     _interpreter.AddPrimitiveWord("2!", TwoStoreAction);
     _interpreter.AddPrimitiveWord("2*", TwoStarAction);
     _interpreter.AddPrimitiveWord("2/", TwoSlashAction);
     _interpreter.AddPrimitiveWord("2@", TwoFetchAction);
     _interpreter.AddPrimitiveWord("2DROP", TwoDropAction);
     _interpreter.AddPrimitiveWord("2DUP", TwoDupAction);
     _interpreter.AddPrimitiveWord("2OVER", TwoOverAction);
     _interpreter.AddPrimitiveWord("2SWAP", TwoSwapAction);
     _interpreter.AddPrimitiveWord(":", ColonAction);
     _interpreter.AddImmediateWord(";", SemicolonAction);
     _interpreter.AddPrimitiveWord("<", LessThanAction);
     _interpreter.AddWord(new LessNumberSignWord(_interpreter));   // <#
     _interpreter.AddPrimitiveWord("=", EqualsAction);
     _interpreter.AddPrimitiveWord(">", GreaterThanAction);
     _interpreter.AddPrimitiveWord(">BODY", ToBodyAction);
     _interpreter.AddPrimitiveWord(">NUMBER", ToNumberAction);
     _interpreter.AddPrimitiveWord(">R", ToRAction);
     _interpreter.AddPrimitiveWord("?DUP", QuestionDupeAction);
     _interpreter.AddPrimitiveWord("@", FetchAction);
     _interpreter.AddPrimitiveWord("ABORT", AbortAction);
     _interpreter.AddImmediateWord("ABORT\"", AbortWithMessageAction);
     _interpreter.AddPrimitiveWord("ABS", AbsAction);
     _interpreter.AddPrimitiveWord("ALIGN", AlignAction);
     _interpreter.AddPrimitiveWord("ALIGNED", AlignedAction);
     _interpreter.AddPrimitiveWord("ALLOT", AllotAction);
     _interpreter.AddPrimitiveWord("AND", AndAction);
     _interpreter.AddPrimitiveWord("BASE", BaseAction);
     _interpreter.AddImmediateWord("BEGIN", BeginAction);
     _interpreter.AddConstantWord("BL", ' ');
     _interpreter.AddPrimitiveWord("C!", CStoreAction);
     _interpreter.AddPrimitiveWord("C,", CCommaAction);
     _interpreter.AddPrimitiveWord("C@", CFetchAction);
     _interpreter.AddPrimitiveWord("CELL+", CellPlusAction);
     _interpreter.AddPrimitiveWord("CELLS", CellsAction);
     _interpreter.AddPrimitiveWord("CHAR", CharAction);
     _interpreter.AddPrimitiveWord("CHAR+", CharPlusAction);
     _interpreter.AddPrimitiveWord("CHARS", CharsAction);
     _interpreter.AddPrimitiveWord("CONSTANT", ConstantAction);
     _interpreter.AddPrimitiveWord("COUNT", CountAction);
     _interpreter.AddPrimitiveWord("CR", CrAction);
     _interpreter.AddPrimitiveWord("CREATE", CreateAction);
     _interpreter.AddPrimitiveWord("DECIMAL", DecimalAction);
     _interpreter.AddPrimitiveWord("DEPTH", DepthAction);
     _interpreter.AddImmediateWord("DO", DoAction);
     _interpreter.AddImmediateWord("DOES>", DoesAction);
     _interpreter.AddPrimitiveWord("DROP", DropAction);
     _interpreter.AddPrimitiveWord("DUP", DupAction);
     _interpreter.AddImmediateWord("ELSE", ElseAction);
     _interpreter.AddPrimitiveWord("EMIT", EmitAction);
     _interpreter.AddPrimitiveWord("EVALUATE", EvaluateAction);
     _interpreter.AddPrimitiveWord("EXECUTE", ExecuteAction);
     _interpreter.AddImmediateWord("EXIT", ExitAction);
     _interpreter.AddWord(new FillWord(_interpreter));       // FILL
     _interpreter.AddPrimitiveWord("FIND", FindAction);
     _interpreter.AddPrimitiveWord("FM/MOD", FMSlashModAction);
     _interpreter.AddPrimitiveWord("HERE", HereAction);
     _interpreter.AddWord(new HoldWord(_interpreter));       // HOLD
     _interpreter.AddImmediateWord("I", GetInnerIndexAction);
     _interpreter.AddImmediateWord("IF", IfAction);
     _interpreter.AddPrimitiveWord("IMMEDIATE", ImmediateAction);
     _interpreter.AddPrimitiveWord("INVERT", InvertAction);
     _interpreter.AddImmediateWord("J", GetOuterIndexAction);
     _interpreter.AddImmediateWord("LEAVE", LeaveAction);
     _interpreter.AddImmediateWord("LITERAL", LiteralAction);
     _interpreter.AddPrimitiveWord("LSHIFT", LShiftAction);
     _interpreter.AddPrimitiveWord("M*", MStarAction);
     _interpreter.AddImmediateWord("LOOP", LoopAction);
     _interpreter.AddPrimitiveWord("MAX", MaxAction);
     _interpreter.AddPrimitiveWord("MIN", MinAction);
     _interpreter.AddPrimitiveWord("MOD", ModAction);
     _interpreter.AddPrimitiveWord("MOVE", MoveAction);
     _interpreter.AddPrimitiveWord("NEGATE", NegateAction);
     _interpreter.AddPrimitiveWord("OR", OrAction);
     _interpreter.AddPrimitiveWord("OVER", OverAction);
     _interpreter.AddImmediateWord("POSTPONE", PostponeAction);
     _interpreter.AddPrimitiveWord("QUIT", QuitAction);
     _interpreter.AddPrimitiveWord("R>", RFromAction);
     _interpreter.AddPrimitiveWord("R@", RFetchAction);
     _interpreter.AddImmediateWord("RECURSE", RecurseAction);
     _interpreter.AddImmediateWord("REPEAT", RepeatAction);
     _interpreter.AddPrimitiveWord("ROT", RoteAction);
     _interpreter.AddPrimitiveWord("RSHIFT", RShiftAction);
     _interpreter.AddImmediateWord("S\"", SQuoteAction);
     _interpreter.AddPrimitiveWord("S>D", SToDAction);
     _interpreter.AddWord(new SignWord(_interpreter));   // SIGN
     _interpreter.AddPrimitiveWord("SM/REM", SMSlashRemAction);
     _interpreter.AddPrimitiveWord("SPACE", SpaceAction);
     _interpreter.AddPrimitiveWord("SPACES", SpacesAction);
     _interpreter.AddPrimitiveWord("STATE", StateAction);
     _interpreter.AddPrimitiveWord("SWAP", SwapAction);
     _interpreter.AddImmediateWord("THEN", ThenAction);
     _interpreter.AddPrimitiveWord("TYPE", TypeAction);
     _interpreter.AddPrimitiveWord("U.", UDotAction);
     _interpreter.AddPrimitiveWord("U<", ULessThanAction);
     _interpreter.AddPrimitiveWord("UM*", UMStarAction);
     _interpreter.AddPrimitiveWord("UM/MOD", UMSlashModAction);
     _interpreter.AddImmediateWord("UNLOOP", UnloopAction);
     _interpreter.AddImmediateWord("UNTIL", UntilAction);
     _interpreter.AddPrimitiveWord("VARIABLE", VariableAction);
     _interpreter.AddImmediateWord("WHILE", WhileAction);
     _interpreter.AddPrimitiveWord("WORD", WordAction);
     _interpreter.AddPrimitiveWord("XOR", XorAction);
     _interpreter.AddImmediateWord("[", LeftBracketAction);
     _interpreter.AddImmediateWord("[']", BracketTickAction);
     _interpreter.AddImmediateWord("[CHAR]", BracketCharAction);
     _interpreter.AddImmediateWord("]", RightBracketAction);
 }
Exemple #8
0
 public void Initialize()
 {
     _interpreter.AddWord(new PrimitiveWord(_interpreter, "BYE", ByeAction));
     _interpreter.AddWord(new PrimitiveWord(_interpreter, "FORGET", ForgetAction));
 }
Exemple #9
0
        public void Initialize()
        {
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OALLOT", AllotAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OHERE", HereAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OVARIABLE", VariableCompilationAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "O!", StoreToVariableAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "O@", FetchFromVariableAction));

            _interpreter.AddWord(new PrimitiveWord(_interpreter, "ODUP", DupAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "ODROP", DropAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OSWAP", SwapAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OOVER", OverAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OPICK", PickAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OROLL", RollAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OOROT", RotAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "-OROT", RotBackAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "ODEPTH", DepthAction));
            _interpreter.AddWord(new PrimitiveWord(_interpreter, "OCLEAR", ClearAction));
        }
Exemple #10
0
 public void Initialize()
 {
     _interpreter.AddWord(new PrimitiveWord(_interpreter, "S.", PrintStringAction));
     _interpreter.AddWord(new PrimitiveWord(_interpreter, "S+", AddAction));
 }