Skip to content

Commit

Permalink
Make a few constants available. Closes #521
Browse files Browse the repository at this point in the history
  • Loading branch information
nddrylliog committed Dec 25, 2012
1 parent 8c836d2 commit 9c36639
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion source/rock/middle/VariableAccess.ooc
Expand Up @@ -3,11 +3,14 @@ import BinaryOp, Visitor, Expression, VariableDecl, FunctionDecl,
TypeDecl, Declaration, Type, Node, ClassDecl, NamespaceDecl,
EnumDecl, PropertyDecl, FunctionCall, Module, Import, FuncType,
NullLiteral, AddressOf, BaseType, StructLiteral, Return,
Argument, InlineContext, Scope, CoverDecl
Argument, InlineContext, Scope, CoverDecl, StringLiteral

import tinker/[Resolver, Response, Trail, Errors]
import structs/ArrayList

// for built-ins
import net/DNS, os/Time, rock/RockVersion, rock/frontend/Target

VariableAccess: class extends Expression {

_warned := false
Expand Down Expand Up @@ -135,6 +138,16 @@ VariableAccess: class extends Expression {
"%s is of type %s" printfln(name, getType() ? getType() toString() : "(nil)")
}

// resolve built-ins first
builtin := getBuiltin(name)
if (builtin) {
if(!trail peek() replace(this, builtin)) {
res throwError(CouldntReplace new(token, this, builtin, trail))
}
res wholeAgain(this, "builtin replaced")
return Response OK
}

trail onOuter(FunctionDecl, |fDecl|
if(fDecl isStatic()) _staticFunc = fDecl
)
Expand Down Expand Up @@ -410,6 +423,21 @@ VariableAccess: class extends Expression {

}

getBuiltin: func (name: String) -> Expression {
match name {
case "__BUILD_DATETIME__" =>
StringLiteral new(Time dateTime(), token)
case "__BUILD_TARGET__" =>
StringLiteral new(Target toString(), token)
case "__BUILD_ROCK_VERSION__" =>
StringLiteral new(RockVersion getName(), token)
case "__BUILD_HOSTNAME__" =>
StringLiteral new(DNS hostname(), token)
case =>
null
}
}

getRef: func -> Declaration { ref }

getType: func -> Type {
Expand Down

0 comments on commit 9c36639

Please sign in to comment.