From 723b8b64c9a4338827f0bed0ac66a537f063a257 Mon Sep 17 00:00:00 2001 From: arookas Date: Mon, 1 Feb 2016 03:26:44 -0500 Subject: [PATCH] Moved int/float/typeof to the standard library --- ssc/ast/nodes.expressions.cs | 16 +++++++------- ssc/ast/nodes.system.cs | 41 ------------------------------------ ssc/parser.cs | 6 +----- ssc/sunscript.grammar | 7 ------ stdlib/common.sun | 6 +++++- 5 files changed, 14 insertions(+), 62 deletions(-) diff --git a/ssc/ast/nodes.expressions.cs b/ssc/ast/nodes.expressions.cs index 18e43bf..9de3a3f 100644 --- a/ssc/ast/nodes.expressions.cs +++ b/ssc/ast/nodes.expressions.cs @@ -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 { diff --git a/ssc/ast/nodes.system.cs b/ssc/ast/nodes.system.cs index 3f1c1be..156d190 100644 --- a/ssc/ast/nodes.system.cs +++ b/ssc/ast/nodes.system.cs @@ -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); - } - } } diff --git a/ssc/parser.cs b/ssc/parser.cs index b964394..204bab3 100644 --- a/ssc/parser.cs +++ b/ssc/parser.cs @@ -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); } diff --git a/ssc/sunscript.grammar b/ssc/sunscript.grammar index 54fd269..2930a9b 100644 --- a/ssc/sunscript.grammar +++ b/ssc/sunscript.grammar @@ -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]; diff --git a/stdlib/common.sun b/stdlib/common.sun index 90ce80e..7a62ee8 100644 --- a/stdlib/common.sun +++ b/stdlib/common.sun @@ -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;