Skip to content

Commit

Permalink
Corrected SAMPLE function throw invalid sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Antiloope committed Dec 1, 2020
1 parent e82b123 commit 99bf693
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/interpreter/languagedefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ void CS::Functions::sample() {

LiteralValue* argValue = ctx->getArgumentValue("fileName");
if( argValue->getDataTypeId() != DataTypesId::String )
throw new SemanticException("Invalid argument for sample function. Expected a file name");
throw SemanticException("Invalid argument for sample function. Expected a file name");

string fileName = *(string*)argValue->getValue();

AudioFile<float> a;
a.load(fileName);
if( !a.load(fileName) )
throw SemanticException("File not found or invalid file format.");

ctx->newAudioFile(fileName,a);

Sample tmp(fileName);
Expand Down
20 changes: 16 additions & 4 deletions src/interpreter/values/executionlinkedvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ LiteralValue* ExecutionLinkedValue::getValue() const {
unique_ptr<LiteralValue> intermediateValue = nullptr;
if( _name == get<0>(_methodsList.front()) )
{
if( !Context::getInstance()->executeFunction(_name,get<1>(_methodsList.front())->getValue()) )
throw SemanticException("Unknown function name", this->getCodeReference());
try {
if( !Context::getInstance()->executeFunction(_name,get<1>(_methodsList.front())->getValue()) )
throw SemanticException("Unknown function name", this->getCodeReference());
}
catch(const SemanticException& e)
{
throw SemanticException(e.what(),this->getCodeReference());
}
intermediateValue = unique_ptr<LiteralValue>(Context::getInstance()->getReturnValue());
}
else
Expand All @@ -107,8 +113,14 @@ LiteralValue* ExecutionLinkedValue::getValue() const {

if( firstMethod )
{
if( !Context::getInstance()->executeMethod(_name,get<0>(method),args.get()) )
throw SyntaxException("Unknown method name",get<1>(method)->getCodeReference());
try {
if( !Context::getInstance()->executeMethod(_name,get<0>(method),args.get()) )
throw SyntaxException("Unknown method name",get<1>(method)->getCodeReference());
}
catch(const SemanticException& e)
{
throw SemanticException(e.what(),get<1>(method)->getCodeReference());
}
firstMethod = false;
intermediateValue = unique_ptr<LiteralValue>(Context::getInstance()->getReturnValue());
}
Expand Down

0 comments on commit 99bf693

Please sign in to comment.