예제 #1
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
void VM::PrintUnhandledError(Thread *const thread)
{
	Value &error = thread->currentError;
	PrintInternal(stderr, L"Unhandled error: %ls: ", error.type->fullName);

	String *message = nullptr;
	// If the member exists and is a readable instance property,
	// we can actually try to invoke the 'message' getter!
	Member *msgMember = error.type->FindMember(strings->members.message, nullptr);
	if (msgMember && !msgMember->IsStatic() && msgMember->IsProperty())
	{
		Property *msgProp = static_cast<Property*>(msgMember);
		if (msgProp->getter != nullptr)
		{
			thread->Push(&error);

			Value result;
			int r = thread->InvokeMethod(msgProp->getter, 0, &result);
			if (r == OVUM_SUCCESS && result.type == types.String)
				message = result.v.string;
		}
	}
	if (message == nullptr)
		message = error.v.error->message;
	if (message != nullptr)
		PrintErrLn(message);

	if (error.v.error->stackTrace)
		PrintErrLn(error.v.error->stackTrace);
}
예제 #2
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
void VM::PrintMethodInitException(MethodInitException &e)
{
	FILE *err = stderr;

	fwprintf(err, L"An error occurred while initializing the method '");

	MethodOverload *method = e.GetMethod();
	if (method->declType)
		PrintInternal(err, L"%ls.", method->declType->fullName);
	PrintErr(method->group->name);

	PrintInternal(err, L"' from module %ls: ", method->group->declModule->GetName());
	fwprintf(err, CSTR L"\n", e.what());

	switch (e.GetFailureKind())
	{
	case MethodInitException::INCONSISTENT_STACK:
	case MethodInitException::INVALID_BRANCH_OFFSET:
	case MethodInitException::INSUFFICIENT_STACK_HEIGHT:
	case MethodInitException::STACK_HAS_REFS:
		fwprintf(err, L"Instruction index: %d\n", e.GetInstructionIndex());
		break;
	case MethodInitException::INACCESSIBLE_MEMBER:
	case MethodInitException::FIELD_STATIC_MISMATCH:
		fwprintf(err, L"Member: ");
		{
			Member *member = e.GetMember();
			if (member->declType)
				PrintInternal(err, L"%ls.", member->declType->fullName);
			PrintInternal(err, L"%ls\n", member->name);
		}
		break;
	case MethodInitException::UNRESOLVED_TOKEN:
		fwprintf(err, L"Token: %08X\n", e.GetToken());
		break;
	case MethodInitException::NO_MATCHING_OVERLOAD:
		fwprintf(err, L"Method: '");
		{
			Method *method = e.GetMethodGroup();
			if (method->declType)
				PrintInternal(err, L"%ls.", method->declType->fullName);
			PrintErr(method->name);
			PrintInternal(err, L"' from module %ls\n", method->declModule->GetName());
		}
		fwprintf(err, L"Argument count: %u\n", e.GetArgumentCount());
		break;
	case MethodInitException::INACCESSIBLE_TYPE:
	case MethodInitException::TYPE_NOT_CONSTRUCTIBLE:
		PrintInternal(err, L"Type: '%ls' ", e.GetType()->fullName);
		PrintInternal(err, L"from module %ls\n", e.GetType()->module->GetName());
		break;
	}
}
예제 #3
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
int VM::LoadModules(VMStartParams &params)
{
	try
	{
		// Set up some stuff first
		this->startupPath = Box<PathName>(new PathName(params.startupFile));
		this->startupPath->RemoveFileName();

		this->startupPathLib = Box<PathName>(new PathName(*this->startupPath));
		this->startupPathLib->Join(OVUM_PATH("lib"));

		this->modulePath = Box<PathName>(new PathName(params.modulePath));

		// And now we can start opening modules! Hurrah!

		PathName startupFile(params.startupFile, std::nothrow);
		if (!startupFile.IsValid())
			return OVUM_ERROR_NO_MEMORY;

		PartiallyOpenedModulesList partiallyOpenedModules;
		this->startupModule = Module::Open(
			this,
			startupFile,
			nullptr,
			partiallyOpenedModules
		);
	}
	catch (ModuleLoadException &e)
	{
		const PathName &fileName = e.GetFileName();
		if (fileName.GetLength() > 0)
			fwprintf(stderr, L"Error loading module '" OVUM_PATHNWF L"': " CSTR L"\n", fileName.GetDataPointer(), e.what());
		else
			fwprintf(stderr, L"Error loading module: " CSTR L"\n", e.what());
		return OVUM_ERROR_MODULE_LOAD;
	}
	catch (std::bad_alloc&)
	{
		return OVUM_ERROR_NO_MEMORY;
	}

	size_t stdTypeCount = standardTypeCollection->GetCount();
	for (size_t i = 0; i < stdTypeCount; i++)
	{
		StandardTypeInfo type;
		standardTypeCollection->GetByIndex(i, type);
		if (this->types.*(type.member) == nullptr)	
		{
			PrintInternal(stderr, L"Startup error: standard type not loaded: %ls\n", type.name);
			return OVUM_ERROR_MODULE_LOAD;
		}
	}

	RETURN_SUCCESS;
}
예제 #4
0
/**
  Prints a formatted unicode string to the default console.

  @param  Fmt        Format string
  @param  ...        Variable argument list for format string.

  @return Length of string printed to the console.

**/
UINTN
ConsolePrint (
  IN CHAR16   *Fmt,
  ...
  )
{
  VA_LIST Args;

  VA_START (Args, Fmt);
  return PrintInternal ((UINTN) -1, (UINTN) -1, gST->ConOut, Fmt, Args);
}
예제 #5
0
/**
  Prints a formatted unicode string to the default console, at
  the supplied cursor position.

  @param  Column     The cursor position to print the string at.
  @param  Row        The cursor position to print the string at.
  @param  Fmt        Format string.
  @param  ...        Variable argument list for format string.

  @return Length of string printed to the console

**/
UINTN
PrintAt (
  IN UINTN     Column,
  IN UINTN     Row,
  IN CHAR16    *Fmt,
  ...
  )
{
  VA_LIST Args;

  VA_START (Args, Fmt);
  return PrintInternal (Column, Row, gST->ConOut, Fmt, Args);
}
예제 #6
0
/**
  Prints a formatted unicode string to the default console, at
  the supplied cursor position.

  @param  Width      Width of String to be printed.
  @param  Column     The cursor position to print the string at.
  @param  Row        The cursor position to print the string at.
  @param  Fmt        Format string.
  @param  ...        Variable argument list for format string.

  @return Length of string printed to the console

**/
UINTN
EFIAPI
PrintAt (
  IN UINTN     Width,
  IN UINTN     Column,
  IN UINTN     Row,
  IN CHAR16    *Fmt,
  ...
  )
{
  VA_LIST Args;
  UINTN   LengthOfPrinted;

  VA_START (Args, Fmt);
  LengthOfPrinted = PrintInternal (Width, Column, Row, gST->ConOut, Fmt, Args);
  VA_END (Args);
  return LengthOfPrinted;
}
예제 #7
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
void VM::PrintErrLn(String *str)
{
	PrintInternal(stderr, L"%ls\n", str);
}
예제 #8
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
void VM::PrintfErr(const wchar_t *format, String *str)
{
	PrintInternal(stderr, format, str);
}
예제 #9
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
void VM::PrintLn(String *str)
{
	PrintInternal(stdout, L"%ls\n", str);
}
예제 #10
0
파일: vm.cpp 프로젝트: osprey-lang/ovum
void VM::Printf(const wchar_t *format, String *str)
{
	PrintInternal(stdout, format, str);
}
예제 #11
0
파일: main.c 프로젝트: creationix/luvmonkey
static JSBool
PrintErr(JSContext *cx, unsigned argc, jsval *vp)
{
  return PrintInternal(cx, argc, vp, stderr);
}
예제 #12
0
		void AstNode::Print(ostream& o, int indentation, AstNode::WeakPtr _parent)
		{
			ASSERT(_parent.expired() || parent.lock() == _parent.lock());
			PrintInternal(o, indentation);
		}