Moved int/float/typeof to the standard library
This commit is contained in:
parent
be73c33069
commit
723b8b64c9
5 changed files with 14 additions and 62 deletions
|
@ -73,17 +73,17 @@ namespace arookas {
|
|||
|
||||
[Flags]
|
||||
enum sunExpressionFlags {
|
||||
// contents
|
||||
None = 0,
|
||||
Literals = 1,
|
||||
Variables = 2,
|
||||
Augments = 4,
|
||||
Casts = 8,
|
||||
Calls = 16,
|
||||
Constants = 32,
|
||||
|
||||
// contents
|
||||
Literals = 1 << 0,
|
||||
Variables = 1 << 1,
|
||||
Augments = 1 << 2,
|
||||
Calls = 1 << 3,
|
||||
Constants = 1 << 4,
|
||||
|
||||
// description
|
||||
Dynamic = 64,
|
||||
Dynamic = 1 << 5,
|
||||
}
|
||||
|
||||
class sunOperand : sunNode {
|
||||
|
|
|
@ -38,45 +38,4 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace arookas {
|
|||
"builtin", "function", "var", "const", "local",
|
||||
"if", "while", "do", "for",
|
||||
"return", "break", "continue",
|
||||
"yield", "exit", "lock", "unlock", "int", "float", "typeof",
|
||||
"yield", "exit", "lock", "unlock",
|
||||
"true", "false",
|
||||
};
|
||||
|
||||
|
@ -157,10 +157,6 @@ namespace arookas {
|
|||
|
||||
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.POSTFIX_AUGMENT: return new sunPostfixAugment(location);
|
||||
}
|
||||
|
|
|
@ -156,9 +156,6 @@ augment_operator = INCREMENT | DECREMENT;
|
|||
expression = operand {binary_operator operand};
|
||||
operand = [unary_operator_list] term;
|
||||
term =
|
||||
int_cast |
|
||||
float_cast |
|
||||
typeof_cast |
|
||||
function_call |
|
||||
variable_reference |
|
||||
variable_augment |
|
||||
|
@ -173,10 +170,6 @@ term =
|
|||
|
||||
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
|
||||
const_definition = const_modifiers IDENTIFIER ASSIGN expression;
|
||||
const_modifiers = CONST [LOCAL];
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
* 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_FLOAT = 1;
|
||||
const TYPE_STRING = 2;
|
||||
|
|
Loading…
Reference in a new issue