This commit is contained in:
Add00
2023-07-31 13:16:01 -04:00
14 changed files with 64 additions and 63 deletions

View File

@@ -71,12 +71,12 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IgnoreImportLibrary>false</IgnoreImportLibrary> <IgnoreImportLibrary>false</IgnoreImportLibrary>
<OutDir>$(SolutionDir)out\$(Configuration)\</OutDir> <OutDir>$(SolutionDir)out\</OutDir>
<IntDir>$(Platform)\$(ProjectName)\$(Configuration)\</IntDir> <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)out\$(Configuration)\</OutDir> <OutDir>$(SolutionDir)out\</OutDir>
<IntDir>$(Platform)\$(ProjectName)\$(Configuration)\</IntDir> <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@@ -110,7 +110,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link> <Link>
<AdditionalDependencies>Toy.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Toy.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)out\$(Configuration)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(SolutionDir)out</AdditionalLibraryDirectories>
</Link> </Link>
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)/source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)/source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -125,30 +125,32 @@
<AdditionalIncludeDirectories>$(SolutionDir)/source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)/source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalLibraryDirectories>$(SolutionDir)out\$(Configuration)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(SolutionDir)out</AdditionalLibraryDirectories>
<AdditionalDependencies>Toy.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Toy.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="repl\lib_about.c" />
<ClCompile Include="repl\lib_random.c" />
<ClCompile Include="repl\lib_runner.c" />
<ClCompile Include="repl\lib_standard.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_random.h" />
<ClInclude Include="repl\lib_runner.h" />
<ClInclude Include="repl\lib_standard.h" />
<ClInclude Include="repl\repl_tools.h" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="Toy.vcxproj"> <ProjectReference Include="Toy.vcxproj">
<Project>{26360002-cc2a-469a-9b28-ba0c1af41657}</Project> <Project>{26360002-cc2a-469a-9b28-ba0c1af41657}</Project>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClCompile Include="repl\drive_system.c" />
<ClCompile Include="repl\lib_random.c" />
<ClCompile Include="repl\lib_runner.c" />
<ClCompile Include="repl\lib_standard.c" />
<ClCompile Include="repl\lib_toy_version_info.c" />
<ClCompile Include="repl\repl_main.c" />
<ClCompile Include="repl\repl_tools.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="repl\drive_system.h" />
<ClInclude Include="repl\lib_random.h" />
<ClInclude Include="repl\lib_runner.h" />
<ClInclude Include="repl\lib_standard.h" />
<ClInclude Include="repl\lib_toy_version_info.h" />
<ClInclude Include="repl\repl_tools.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@@ -71,12 +71,12 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)out\</OutDir> <OutDir>$(SolutionDir)out\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir> <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)out\</OutDir> <OutDir>$(SolutionDir)out\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir> <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@@ -1,5 +0,0 @@
#pragma once
#include "toy_interpreter.h"
int Toy_hookAbout(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias);

View File

@@ -202,11 +202,11 @@ static int nativeMax(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//cooerce if needed //cooerce if needed
if (TOY_IS_INTEGER(resultLiteral) && TOY_IS_FLOAT(selfLiteral)) { if (TOY_IS_INTEGER(resultLiteral) && TOY_IS_FLOAT(selfLiteral)) {
resultLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(resultLiteral) ); resultLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(resultLiteral) );
} }
if (TOY_IS_FLOAT(resultLiteral) && TOY_IS_INTEGER(selfLiteral)) { if (TOY_IS_FLOAT(resultLiteral) && TOY_IS_INTEGER(selfLiteral)) {
selfLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(selfLiteral) ); selfLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(selfLiteral) );
} }
//compare //compare
@@ -258,11 +258,11 @@ static int nativeMin(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//cooerce if needed //cooerce if needed
if (TOY_IS_INTEGER(resultLiteral) && TOY_IS_FLOAT(selfLiteral)) { if (TOY_IS_INTEGER(resultLiteral) && TOY_IS_FLOAT(selfLiteral)) {
resultLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(resultLiteral) ); resultLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(resultLiteral) );
} }
if (TOY_IS_FLOAT(resultLiteral) && TOY_IS_INTEGER(selfLiteral)) { if (TOY_IS_FLOAT(resultLiteral) && TOY_IS_INTEGER(selfLiteral)) {
selfLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(selfLiteral) ); selfLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(selfLiteral) );
} }
//compare //compare

View File

@@ -1,23 +1,23 @@
#include "lib_about.h" #include "lib_toy_version_info.h"
#include "toy_memory.h" #include "toy_memory.h"
int Toy_hookAbout(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias) { int Toy_hookToyVersionInfo(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias) {
//the about keys //the info keys
Toy_Literal majorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("major")); Toy_Literal majorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("major"));
Toy_Literal minorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("minor")); Toy_Literal minorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("minor"));
Toy_Literal patchKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("patch")); Toy_Literal patchKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("patch"));
Toy_Literal buildKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("build")); Toy_Literal buildKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("build"));
Toy_Literal authorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("author")); Toy_Literal authorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("author"));
//the about identifiers //the info identifiers
Toy_Literal majorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("major")); Toy_Literal majorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("major"));
Toy_Literal minorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("minor")); Toy_Literal minorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("minor"));
Toy_Literal patchIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("patch")); Toy_Literal patchIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("patch"));
Toy_Literal buildIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("build")); Toy_Literal buildIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("build"));
Toy_Literal authorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("author")); Toy_Literal authorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("author"));
//the about values //the info values
Toy_Literal majorLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_MAJOR); Toy_Literal majorLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_MAJOR);
Toy_Literal minorLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_MINOR); Toy_Literal minorLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_MINOR);
Toy_Literal patchLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_PATCH); Toy_Literal patchLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_PATCH);

View File

@@ -0,0 +1,5 @@
#pragma once
#include "toy_interpreter.h"
int Toy_hookToyVersionInfo(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias);

View File

@@ -1,6 +1,6 @@
#include "repl_tools.h" #include "repl_tools.h"
#include "drive_system.h" #include "drive_system.h"
#include "lib_about.h" #include "lib_toy_version_info.h"
#include "lib_standard.h" #include "lib_standard.h"
#include "lib_random.h" #include "lib_random.h"
#include "lib_runner.h" #include "lib_runner.h"
@@ -26,7 +26,7 @@ void repl(const char* initialInput) {
Toy_initInterpreter(&interpreter); Toy_initInterpreter(&interpreter);
//inject the libs //inject the libs
Toy_injectNativeHook(&interpreter, "about", Toy_hookAbout); Toy_injectNativeHook(&interpreter, "toy_version_info", Toy_hookToyVersionInfo);
Toy_injectNativeHook(&interpreter, "standard", Toy_hookStandard); Toy_injectNativeHook(&interpreter, "standard", Toy_hookStandard);
Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom); Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom);
Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner); Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner);

View File

@@ -1,5 +1,5 @@
#include "repl_tools.h" #include "repl_tools.h"
#include "lib_about.h" #include "lib_toy_version_info.h"
#include "lib_standard.h" #include "lib_standard.h"
#include "lib_random.h" #include "lib_random.h"
#include "lib_runner.h" #include "lib_runner.h"
@@ -111,7 +111,7 @@ void Toy_runBinary(const unsigned char* tb, size_t size) {
Toy_initInterpreter(&interpreter); Toy_initInterpreter(&interpreter);
//inject the libs //inject the libs
Toy_injectNativeHook(&interpreter, "about", Toy_hookAbout); Toy_injectNativeHook(&interpreter, "toy_version_info", Toy_hookToyVersionInfo);
Toy_injectNativeHook(&interpreter, "standard", Toy_hookStandard); Toy_injectNativeHook(&interpreter, "standard", Toy_hookStandard);
Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom); Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom);
Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner); Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner);
@@ -159,7 +159,7 @@ static unsigned char readByte(const unsigned char* tb, int* count) {
static const char* readString(const unsigned char* tb, int* count) { static const char* readString(const unsigned char* tb, int* count) {
const unsigned char* ret = tb + *count; const unsigned char* ret = tb + *count;
*count += strlen((char*)ret) + 1; //+1 for null character *count += (int)strlen((char*)ret) + 1; //+1 for null character
return (const char*)ret; return (const char*)ret;
} }

View File

@@ -46,7 +46,7 @@ const unsigned char* Toy_compileString(const char* source, size_t* size);
This function takes a bytecode array of `size` size, and executes it. The libraries available to the code are currently: This function takes a bytecode array of `size` size, and executes it. The libraries available to the code are currently:
* lib_about * lib_toy_version_info
* lib_standard * lib_standard
* lib_random * lib_random
* lib_runner * lib_runner

View File

@@ -750,23 +750,10 @@ static Toy_Opcode decrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
//wait - is the previous token a type? this should be casting instead //wait - is the previous token a type? this should be casting instead
if (parser->previous.type >= TOY_TOKEN_NULL && parser->previous.type <= TOY_TOKEN_ANY) { if (parser->previous.type >= TOY_TOKEN_NULL && parser->previous.type <= TOY_TOKEN_ANY) {
//casting type
Toy_ASTNode* lhsNode = NULL;
castingPrefix(parser, &lhsNode);
advance(parser);
//casting value //casting value
Toy_ASTNode* rhsNode = NULL; parsePrecedence(parser, nodeHandle, PREC_CALL);
grouping(parser, &rhsNode);
//emit the cast node return TOY_OP_TYPE_CAST; //opcode value
Toy_emitASTNodeBinary(&lhsNode, rhsNode, TOY_OP_TYPE_CAST);
//pass it off to the caller
*nodeHandle = lhsNode;
return TOY_OP_GROUPING_BEGIN; //dummy value
} }
advance(parser); //skip the left paren advance(parser); //skip the left paren

View File

@@ -0,0 +1,11 @@
//test for casting + grouping, see #67
{
assert string(10 % 4) == "2", "basic group casting failed";
assert string 4 == "4", "normal casting failed";
assert typeof string(10 % 4) == string, "group casting type failed";
}
print "All good";

View File

@@ -1,5 +1,5 @@
import about as about; import toy_version_info as toy_version_info;
import about; import toy_version_info;
assert author == "Kayne Ruse, KR Game Studios", "Author failed"; assert author == "Kayne Ruse, KR Game Studios", "Author failed";

View File

@@ -119,6 +119,7 @@ int main() {
"dottify-bugfix.toy", "dottify-bugfix.toy",
"function-within-function-bugfix.toy", "function-within-function-bugfix.toy",
"functions.toy", "functions.toy",
"group-casting-bugfix.toy",
"increment-postfix-bugfix.toy", "increment-postfix-bugfix.toy",
"index-arrays.toy", "index-arrays.toy",
"index-assignment-both-bugfix.toy", "index-assignment-both-bugfix.toy",

View File

@@ -14,10 +14,10 @@
#include "../repl/repl_tools.h" #include "../repl/repl_tools.h"
#include "../repl/drive_system.h" #include "../repl/drive_system.h"
#include "../repl/lib_about.h" #include "../repl/lib_toy_version_info.h"
#include "../repl/lib_standard.h"
#include "../repl/lib_random.h" #include "../repl/lib_random.h"
#include "../repl/lib_runner.h" #include "../repl/lib_runner.h"
#include "../repl/lib_standard.h"
//supress the print output //supress the print output
static void noPrintFn(const char* output) { static void noPrintFn(const char* output) {
@@ -72,7 +72,7 @@ int main() {
//run each file in test/scripts //run each file in test/scripts
Payload payloads[] = { Payload payloads[] = {
{"interactions.toy", "standard", Toy_hookStandard}, //interactions needs standard {"interactions.toy", "standard", Toy_hookStandard}, //interactions needs standard
{"about.toy", "about", Toy_hookAbout}, {"toy_version_info.toy", "toy_version_info", Toy_hookToyVersionInfo},
{"standard.toy", "standard", Toy_hookStandard}, {"standard.toy", "standard", Toy_hookStandard},
{"runner.toy", "runner", Toy_hookRunner}, {"runner.toy", "runner", Toy_hookRunner},
{"random.toy", "random", Toy_hookRandom}, {"random.toy", "random", Toy_hookRandom},