Moved int/float/typeof to the standard library

This commit is contained in:
arookas 2016-02-01 03:26:44 -05:00
parent be73c33069
commit 723b8b64c9
5 changed files with 14 additions and 62 deletions

View file

@ -73,17 +73,17 @@ namespace arookas {
[Flags] [Flags]
enum sunExpressionFlags { enum sunExpressionFlags {
// contents
None = 0, None = 0,
Literals = 1,
Variables = 2, // contents
Augments = 4, Literals = 1 << 0,
Casts = 8, Variables = 1 << 1,
Calls = 16, Augments = 1 << 2,
Constants = 32, Calls = 1 << 3,
Constants = 1 << 4,
// description // description
Dynamic = 64, Dynamic = 1 << 5,
} }
class sunOperand : sunNode { class sunOperand : sunNode {

View file

@ -38,45 +38,4 @@
compiler.Binary.WritePOP(); compiler.Binary.WritePOP();
} }
} }
abstract class sunCast : sunNode, sunTerm {
public sunExpression Argument { get { return this[0] as sunExpression; } }
protected sunCast(sunSourceLocation location)
: base(location) { }
sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) {
return sunExpressionFlags.Casts | Argument.Analyze(context);
}
}
class sunIntCast : sunCast {
public sunIntCast(sunSourceLocation location)
: base(location) { }
public override void Compile(sunCompiler compiler) {
Argument.Compile(compiler);
compiler.Context.Int.OpenCallSite(compiler, 1);
}
}
class sunFloatCast : sunCast {
public sunFloatCast(sunSourceLocation location)
: base(location) { }
public override void Compile(sunCompiler compiler) {
Argument.Compile(compiler);
compiler.Context.Float.OpenCallSite(compiler, 1);
}
}
class sunTypeofCast : sunCast {
public sunTypeofCast(sunSourceLocation location)
: base(location) { }
public override void Compile(sunCompiler compiler) {
Argument.Compile(compiler);
compiler.Context.Typeof.OpenCallSite(compiler, 1);
}
}
} }

View file

@ -8,7 +8,7 @@ namespace arookas {
"builtin", "function", "var", "const", "local", "builtin", "function", "var", "const", "local",
"if", "while", "do", "for", "if", "while", "do", "for",
"return", "break", "continue", "return", "break", "continue",
"yield", "exit", "lock", "unlock", "int", "float", "typeof", "yield", "exit", "lock", "unlock",
"true", "false", "true", "false",
}; };
@ -157,10 +157,6 @@ namespace arookas {
case __sunConstants.UNARY_OPERATOR_LIST: return new sunUnaryOperatorList(location); case __sunConstants.UNARY_OPERATOR_LIST: return new sunUnaryOperatorList(location);
case __sunConstants.INT_CAST: return new sunIntCast(location);
case __sunConstants.FLOAT_CAST: return new sunFloatCast(location);
case __sunConstants.TYPEOF_CAST: return new sunTypeofCast(location);
case __sunConstants.PREFIX_AUGMENT: return new sunPrefixAugment(location); case __sunConstants.PREFIX_AUGMENT: return new sunPrefixAugment(location);
case __sunConstants.POSTFIX_AUGMENT: return new sunPostfixAugment(location); case __sunConstants.POSTFIX_AUGMENT: return new sunPostfixAugment(location);
} }

View file

@ -156,9 +156,6 @@ augment_operator = INCREMENT | DECREMENT;
expression = operand {binary_operator operand}; expression = operand {binary_operator operand};
operand = [unary_operator_list] term; operand = [unary_operator_list] term;
term = term =
int_cast |
float_cast |
typeof_cast |
function_call | function_call |
variable_reference | variable_reference |
variable_augment | variable_augment |
@ -173,10 +170,6 @@ term =
unary_operator_list = unary_operator+; unary_operator_list = unary_operator+;
int_cast = INT L_PAREN expression R_PAREN;
float_cast = FLOAT L_PAREN expression R_PAREN;
typeof_cast = TYPEOF L_PAREN expression R_PAREN;
// constants // constants
const_definition = const_modifiers IDENTIFIER ASSIGN expression; const_definition = const_modifiers IDENTIFIER ASSIGN expression;
const_modifiers = CONST [LOCAL]; const_modifiers = CONST [LOCAL];

View file

@ -5,7 +5,11 @@
* 2015-2016 arookas * 2015-2016 arookas
\* ================================================= */ \* ================================================= */
// return values for typeof(x) // casting
builtin const int(x);
builtin const float(x);
builtin const typeof(x);
const TYPE_INT = 0; const TYPE_INT = 0;
const TYPE_FLOAT = 1; const TYPE_FLOAT = 1;
const TYPE_STRING = 2; const TYPE_STRING = 2;