Changed declare/define functions

This commit is contained in:
arookas 2016-02-01 04:57:07 -05:00
parent 6f74979d61
commit 25c3853309

View file

@ -53,26 +53,27 @@ namespace arookas {
// callables // callables
public sunBuiltinSymbol DeclareBuiltin(sunBuiltinDeclaration node) { public sunBuiltinSymbol DeclareBuiltin(sunBuiltinDeclaration node) {
if (SymbolTable.Callables.Any(i => i.Name == node.Builtin.Value)) { if (SymbolTable.Callables.Any(i => i.Name == node.Name.Value)) {
throw new sunRedeclaredBuiltinException(node); throw new sunRedeclaredBuiltinException(node);
} }
var symbol = new sunBuiltinSymbol(node.Builtin.Value, node.Parameters.ParameterInfo, SymbolTable.Count); var symbol = new sunBuiltinSymbol(node.Name.Value, node.Parameters.ParameterInfo, SymbolTable.Count);
SymbolTable.Add(symbol); SymbolTable.Add(symbol);
return symbol; return symbol;
} }
public sunFunctionSymbol DefineFunction(sunFunctionDefinition node) { public sunFunctionSymbol DefineFunction(sunFunctionDefinition node) {
var name = MangleSymbolName(node.Name.Value, false, (node.Modifiers & sunSymbolModifiers.Local) != 0);
if (node.Parameters.IsVariadic) { if (node.Parameters.IsVariadic) {
throw new sunVariadicFunctionException(node); throw new sunVariadicFunctionException(node);
} }
if (SymbolTable.Callables.Any(i => i.Name == node.Function.Value)) { if (SymbolTable.Callables.Any(i => i.Name == name)) {
throw new sunRedefinedFunctionException(node); throw new sunRedefinedFunctionException(node);
} }
var symbol = new sunFunctionSymbol(node.Function.Value, node.Parameters.ParameterInfo, node.Body); var symbol = new sunFunctionSymbol(name, node.Parameters.ParameterInfo, node.Body);
SymbolTable.Add(symbol); SymbolTable.Add(symbol);
return symbol; return symbol;
} }
public sunCallableSymbol ResolveCallable(sunFunctionCall node) { public sunCallableSymbol ResolveCallable(sunFunctionCall node) {
var global = node.Function.Value; var global = node.Name.Value;
var local = MangleSymbolName(global, false, true); var local = MangleSymbolName(global, false, true);
var symbol = SymbolTable.Callables.FirstOrDefault(i => i.Name == local); var symbol = SymbolTable.Callables.FirstOrDefault(i => i.Name == local);
if (symbol != null) { if (symbol != null) {
@ -93,17 +94,24 @@ namespace arookas {
} }
// storables // storables
public sunVariableSymbol DeclareVariable(sunIdentifier node) { public sunVariableSymbol DeclareVariable(sunVariableDeclaration node) {
return DeclareVariable(node.Name, node.Modifiers);
}
public sunVariableSymbol DeclareVariable(sunVariableDefinition node) {
return DeclareVariable(node.Name, node.Modifiers);
}
sunVariableSymbol DeclareVariable(sunIdentifier node, sunSymbolModifiers modifiers) {
var name = MangleSymbolName(node.Value, false, false);
#if SSC_PACK_VARS #if SSC_PACK_VARS
if (Scopes.Top.GetIsDeclared(node.Value)) { if (Scopes.Top.GetIsDeclared(name)) {
throw new sunRedeclaredVariableException(node); throw new sunRedeclaredVariableException(node);
} }
#else #else
if (Scopes.Any(i => i.GetIsDeclared(node.Value))) { if (Scopes.Any(i => i.GetIsDeclared(name))) {
throw new sunRedeclaredVariableException(node); throw new sunRedeclaredVariableException(node);
} }
#endif #endif
var symbol = Scopes.DeclareVariable(node.Value); var symbol = Scopes.DeclareVariable(name);
if (Scopes.Top.Type == sunScopeType.Script) { // global-scope variables are added to the symbol table if (Scopes.Top.Type == sunScopeType.Script) { // global-scope variables are added to the symbol table
#if SSC_PACK_VARS #if SSC_PACK_VARS
// only add the variable symbol if there isn't one with this index already // only add the variable symbol if there isn't one with this index already
@ -116,17 +124,21 @@ namespace arookas {
} }
return symbol; return symbol;
} }
public sunConstantSymbol DeclareConstant(sunIdentifier node, sunExpression expression) { public sunConstantSymbol DeclareConstant(sunConstantDefinition node) {
return DeclareConstant(node.Name, node.Expression, node.Modifiers);
}
sunConstantSymbol DeclareConstant(sunIdentifier node, sunExpression expression, sunSymbolModifiers modifiers) {
var name = MangleSymbolName(node.Value, false, (modifiers & sunSymbolModifiers.Local) != 0);
#if SSC_PACK_VARS #if SSC_PACK_VARS
if (Scopes.Top.GetIsDeclared(node.Value)) { if (Scopes.Top.GetIsDeclared(name)) {
throw new sunRedeclaredVariableException(node); throw new sunRedeclaredVariableException(node);
} }
#else #else
if (Scopes.Any(i => i.GetIsDeclared(node.Value))) { if (Scopes.Any(i => i.GetIsDeclared(name))) {
throw new sunRedeclaredVariableException(node); throw new sunRedeclaredVariableException(node);
} }
#endif #endif
return Scopes.DeclareConstant(node.Value, expression); return Scopes.DeclareConstant(name, expression);
} }
public sunStorableSymbol ResolveStorable(sunIdentifier node) { public sunStorableSymbol ResolveStorable(sunIdentifier node) {
var global = node.Value; var global = node.Value;