mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added MSVC build support, likely broke tests
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,6 +1,4 @@
|
|||||||
#Editor generated files
|
#Editor generated files
|
||||||
*.sln
|
|
||||||
*.vcproj
|
|
||||||
*.suo
|
*.suo
|
||||||
*.ncb
|
*.ncb
|
||||||
*.user
|
*.user
|
||||||
@@ -13,7 +11,9 @@ Out/
|
|||||||
release/
|
release/
|
||||||
debug/
|
debug/
|
||||||
out/
|
out/
|
||||||
|
bin/
|
||||||
.cache/
|
.cache/
|
||||||
|
.vs/
|
||||||
|
|
||||||
#Project generated files
|
#Project generated files
|
||||||
*.db
|
*.db
|
||||||
@@ -22,9 +22,10 @@ out/
|
|||||||
*.exe
|
*.exe
|
||||||
*.meta
|
*.meta
|
||||||
*.log
|
*.log
|
||||||
out
|
*.out
|
||||||
*.stackdump
|
*.stackdump
|
||||||
*.tb
|
*.tb
|
||||||
|
*.filters
|
||||||
|
|
||||||
#Shell files
|
#Shell files
|
||||||
*.bat
|
*.bat
|
||||||
|
|||||||
134
Repl.vcxproj
Normal file
134
Repl.vcxproj
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{97F823E5-3AB8-47EF-B142-C15DD7CADF76}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<IgnoreImportLibrary>false</IgnoreImportLibrary>
|
||||||
|
<OutDir>$(SolutionDir)bin\$(Configuration)</OutDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<TargetMachine>MachineX86</TargetMachine>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<TargetMachine>MachineX86</TargetMachine>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies>Toy.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(SolutionDir)bin\$(Configuration)</AdditionalLibraryDirectories>
|
||||||
|
</Link>
|
||||||
|
<ClCompile>
|
||||||
|
<AdditionalIncludeDirectories>C:\Users\kayne\Desktop\Toy\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="repl\lib_about.c" />
|
||||||
|
<ClCompile Include="repl\lib_compound.c" />
|
||||||
|
<ClCompile Include="repl\lib_runner.c" />
|
||||||
|
<ClCompile Include="repl\lib_standard.c" />
|
||||||
|
<ClCompile Include="repl\lib_timer.c" />
|
||||||
|
<ClCompile Include="repl\repl_main.c" />
|
||||||
|
<ClCompile Include="repl\repl_tools.c" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="repl\lib_about.h" />
|
||||||
|
<ClInclude Include="repl\lib_compound.h" />
|
||||||
|
<ClInclude Include="repl\lib_runner.h" />
|
||||||
|
<ClInclude Include="repl\lib_standard.h" />
|
||||||
|
<ClInclude Include="repl\lib_timer.h" />
|
||||||
|
<ClInclude Include="repl\repl_tools.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
147
Toy.vcxproj
Normal file
147
Toy.vcxproj
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{26360002-CC2A-469A-9B28-BA0C1AF41657}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<OutDir>$(SolutionDir)bin\$(Configuration)</OutDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;TOY_EXPORTS;TOY_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<TargetMachine>MachineX86</TargetMachine>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TOY_EXPORTS;TOY_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<TargetMachine>MachineX86</TargetMachine>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PreprocessorDefinitions>TOY_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="source\toy_ast_node.c" />
|
||||||
|
<ClCompile Include="source\toy_builtin.c" />
|
||||||
|
<ClCompile Include="source\toy_common.c" />
|
||||||
|
<ClCompile Include="source\toy_compiler.c" />
|
||||||
|
<ClCompile Include="source\toy_interpreter.c" />
|
||||||
|
<ClCompile Include="source\toy_keyword_types.c" />
|
||||||
|
<ClCompile Include="source\toy_lexer.c" />
|
||||||
|
<ClCompile Include="source\toy_literal.c" />
|
||||||
|
<ClCompile Include="source\toy_literal_array.c" />
|
||||||
|
<ClCompile Include="source\toy_literal_dictionary.c" />
|
||||||
|
<ClCompile Include="source\toy_memory.c" />
|
||||||
|
<ClCompile Include="source\toy_parser.c" />
|
||||||
|
<ClCompile Include="source\toy_refstring.c" />
|
||||||
|
<ClCompile Include="source\toy_scope.c" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="source\toy_ast_node.h" />
|
||||||
|
<ClInclude Include="source\toy_builtin.h" />
|
||||||
|
<ClInclude Include="source\toy_common.h" />
|
||||||
|
<ClInclude Include="source\toy_compiler.h" />
|
||||||
|
<ClInclude Include="source\toy_console_colors.h" />
|
||||||
|
<ClInclude Include="source\toy_interpreter.h" />
|
||||||
|
<ClInclude Include="source\toy_keyword_types.h" />
|
||||||
|
<ClInclude Include="source\toy_lexer.h" />
|
||||||
|
<ClInclude Include="source\toy_literal.h" />
|
||||||
|
<ClInclude Include="source\toy_literal_array.h" />
|
||||||
|
<ClInclude Include="source\toy_literal_dictionary.h" />
|
||||||
|
<ClInclude Include="source\toy_memory.h" />
|
||||||
|
<ClInclude Include="source\toy_opcodes.h" />
|
||||||
|
<ClInclude Include="source\toy_parser.h" />
|
||||||
|
<ClInclude Include="source\toy_refstring.h" />
|
||||||
|
<ClInclude Include="source\toy_scope.h" />
|
||||||
|
<ClInclude Include="source\toy_token_types.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
44
Toylang.sln
Normal file
44
Toylang.sln
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.4.33213.308
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Toy", "Toy.vcxproj", "{26360002-CC2A-469A-9B28-BA0C1AF41657}"
|
||||||
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Repl", "Repl.vcxproj", "{97F823E5-3AB8-47EF-B142-C15DD7CADF76}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657} = {26360002-CC2A-469A-9B28-BA0C1AF41657}
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Release|x64.Build.0 = Release|x64
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{26360002-CC2A-469A-9B28-BA0C1AF41657}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Release|x64.Build.0 = Release|x64
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{97F823E5-3AB8-47EF-B142-C15DD7CADF76}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {7089F1AD-8EC0-4F27-AFD1-5FD43D91AABC}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -83,7 +83,7 @@ static int nativeConcat(Toy_Interpreter* interpreter, Toy_LiteralArray* argument
|
|||||||
}
|
}
|
||||||
|
|
||||||
//get the combined length for the new string
|
//get the combined length for the new string
|
||||||
int length = TOY_AS_STRING(selfLiteral)->length + TOY_AS_STRING(otherLiteral)->length + 1;
|
size_t length = TOY_AS_STRING(selfLiteral)->length + TOY_AS_STRING(otherLiteral)->length + 1;
|
||||||
|
|
||||||
if (length > TOY_MAX_STRING_LENGTH) {
|
if (length > TOY_MAX_STRING_LENGTH) {
|
||||||
interpreter->errorOutput("Can't concatenate these strings, result is too long (error found in _concat)\n");
|
interpreter->errorOutput("Can't concatenate these strings, result is too long (error found in _concat)\n");
|
||||||
@@ -1136,8 +1136,8 @@ static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
|
|||||||
Toy_RefString* selfRefString = TOY_AS_STRING(selfLiteral);
|
Toy_RefString* selfRefString = TOY_AS_STRING(selfLiteral);
|
||||||
|
|
||||||
//allocate space for the new string
|
//allocate space for the new string
|
||||||
int bufferBegin = 0;
|
size_t bufferBegin = 0;
|
||||||
int bufferEnd = Toy_lengthRefString(selfRefString);
|
size_t bufferEnd = Toy_lengthRefString(selfRefString);
|
||||||
|
|
||||||
//for each character in self, check it against each character in trimChars - on a fail, go to end
|
//for each character in self, check it against each character in trimChars - on a fail, go to end
|
||||||
for (int i = 0; i < (int)Toy_lengthRefString(selfRefString); i++) {
|
for (int i = 0; i < (int)Toy_lengthRefString(selfRefString); i++) {
|
||||||
@@ -1163,7 +1163,7 @@ static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//again, from the back
|
//again, from the back
|
||||||
for (int i = Toy_lengthRefString(selfRefString); i >= 0; i--) {
|
for (int i = (int)Toy_lengthRefString(selfRefString); i >= 0; i--) {
|
||||||
int trimIndex = 0;
|
int trimIndex = 0;
|
||||||
|
|
||||||
while (trimIndex < (int)Toy_lengthRefString(trimCharsRefString)) {
|
while (trimIndex < (int)Toy_lengthRefString(trimCharsRefString)) {
|
||||||
@@ -1247,8 +1247,8 @@ static int nativeTrimBegin(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
|
|||||||
Toy_RefString* selfRefString = TOY_AS_STRING(selfLiteral);
|
Toy_RefString* selfRefString = TOY_AS_STRING(selfLiteral);
|
||||||
|
|
||||||
//allocate space for the new string
|
//allocate space for the new string
|
||||||
int bufferBegin = 0;
|
size_t bufferBegin = 0;
|
||||||
int bufferEnd = Toy_lengthRefString(selfRefString);
|
size_t bufferEnd = Toy_lengthRefString(selfRefString);
|
||||||
|
|
||||||
//for each character in self, check it against each character in trimChars - on a fail, go to end
|
//for each character in self, check it against each character in trimChars - on a fail, go to end
|
||||||
for (int i = 0; i < (int)Toy_lengthRefString(selfRefString); i++) {
|
for (int i = 0; i < (int)Toy_lengthRefString(selfRefString); i++) {
|
||||||
@@ -1335,8 +1335,8 @@ static int nativeTrimEnd(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
|
|||||||
Toy_RefString* selfRefString = TOY_AS_STRING(selfLiteral);
|
Toy_RefString* selfRefString = TOY_AS_STRING(selfLiteral);
|
||||||
|
|
||||||
//allocate space for the new string
|
//allocate space for the new string
|
||||||
int bufferBegin = 0;
|
size_t bufferBegin = 0;
|
||||||
int bufferEnd = Toy_lengthRefString(selfRefString);
|
size_t bufferEnd = Toy_lengthRefString(selfRefString);
|
||||||
|
|
||||||
//again, from the back
|
//again, from the back
|
||||||
for (int i = (int)Toy_lengthRefString(selfRefString); i >= 0; i--) {
|
for (int i = (int)Toy_lengthRefString(selfRefString); i >= 0; i--) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ static int nativeLoadScript(Toy_Interpreter* interpreter, Toy_LiteralArray* argu
|
|||||||
|
|
||||||
//use raw types - easier
|
//use raw types - easier
|
||||||
const char* filePath = Toy_toCString(TOY_AS_STRING(filePathLiteral));
|
const char* filePath = Toy_toCString(TOY_AS_STRING(filePathLiteral));
|
||||||
int filePathLength = Toy_lengthRefString(TOY_AS_STRING(filePathLiteral));
|
size_t filePathLength = Toy_lengthRefString(TOY_AS_STRING(filePathLiteral));
|
||||||
|
|
||||||
//load and compile the bytecode
|
//load and compile the bytecode
|
||||||
size_t fileSize = 0;
|
size_t fileSize = 0;
|
||||||
@@ -138,7 +138,7 @@ static int nativeLoadScriptBytecode(Toy_Interpreter* interpreter, Toy_LiteralArr
|
|||||||
|
|
||||||
//get the final real file path (concat) TODO: move this concat to refstring library
|
//get the final real file path (concat) TODO: move this concat to refstring library
|
||||||
Toy_RefString* realDrive = Toy_copyRefString(TOY_AS_STRING(realDriveLiteral));
|
Toy_RefString* realDrive = Toy_copyRefString(TOY_AS_STRING(realDriveLiteral));
|
||||||
int realLength = Toy_lengthRefString(realDrive) + Toy_lengthRefString(path);
|
size_t realLength = Toy_lengthRefString(realDrive) + Toy_lengthRefString(path);
|
||||||
|
|
||||||
char* filePath = TOY_ALLOCATE(char, realLength + 1); //+1 for null
|
char* filePath = TOY_ALLOCATE(char, realLength + 1); //+1 for null
|
||||||
snprintf(filePath, realLength, "%s%s", Toy_toCString(realDrive), Toy_toCString(path));
|
snprintf(filePath, realLength, "%s%s", Toy_toCString(realDrive), Toy_toCString(path));
|
||||||
@@ -159,7 +159,7 @@ static int nativeLoadScriptBytecode(Toy_Interpreter* interpreter, Toy_LiteralArr
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check for break-out attempts
|
//check for break-out attempts
|
||||||
for (int i = 0; i < realLength - 1; i++) {
|
for (size_t i = 0; i < realLength - 1; i++) {
|
||||||
if (filePath[i] == '.' && filePath[i + 1] == '.') {
|
if (filePath[i] == '.' && filePath[i + 1] == '.') {
|
||||||
interpreter->errorOutput("Parent directory access not allowed\n");
|
interpreter->errorOutput("Parent directory access not allowed\n");
|
||||||
TOY_FREE_ARRAY(char, filePath, realLength);
|
TOY_FREE_ARRAY(char, filePath, realLength);
|
||||||
@@ -617,7 +617,7 @@ Toy_Literal Toy_getFilePathLiteral(Toy_Interpreter* interpreter, Toy_Literal* dr
|
|||||||
|
|
||||||
//get the final real file path (concat) TODO: move this concat to refstring library
|
//get the final real file path (concat) TODO: move this concat to refstring library
|
||||||
Toy_RefString* realDrive = Toy_copyRefString(TOY_AS_STRING(realDriveLiteral));
|
Toy_RefString* realDrive = Toy_copyRefString(TOY_AS_STRING(realDriveLiteral));
|
||||||
int realLength = Toy_lengthRefString(realDrive) + Toy_lengthRefString(path);
|
size_t realLength = Toy_lengthRefString(realDrive) + Toy_lengthRefString(path);
|
||||||
|
|
||||||
char* filePath = TOY_ALLOCATE(char, realLength + 1); //+1 for null
|
char* filePath = TOY_ALLOCATE(char, realLength + 1); //+1 for null
|
||||||
snprintf(filePath, realLength, "%s%s", Toy_toCString(realDrive), Toy_toCString(path));
|
snprintf(filePath, realLength, "%s%s", Toy_toCString(realDrive), Toy_toCString(path));
|
||||||
@@ -630,7 +630,7 @@ Toy_Literal Toy_getFilePathLiteral(Toy_Interpreter* interpreter, Toy_Literal* dr
|
|||||||
Toy_deleteRefString(drivePath);
|
Toy_deleteRefString(drivePath);
|
||||||
|
|
||||||
//check for break-out attempts
|
//check for break-out attempts
|
||||||
for (int i = 0; i < realLength - 1; i++) {
|
for (size_t i = 0; i < realLength - 1; i++) {
|
||||||
if (filePath[i] == '.' && filePath[i + 1] == '.') {
|
if (filePath[i] == '.' && filePath[i + 1] == '.') {
|
||||||
interpreter->errorOutput("Parent directory access not allowed\n");
|
interpreter->errorOutput("Parent directory access not allowed\n");
|
||||||
TOY_FREE_ARRAY(char, filePath, realLength + 1);
|
TOY_FREE_ARRAY(char, filePath, realLength + 1);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include "toy_memory.h"
|
#include "toy_memory.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
static int nativeClock(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeClock(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
//no arguments
|
//no arguments
|
||||||
@@ -18,7 +17,7 @@ static int nativeClock(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
|
|||||||
char* timestr = asctime(timeinfo);
|
char* timestr = asctime(timeinfo);
|
||||||
|
|
||||||
//push to the stack
|
//push to the stack
|
||||||
int len = strlen(timestr) - 1; //-1 for the newline
|
size_t len = strlen(timestr) - 1; //-1 for the newline
|
||||||
Toy_Literal timeLiteral = TOY_TO_STRING_LITERAL(Toy_createRefStringLength(timestr, len));
|
Toy_Literal timeLiteral = TOY_TO_STRING_LITERAL(Toy_createRefStringLength(timestr, len));
|
||||||
|
|
||||||
//push to the stack
|
//push to the stack
|
||||||
@@ -32,7 +31,7 @@ static int nativeClock(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
|
|||||||
|
|
||||||
//call the hook
|
//call the hook
|
||||||
typedef struct Natives {
|
typedef struct Natives {
|
||||||
char* name;
|
const char* name;
|
||||||
Toy_NativeFn fn;
|
Toy_NativeFn fn;
|
||||||
} Natives;
|
} Natives;
|
||||||
|
|
||||||
|
|||||||
122
repl/lib_timer.c
122
repl/lib_timer.c
@@ -4,45 +4,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
//GOD DAMN IT: https://stackoverflow.com/questions/15846762/timeval-subtract-explanation
|
//natives
|
||||||
static int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) {
|
|
||||||
//normallize
|
|
||||||
if (x->tv_usec > 999999) {
|
|
||||||
x->tv_sec += x->tv_usec / 1000000;
|
|
||||||
x->tv_usec %= 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y->tv_usec > 999999) {
|
|
||||||
y->tv_sec += y->tv_usec / 1000000;
|
|
||||||
y->tv_usec %= 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
//calc
|
|
||||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
|
||||||
|
|
||||||
if ((result->tv_usec = x->tv_usec - y->tv_usec) < 0) {
|
|
||||||
if (result->tv_sec != 0) { //only works far from 0
|
|
||||||
result->tv_usec += 1000000;
|
|
||||||
result->tv_sec--; // borrow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result->tv_sec < 0 || (result->tv_sec == 0 && result->tv_usec < 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//god damn it
|
|
||||||
static struct timeval* diff(struct timeval* lhs, struct timeval* rhs) {
|
|
||||||
struct timeval* d = TOY_ALLOCATE(struct timeval, 1);
|
|
||||||
|
|
||||||
//I gave up, copied from SO
|
|
||||||
timeval_subtract(d, rhs, lhs);
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
//callbacks
|
|
||||||
static int nativeStartTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeStartTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
//no arguments
|
//no arguments
|
||||||
if (arguments->count != 0) {
|
if (arguments->count != 0) {
|
||||||
@@ -50,15 +13,15 @@ static int nativeStartTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* argu
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the timeinfo from C
|
//get the time from C (this is dumb)
|
||||||
struct timeval* timeinfo = TOY_ALLOCATE(struct timeval, 1);
|
clock_t* ptr = TOY_ALLOCATE(clock_t, 1);
|
||||||
gettimeofday(timeinfo, NULL);
|
*ptr = clock();
|
||||||
|
|
||||||
//wrap in an opaque literal for Toy
|
//wrap in an opaque literal for Toy
|
||||||
Toy_Literal timeLiteral = TOY_TO_OPAQUE_LITERAL(timeinfo, -1);
|
Toy_Literal timerLiteral = TOY_TO_OPAQUE_LITERAL(ptr, -1); //TODO: sort out the tags
|
||||||
Toy_pushLiteralArray(&interpreter->stack, timeLiteral);
|
Toy_pushLiteralArray(&interpreter->stack, timerLiteral);
|
||||||
|
|
||||||
Toy_freeLiteral(timeLiteral);
|
Toy_freeLiteral(timerLiteral);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -70,33 +33,33 @@ static int nativeStopTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* argum
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the timeinfo from C
|
clock_t stop = clock();
|
||||||
struct timeval timerStop;
|
|
||||||
gettimeofday(&timerStop, NULL);
|
|
||||||
|
|
||||||
//unwrap the opaque literal
|
//unwrap the opaque literal
|
||||||
Toy_Literal timeLiteral = Toy_popLiteralArray(arguments);
|
Toy_Literal timerLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
Toy_Literal timeLiteralIdn = timeLiteral;
|
Toy_Literal timerLiteralIdn = timerLiteral;
|
||||||
if (TOY_IS_IDENTIFIER(timeLiteral) && Toy_parseIdentifierToValue(interpreter, &timeLiteral)) {
|
if (TOY_IS_IDENTIFIER(timerLiteral) && Toy_parseIdentifierToValue(interpreter, &timerLiteral)) {
|
||||||
Toy_freeLiteral(timeLiteralIdn);
|
Toy_freeLiteral(timerLiteralIdn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TOY_IS_OPAQUE(timeLiteral)) {
|
if (!TOY_IS_OPAQUE(timerLiteral)) {
|
||||||
interpreter->errorOutput("Incorrect argument type passed to _stopTimer\n");
|
interpreter->errorOutput("Incorrect argument type passed to _stopTimer\n");
|
||||||
Toy_freeLiteral(timeLiteral);
|
Toy_freeLiteral(timerLiteral);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* timerStart = TOY_AS_OPAQUE(timeLiteral);
|
clock_t* ptr = TOY_AS_OPAQUE(timerLiteral);
|
||||||
|
|
||||||
//determine the difference, and wrap it
|
//determine the difference, and wrap it
|
||||||
struct timeval* d = diff(timerStart, &timerStop);
|
clock_t* diff = TOY_ALLOCATE(clock_t, 1);
|
||||||
Toy_Literal diffLiteral = TOY_TO_OPAQUE_LITERAL(d, -1);
|
*diff = *ptr - stop;
|
||||||
|
Toy_Literal diffLiteral = TOY_TO_OPAQUE_LITERAL(diff, -1);
|
||||||
|
|
||||||
Toy_pushLiteralArray(&interpreter->stack, diffLiteral);
|
Toy_pushLiteralArray(&interpreter->stack, diffLiteral);
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
Toy_freeLiteral(timeLiteral);
|
Toy_freeLiteral(timerLiteral);
|
||||||
Toy_freeLiteral(diffLiteral);
|
Toy_freeLiteral(diffLiteral);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -137,13 +100,12 @@ static int nativeCreateTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the timeinfo from toy
|
//determine the clocks per whatever
|
||||||
struct timeval* timeinfo = TOY_ALLOCATE(struct timeval, 1);
|
clock_t* timer = TOY_ALLOCATE(clock_t, 1);
|
||||||
timeinfo->tv_sec = TOY_AS_INTEGER(secondLiteral);
|
*timer = TOY_AS_INTEGER(secondLiteral) * CLOCKS_PER_SEC + TOY_AS_INTEGER(microsecondLiteral);
|
||||||
timeinfo->tv_usec = TOY_AS_INTEGER(microsecondLiteral);
|
|
||||||
|
|
||||||
//wrap in an opaque literal for Toy
|
//wrap in an opaque literal for Toy
|
||||||
Toy_Literal timeLiteral = TOY_TO_OPAQUE_LITERAL(timeinfo, -1);
|
Toy_Literal timeLiteral = TOY_TO_OPAQUE_LITERAL(timer, -1);
|
||||||
Toy_pushLiteralArray(&interpreter->stack, timeLiteral);
|
Toy_pushLiteralArray(&interpreter->stack, timeLiteral);
|
||||||
|
|
||||||
Toy_freeLiteral(timeLiteral);
|
Toy_freeLiteral(timeLiteral);
|
||||||
@@ -174,10 +136,10 @@ static int nativeGetTimerSeconds(Toy_Interpreter* interpreter, Toy_LiteralArray*
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* timer = TOY_AS_OPAQUE(timeLiteral);
|
clock_t* timer = TOY_AS_OPAQUE(timeLiteral);
|
||||||
|
|
||||||
//create the result literal
|
//create the result literal
|
||||||
Toy_Literal result = TOY_TO_INTEGER_LITERAL(timer->tv_sec);
|
Toy_Literal result = TOY_TO_INTEGER_LITERAL(*timer / CLOCKS_PER_SEC);
|
||||||
Toy_pushLiteralArray(&interpreter->stack, result);
|
Toy_pushLiteralArray(&interpreter->stack, result);
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
@@ -208,10 +170,10 @@ static int nativeGetTimerMicroseconds(Toy_Interpreter* interpreter, Toy_LiteralA
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* timer = TOY_AS_OPAQUE(timeLiteral);
|
clock_t* timer = TOY_AS_OPAQUE(timeLiteral);
|
||||||
|
|
||||||
//create the result literal
|
//create the result literal
|
||||||
Toy_Literal result = TOY_TO_INTEGER_LITERAL(timer->tv_usec);
|
Toy_Literal result = TOY_TO_INTEGER_LITERAL(*timer % CLOCKS_PER_SEC);
|
||||||
Toy_pushLiteralArray(&interpreter->stack, result);
|
Toy_pushLiteralArray(&interpreter->stack, result);
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
@@ -249,12 +211,14 @@ static int nativeCompareTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* lhsTimer = TOY_AS_OPAQUE(lhsLiteral);
|
clock_t* lhsTimer = TOY_AS_OPAQUE(lhsLiteral);
|
||||||
struct timeval* rhsTimer = TOY_AS_OPAQUE(rhsLiteral);
|
clock_t* rhsTimer = TOY_AS_OPAQUE(rhsLiteral);
|
||||||
|
|
||||||
//determine the difference, and wrap it
|
//determine the difference, and wrap it
|
||||||
struct timeval* d = diff(lhsTimer, rhsTimer);
|
clock_t* diff = TOY_ALLOCATE(clock_t, 1);
|
||||||
Toy_Literal diffLiteral = TOY_TO_OPAQUE_LITERAL(d, -1);
|
*diff = *lhsTimer - *rhsTimer;
|
||||||
|
|
||||||
|
Toy_Literal diffLiteral = TOY_TO_OPAQUE_LITERAL(diff, -1);
|
||||||
Toy_pushLiteralArray(&interpreter->stack, diffLiteral);
|
Toy_pushLiteralArray(&interpreter->stack, diffLiteral);
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
@@ -286,20 +250,12 @@ static int nativeTimerToString(Toy_Interpreter* interpreter, Toy_LiteralArray* a
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* timer = TOY_AS_OPAQUE(timeLiteral);
|
clock_t* timer = TOY_AS_OPAQUE(timeLiteral);
|
||||||
|
|
||||||
//create the string literal
|
//create the string literal
|
||||||
Toy_Literal resultLiteral = TOY_TO_NULL_LITERAL;
|
|
||||||
if (timer->tv_sec == 0 && timer->tv_usec < 0) { //special case, for when the negative sign is encoded in the usec
|
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
snprintf(buffer, 128, "-%ld.%06ld", timer->tv_sec, -timer->tv_usec);
|
snprintf(buffer, 128, "%ld.%06ld", *timer / CLOCKS_PER_SEC, *timer % CLOCKS_PER_SEC);
|
||||||
resultLiteral = TOY_TO_STRING_LITERAL(Toy_createRefStringLength(buffer, strlen(buffer)));
|
Toy_Literal resultLiteral = TOY_TO_STRING_LITERAL(Toy_createRefStringLength(buffer, strlen(buffer)));
|
||||||
}
|
|
||||||
else { //normal case
|
|
||||||
char buffer[128];
|
|
||||||
snprintf(buffer, 128, "%ld.%06ld", timer->tv_sec, timer->tv_usec);
|
|
||||||
resultLiteral = TOY_TO_STRING_LITERAL(Toy_createRefStringLength(buffer, strlen(buffer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_pushLiteralArray(&interpreter->stack, resultLiteral);
|
Toy_pushLiteralArray(&interpreter->stack, resultLiteral);
|
||||||
|
|
||||||
@@ -331,9 +287,9 @@ static int nativeDestroyTimer(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval* timer = TOY_AS_OPAQUE(timeLiteral);
|
clock_t* timer = TOY_AS_OPAQUE(timeLiteral);
|
||||||
|
|
||||||
TOY_FREE(struct timeval, timer);
|
TOY_FREE(clock_t, timer);
|
||||||
|
|
||||||
Toy_freeLiteral(timeLiteral);
|
Toy_freeLiteral(timeLiteral);
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define INPUT_BUFFER_SIZE 2048
|
||||||
|
|
||||||
void repl() {
|
void repl() {
|
||||||
//repl does it's own thing for now
|
//repl does it's own thing for now
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
const int size = 2048;
|
char input[INPUT_BUFFER_SIZE];
|
||||||
char input[size];
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
memset(input, 0, size);
|
|
||||||
|
|
||||||
Toy_Interpreter interpreter; //persist the interpreter for the scopes
|
Toy_Interpreter interpreter; //persist the interpreter for the scopes
|
||||||
Toy_initInterpreter(&interpreter);
|
Toy_initInterpreter(&interpreter);
|
||||||
@@ -38,7 +39,7 @@ void repl() {
|
|||||||
printf("> ");
|
printf("> ");
|
||||||
|
|
||||||
//handle EOF for exits
|
//handle EOF for exits
|
||||||
if (!fgets(input, size, stdin)) {
|
if (!fgets(input, INPUT_BUFFER_SIZE, stdin)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ int Toy_writeFile(const char* path, const unsigned char* bytes, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int written = fwrite(bytes, size, 1, file);
|
size_t written = fwrite(bytes, size, 1, file);
|
||||||
|
|
||||||
if (written != 1) {
|
if (written != 1) {
|
||||||
fprintf(stderr, TOY_CC_ERROR "Could not write file \"%s\"\n" TOY_CC_RESET, path);
|
fprintf(stderr, TOY_CC_ERROR "Could not write file \"%s\"\n" TOY_CC_RESET, path);
|
||||||
@@ -118,7 +118,7 @@ void Toy_runBinary(const unsigned char* tb, size_t size) {
|
|||||||
Toy_injectNativeHook(&interpreter, "timer", Toy_hookTimer);
|
Toy_injectNativeHook(&interpreter, "timer", Toy_hookTimer);
|
||||||
Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner);
|
Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner);
|
||||||
|
|
||||||
Toy_runInterpreter(&interpreter, tb, size);
|
Toy_runInterpreter(&interpreter, tb, (int)size);
|
||||||
Toy_freeInterpreter(&interpreter);
|
Toy_freeInterpreter(&interpreter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ STATIC_ASSERT(sizeof(unsigned char) == 1);
|
|||||||
STATIC_ASSERT(sizeof(unsigned short) == 2);
|
STATIC_ASSERT(sizeof(unsigned short) == 2);
|
||||||
STATIC_ASSERT(sizeof(unsigned int) == 4);
|
STATIC_ASSERT(sizeof(unsigned int) == 4);
|
||||||
|
|
||||||
#ifndef TOY_EXPORT
|
|
||||||
|
|
||||||
//declare the singleton
|
//declare the singleton
|
||||||
Toy_CommandLine Toy_commandLine;
|
Toy_CommandLine Toy_commandLine;
|
||||||
|
|
||||||
@@ -121,5 +119,3 @@ void Toy_copyrightCommandLine(int argc, const char* argv[]) {
|
|||||||
printf("2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\n\n");
|
printf("2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\n\n");
|
||||||
printf("3. This notice may not be removed or altered from any source distribution.\n\n");
|
printf("3. This notice may not be removed or altered from any source distribution.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -11,17 +11,22 @@
|
|||||||
|
|
||||||
//platform-specific specifications
|
//platform-specific specifications
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
|
||||||
#define TOY_API extern
|
#define TOY_API extern
|
||||||
|
|
||||||
#elif defined(_WIN32) || defined(WIN32)
|
#elif defined(_WIN32) || defined(_MSC_VER)
|
||||||
#define TOY_API
|
|
||||||
|
#ifndef TOY_EXPORT
|
||||||
|
#define TOY_API __declspec(dllimport)
|
||||||
|
#else
|
||||||
|
#define TOY_API __declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define TOY_API
|
#define TOY_API extern
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TOY_EXPORT
|
|
||||||
//for processing the command line arguments
|
//for processing the command line arguments
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool error;
|
bool error;
|
||||||
@@ -35,11 +40,10 @@ typedef struct {
|
|||||||
bool verbose;
|
bool verbose;
|
||||||
} Toy_CommandLine;
|
} Toy_CommandLine;
|
||||||
|
|
||||||
extern Toy_CommandLine Toy_commandLine;
|
TOY_API Toy_CommandLine Toy_commandLine;
|
||||||
|
|
||||||
void Toy_initCommandLine(int argc, const char* argv[]);
|
TOY_API void Toy_initCommandLine(int argc, const char* argv[]);
|
||||||
|
|
||||||
void Toy_usageCommandLine(int argc, const char* argv[]);
|
TOY_API void Toy_usageCommandLine(int argc, const char* argv[]);
|
||||||
void Toy_helpCommandLine(int argc, const char* argv[]);
|
TOY_API void Toy_helpCommandLine(int argc, const char* argv[]);
|
||||||
void Toy_copyrightCommandLine(int argc, const char* argv[]);
|
TOY_API void Toy_copyrightCommandLine(int argc, const char* argv[]);
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -2356,7 +2356,7 @@ void Toy_initInterpreter(Toy_Interpreter* interpreter) {
|
|||||||
Toy_resetInterpreter(interpreter);
|
Toy_resetInterpreter(interpreter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toy_runInterpreter(Toy_Interpreter* interpreter, const unsigned char* bytecode, int length) {
|
void Toy_runInterpreter(Toy_Interpreter* interpreter, const unsigned char* bytecode, size_t length) {
|
||||||
//initialize here instead of initInterpreter()
|
//initialize here instead of initInterpreter()
|
||||||
Toy_initLiteralArray(&interpreter->literalCache);
|
Toy_initLiteralArray(&interpreter->literalCache);
|
||||||
interpreter->bytecode = NULL;
|
interpreter->bytecode = NULL;
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ TOY_API void Toy_setInterpreterError(Toy_Interpreter* interpreter, Toy_PrintFn e
|
|||||||
|
|
||||||
//main access
|
//main access
|
||||||
TOY_API void Toy_initInterpreter(Toy_Interpreter* interpreter); //start of program
|
TOY_API void Toy_initInterpreter(Toy_Interpreter* interpreter); //start of program
|
||||||
TOY_API void Toy_runInterpreter(Toy_Interpreter* interpreter, const unsigned char* bytecode, int length); //run the code
|
TOY_API void Toy_runInterpreter(Toy_Interpreter* interpreter, const unsigned char* bytecode, size_t length); //run the code
|
||||||
TOY_API void Toy_resetInterpreter(Toy_Interpreter* interpreter); //use this to reset the interpreter's environment between runs
|
TOY_API void Toy_resetInterpreter(Toy_Interpreter* interpreter); //use this to reset the interpreter's environment between runs
|
||||||
TOY_API void Toy_freeInterpreter(Toy_Interpreter* interpreter); //end of program
|
TOY_API void Toy_freeInterpreter(Toy_Interpreter* interpreter); //end of program
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ typedef struct {
|
|||||||
} Toy_Token;
|
} Toy_Token;
|
||||||
|
|
||||||
TOY_API void Toy_initLexer(Toy_Lexer* lexer, const char* source);
|
TOY_API void Toy_initLexer(Toy_Lexer* lexer, const char* source);
|
||||||
Toy_Token Toy_scanLexer(Toy_Lexer* lexer);
|
TOY_API Toy_Token Toy_scanLexer(Toy_Lexer* lexer);
|
||||||
|
|
||||||
//for debugging
|
//for debugging
|
||||||
void Toy_printToken(Toy_Token* token);
|
TOY_API void Toy_printToken(Toy_Token* token);
|
||||||
|
|
||||||
void Toy_private_setComments(Toy_Lexer* lexer, bool enabled);
|
TOY_API void Toy_private_setComments(Toy_Lexer* lexer, bool enabled);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#define TOY_FREE_ARRAY(type, pointer, oldCount) Toy_reallocate((type*)pointer, sizeof(type) * (oldCount), 0)
|
#define TOY_FREE_ARRAY(type, pointer, oldCount) Toy_reallocate((type*)pointer, sizeof(type) * (oldCount), 0)
|
||||||
|
|
||||||
//implementation details
|
//implementation details
|
||||||
void* Toy_reallocate(void* pointer, size_t oldSize, size_t newSize);
|
TOY_API void* Toy_reallocate(void* pointer, size_t oldSize, size_t newSize);
|
||||||
|
|
||||||
//assign the memory allocator
|
//assign the memory allocator
|
||||||
typedef void* (*Toy_MemoryAllocatorFn)(void* pointer, size_t oldSize, size_t newSize);
|
typedef void* (*Toy_MemoryAllocatorFn)(void* pointer, size_t oldSize, size_t newSize);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "toy_common.h"
|
||||||
|
|
||||||
//memory allocation hook
|
//memory allocation hook
|
||||||
typedef void* (*Toy_RefStringAllocatorFn)(void* pointer, size_t oldSize, size_t newSize);
|
typedef void* (*Toy_RefStringAllocatorFn)(void* pointer, size_t oldSize, size_t newSize);
|
||||||
void Toy_setRefStringAllocatorFn(Toy_RefStringAllocatorFn);
|
void Toy_setRefStringAllocatorFn(Toy_RefStringAllocatorFn);
|
||||||
@@ -15,13 +17,13 @@ typedef struct Toy_RefString {
|
|||||||
} Toy_RefString;
|
} Toy_RefString;
|
||||||
|
|
||||||
//API
|
//API
|
||||||
Toy_RefString* Toy_createRefString(const char* cstring);
|
TOY_API Toy_RefString* Toy_createRefString(const char* cstring);
|
||||||
Toy_RefString* Toy_createRefStringLength(const char* cstring, size_t length);
|
TOY_API Toy_RefString* Toy_createRefStringLength(const char* cstring, size_t length);
|
||||||
void Toy_deleteRefString(Toy_RefString* refString);
|
TOY_API void Toy_deleteRefString(Toy_RefString* refString);
|
||||||
int Toy_countRefString(Toy_RefString* refString);
|
TOY_API int Toy_countRefString(Toy_RefString* refString);
|
||||||
size_t Toy_lengthRefString(Toy_RefString* refString);
|
TOY_API size_t Toy_lengthRefString(Toy_RefString* refString);
|
||||||
Toy_RefString* Toy_copyRefString(Toy_RefString* refString);
|
TOY_API Toy_RefString* Toy_copyRefString(Toy_RefString* refString);
|
||||||
Toy_RefString* Toy_deepCopyRefString(Toy_RefString* refString);
|
TOY_API Toy_RefString* Toy_deepCopyRefString(Toy_RefString* refString);
|
||||||
const char* Toy_toCString(Toy_RefString* refString);
|
TOY_API const char* Toy_toCString(Toy_RefString* refString);
|
||||||
bool Toy_equalsRefString(Toy_RefString* lhs, Toy_RefString* rhs);
|
TOY_API bool Toy_equalsRefString(Toy_RefString* lhs, Toy_RefString* rhs);
|
||||||
bool Toy_equalsRefStringCString(Toy_RefString* lhs, char* cstring);
|
TOY_API bool Toy_equalsRefStringCString(Toy_RefString* lhs, char* cstring);
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ typedef struct Toy_Scope {
|
|||||||
int references; //how many scopes point here
|
int references; //how many scopes point here
|
||||||
} Toy_Scope;
|
} Toy_Scope;
|
||||||
|
|
||||||
Toy_Scope* Toy_pushScope(Toy_Scope* scope);
|
TOY_API Toy_Scope* Toy_pushScope(Toy_Scope* scope);
|
||||||
Toy_Scope* Toy_popScope(Toy_Scope* scope);
|
TOY_API Toy_Scope* Toy_popScope(Toy_Scope* scope);
|
||||||
Toy_Scope* Toy_copyScope(Toy_Scope* original);
|
TOY_API Toy_Scope* Toy_copyScope(Toy_Scope* original);
|
||||||
|
|
||||||
//returns false if error
|
//returns false if error
|
||||||
bool Toy_declareScopeVariable(Toy_Scope* scope, Toy_Literal key, Toy_Literal type);
|
TOY_API bool Toy_declareScopeVariable(Toy_Scope* scope, Toy_Literal key, Toy_Literal type);
|
||||||
bool Toy_isDelcaredScopeVariable(Toy_Scope* scope, Toy_Literal key);
|
TOY_API bool Toy_isDelcaredScopeVariable(Toy_Scope* scope, Toy_Literal key);
|
||||||
|
|
||||||
//return false if undefined
|
//return false if undefined
|
||||||
bool Toy_setScopeVariable(Toy_Scope* scope, Toy_Literal key, Toy_Literal value, bool constCheck);
|
TOY_API bool Toy_setScopeVariable(Toy_Scope* scope, Toy_Literal key, Toy_Literal value, bool constCheck);
|
||||||
bool Toy_getScopeVariable(Toy_Scope* scope, Toy_Literal key, Toy_Literal* value);
|
TOY_API bool Toy_getScopeVariable(Toy_Scope* scope, Toy_Literal key, Toy_Literal* value);
|
||||||
|
|
||||||
Toy_Literal Toy_getScopeType(Toy_Scope* scope, Toy_Literal key);
|
TOY_API Toy_Literal Toy_getScopeType(Toy_Scope* scope, Toy_Literal key);
|
||||||
|
|||||||
Reference in New Issue
Block a user