Skip to content

Commit

Permalink
Work on System.Convert (#459)
Browse files Browse the repository at this point in the history
* Work on System.Convert

Implementation of NativeToInt64 and NativeToDouble.

Signed-off-by: Christophe Gerbier <[email protected]>

* Adjust managed stack frame for some boards

Signed-off-by: Christophe Gerbier <[email protected]>
  • Loading branch information
Christophe Gerbier authored and josesimoes committed Aug 31, 2017
1 parent d979bd2 commit 3d07ab2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/CLR/CorLib/corlib_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,8 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_corlib_native_System_Console::OutNative___STATIC__VOID__STRING__BOOLEAN,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_corlib_native_System_Convert::NativeToInt64___STATIC__I8__STRING__BOOLEAN__I8__I8__I4,
Library_corlib_native_System_Convert::NativeToDouble___STATIC__R8__STRING,
NULL,
NULL,
NULL,
Expand Down Expand Up @@ -901,6 +900,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib =
{
"mscorlib",
0x964C8465,
0x7D73728E,
method_lookup
};

6 changes: 6 additions & 0 deletions src/CLR/CorLib/corlib_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef _CORLIB_NATIVE_H_
#define _CORLIB_NATIVE_H_

#include <nanoCLR_Interop.h>
#include <nanoCLR_Runtime.h>
#include <nanoCLR_Checks.h>

struct Library_corlib_native_System_Object
{
NANOCLR_NATIVE_DECLARE(Equals___BOOLEAN__OBJECT);
Expand Down Expand Up @@ -313,6 +317,8 @@ struct Library_corlib_native_System_Console

struct Library_corlib_native_System_Convert
{
NANOCLR_NATIVE_DECLARE(NativeToInt64___STATIC__I8__STRING__BOOLEAN__I8__I8__I4);
NANOCLR_NATIVE_DECLARE(NativeToDouble___STATIC__R8__STRING);
NANOCLR_NATIVE_DECLARE(ToBase64String___STATIC__STRING__SZARRAY_U1__I4__I4__BOOLEAN);
NANOCLR_NATIVE_DECLARE(FromBase64CharArray___STATIC__SZARRAY_U1__SZARRAY_CHAR__I4);

Expand Down
32 changes: 31 additions & 1 deletion src/CLR/CorLib/corlib_native_System_Convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,38 @@
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#include "CorLib.h"
#include "corlib_native.h"

HRESULT Library_corlib_native_System_Convert::NativeToInt64___STATIC__I8__STRING__BOOLEAN__I8__I8__I4( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();
{
CLR_INT64 _result = 0;
CLR_INT64 _zero = 0;

const char * _string = stack.Arg0().RecoverString();
bool _signed = (bool)stack.Arg1().NumericByRef().u1;
long long _minValue = stack.Arg2().NumericByRef().s8;
long long _maxValue = stack.Arg3().NumericByRef().s8;
signed int radix = stack.Arg4().NumericByRef().s4;

_result = _signed ? strtoll(_string, nullptr, radix) : (long long) strtoull(_string, nullptr, radix);

stack.SetResult_I8 ((_result > _maxValue || _result < _minValue) ? _zero : _result);
}
NANOCLR_NOCLEANUP();
}

HRESULT Library_corlib_native_System_Convert::NativeToDouble___STATIC__R8__STRING( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();
{
const char * _string = stack.Arg0().RecoverString();

stack.SetResult_R8 (strtod(_string, nullptr));
}
NANOCLR_NOCLEANUP();
}

HRESULT Library_corlib_native_System_Convert::ToBase64String___STATIC__STRING__SZARRAY_U1__I4__I4__BOOLEAN( CLR_RT_StackFrame& stack )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAG
# the size of the CLR managed heap is defined here
###################################################
set_property(TARGET ${NANOBOOTER_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x0")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x29900")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x29600")


set(NANOBOOTER_HEX_FILE ${PROJECT_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.hex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAG
# the size of the CLR managed heap is defined here
###################################################
set_property(TARGET ${NANOBOOTER_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x0")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x199E0")
set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS ",--library-path=${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/common,--defsym=__main_stack_size__=0x400,--defsym=__process_stack_size__=0x400,--defsym=__clr_managed_heap_size__=0x196E0")


set(NANOBOOTER_HEX_FILE ${PROJECT_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.hex)
Expand Down

0 comments on commit 3d07ab2

Please sign in to comment.