From 9c82cbeddf1b03cc99660a867de8720d1d174b9c Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 9 Mar 2015 19:22:43 +0100 Subject: [PATCH] Global variable "now" (alias for block.timestamp). --- ExpressionCompiler.cpp | 12 +++++++++++- GlobalContext.cpp | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index b02aecf5f..d2457e676 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -825,10 +825,20 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier) Declaration const* declaration = _identifier.getReferencedDeclaration(); if (MagicVariableDeclaration const* magicVar = dynamic_cast(declaration)) { - if (magicVar->getType()->getCategory() == Type::Category::Contract) + switch (magicVar->getType()->getCategory()) + { + case Type::Category::Contract: // "this" or "super" if (!dynamic_cast(*magicVar->getType()).isSuper()) m_context << eth::Instruction::ADDRESS; + break; + case Type::Category::Integer: + // "now" + m_context << eth::Instruction::TIMESTAMP; + break; + default: + break; + } } else if (FunctionDefinition const* functionDef = dynamic_cast(declaration)) m_context << m_context.getVirtualFunctionEntryLabel(*functionDef).pushTag(); diff --git a/GlobalContext.cpp b/GlobalContext.cpp index 60de5105f..411e99abb 100644 --- a/GlobalContext.cpp +++ b/GlobalContext.cpp @@ -37,6 +37,7 @@ GlobalContext::GlobalContext(): m_magicVariables(vector>{make_shared("block", make_shared(MagicType::Kind::Block)), make_shared("msg", make_shared(MagicType::Kind::Message)), make_shared("tx", make_shared(MagicType::Kind::Transaction)), + make_shared("now", make_shared(256)), make_shared("suicide", make_shared(strings{"address"}, strings{}, FunctionType::Location::Suicide)), make_shared("sha3",