Implement 64-Bit System Clock Runtime & Secured Integer Parser#39
Open
LucasChen1108 wants to merge 6 commits intosource-academy:masterfrom
Open
Implement 64-Bit System Clock Runtime & Secured Integer Parser#39LucasChen1108 wants to merge 6 commits intosource-academy:masterfrom
LucasChen1108 wants to merge 6 commits intosource-academy:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the parse_int and runtime primitives for the Sinter VM. It introduces a cross-platform mechanism to retrieve the current time in milliseconds and adds a 1MB heap allocation for the native runner. Feedback was provided regarding the missing return value check for malloc in the runner, which could lead to a segmentation fault, and the lack of ERANGE error handling when using strtol in the parse_int implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement 64-Bit System Clock Runtime & Secured Integer Parser
Overview
This pull request addresses two unimplemented stubs within Sinter's default core specification: returning exact VM uptimes via
runtime(), and decoding strings securely into integers viaparse_int().The
runtime()logic has been adapted to map cleanly with EV3/POSIX<time.h>standards, and a separate web-compatible implementation has been added tolib.cfor the Sinter WebAssembly demo.What's Changed
lib.c): Addedget_time_msimplementation for the WebAssembly target, enablingruntime()to function correctly in the browser-based Sinter demo.clock_gettime(CLOCK_MONOTONIC)and bridges hardware execution time accurately intosivmfn_primitives.sinter_get_time_msto auint64_tinterface to handle long-running programs safely.runtime()evaluates whether elapsed uptime exceedsNANBOX_INTMAXlimits. If the timestamp overflows, it safely falls back toNANBOX_OFFLOAT, preventing crashes on long-running robots.sivmfn_prim_unimplstubs forparse_intandruntimein the primitives dispatch table (sivmfn_primitives[]) with the new implementations, activating both functions in the VM for the first time.parse_intParser:primitives.cleveragessistrobj_tocharptrto extract chars from internal C string structs directly.< 2or> 36)!isfinite(fv) || truncf(fv) != fvendptr == strfromstrtolto ensure unresolved strings returnNANBOX_CANONICAL_NANType of Patch
Test Plan
Native EV3/Linux:
Compiled via GCC and tested with:
Execution generated
0faults locally.Web Demo:
Tested on the browser-based Sinter demo with the following Source program:
Successfully returns correct parsed values and elapsed time in milliseconds.