xref: /illumos-gate/usr/src/common/ficl/word.c (revision afc2ba1d)
1 #include "ficl.h"
2 
3 /*
4  * w o r d I s I m m e d i a t e
5  */
6 int
ficlWordIsImmediate(ficlWord * word)7 ficlWordIsImmediate(ficlWord *word)
8 {
9 	return ((word != NULL) && (word->flags & FICL_WORD_IMMEDIATE));
10 }
11 
12 /*
13  * w o r d I s C o m p i l e O n l y
14  */
15 int
ficlWordIsCompileOnly(ficlWord * word)16 ficlWordIsCompileOnly(ficlWord *word)
17 {
18 	return ((word != NULL) && (word->flags & FICL_WORD_COMPILE_ONLY));
19 }
20 
21 /*
22  * f i c l W o r d C l a s s i f y
23  * This public function helps to classify word types for SEE
24  * and the debugger in tools.c. Given an pointer to a word, it returns
25  * a member of WOR
26  */
27 ficlWordKind
ficlWordClassify(ficlWord * word)28 ficlWordClassify(ficlWord *word)
29 {
30 	ficlPrimitive code;
31 	ficlInstruction i;
32 	ficlWordKind iType;
33 
34 	if ((((ficlInstruction)word) > ficlInstructionInvalid) &&
35 	    (((ficlInstruction)word) < ficlInstructionLast)) {
36 		i = (ficlInstruction)word;
37 		iType = FICL_WORDKIND_INSTRUCTION;
38 		goto IS_INSTRUCTION;
39 	}
40 
41 	code = word->code;
42 
43 	if ((((ficlInstruction)code) > ficlInstructionInvalid) &&
44 	    (((ficlInstruction)code) < ficlInstructionLast)) {
45 		i = (ficlInstruction)code;
46 		iType = FICL_WORDKIND_INSTRUCTION_WORD;
47 		goto IS_INSTRUCTION;
48 	}
49 
50 	return (FICL_WORDKIND_PRIMITIVE);
51 
52 IS_INSTRUCTION:
53 
54 	switch (i) {
55 	case ficlInstructionConstantParen:
56 #if FICL_WANT_FLOAT
57 	case ficlInstructionFConstantParen:
58 #endif /* FICL_WANT_FLOAT */
59 	return (FICL_WORDKIND_CONSTANT);
60 
61 	case ficlInstruction2ConstantParen:
62 #if FICL_WANT_FLOAT
63 	case ficlInstructionF2ConstantParen:
64 #endif /* FICL_WANT_FLOAT */
65 	return (FICL_WORDKIND_2CONSTANT);
66 
67 #if FICL_WANT_LOCALS
68 	case ficlInstructionToLocalParen:
69 	case ficlInstructionTo2LocalParen:
70 #if FICL_WANT_FLOAT
71 	case ficlInstructionToFLocalParen:
72 	case ficlInstructionToF2LocalParen:
73 #endif /* FICL_WANT_FLOAT */
74 	return (FICL_WORDKIND_INSTRUCTION_WITH_ARGUMENT);
75 #endif /* FICL_WANT_LOCALS */
76 
77 #if FICL_WANT_USER
78 	case ficlInstructionUserParen:
79 	return (FICL_WORDKIND_USER);
80 #endif
81 
82 	case ficlInstruction2LiteralParen:
83 	return (FICL_WORDKIND_2LITERAL);
84 
85 #if FICL_WANT_FLOAT
86 	case ficlInstructionFLiteralParen:
87 	return (FICL_WORDKIND_FLITERAL);
88 #endif
89 	case ficlInstructionCreateParen:
90 	return (FICL_WORDKIND_CREATE);
91 
92 	case ficlInstructionCStringLiteralParen:
93 	return (FICL_WORDKIND_CSTRING_LITERAL);
94 
95 	case ficlInstructionStringLiteralParen:
96 	return (FICL_WORDKIND_STRING_LITERAL);
97 
98 	case ficlInstructionColonParen:
99 	return (FICL_WORDKIND_COLON);
100 
101 	case ficlInstructionDoDoes:
102 	return (FICL_WORDKIND_DOES);
103 
104 	case ficlInstructionDoParen:
105 	return (FICL_WORDKIND_DO);
106 
107 	case ficlInstructionQDoParen:
108 	return (FICL_WORDKIND_QDO);
109 
110 	case ficlInstructionVariableParen:
111 	return (FICL_WORDKIND_VARIABLE);
112 
113 	case ficlInstructionBranchParenWithCheck:
114 	case ficlInstructionBranchParen:
115 	return (FICL_WORDKIND_BRANCH);
116 
117 	case ficlInstructionBranch0ParenWithCheck:
118 	case ficlInstructionBranch0Paren:
119 	return (FICL_WORDKIND_BRANCH0);
120 
121 	case ficlInstructionLiteralParen:
122 	return (FICL_WORDKIND_LITERAL);
123 
124 	case ficlInstructionLoopParen:
125 	return (FICL_WORDKIND_LOOP);
126 
127 	case ficlInstructionOfParen:
128 	return (FICL_WORDKIND_OF);
129 
130 	case ficlInstructionPlusLoopParen:
131 	return (FICL_WORDKIND_PLOOP);
132 
133 	default:
134 	return (iType);
135 	}
136 }
137