Browse Source

separate hl binary from hldll

Nicolas Cannasse 9 years ago
parent
commit
d5aaa7bfe8
13 changed files with 533 additions and 322 deletions
  1. 2 0
      .gitignore
  2. 16 48
      hl.vcxproj
  3. 1 105
      hl.vcxproj.filters
  4. 202 0
      hldll.vcxproj
  5. 112 0
      hldll.vcxproj.filters
  6. 111 90
      src/hl.h
  7. 7 3
      src/hlc.h
  8. 25 7
      src/main.c
  9. 2 2
      src/std/error.c
  10. 10 2
      src/std/fun.c
  11. 6 0
      src/std/string.c
  12. 26 52
      src/std/sys.c
  13. 13 13
      src/std/types.c

+ 2 - 0
.gitignore

@@ -21,3 +21,5 @@ x64
 /src/_main5.c
 /src/_main6.c
 *.a
+*.opendb
+/include/sdl

+ 16 - 48
hl.vcxproj

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
       <Configuration>Debug</Configuration>
@@ -28,6 +28,7 @@
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
     <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
@@ -40,6 +41,7 @@
     <UseDebugLibraries>false</UseDebugLibraries>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>v140</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
@@ -66,19 +68,23 @@
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LinkIncremental>true</LinkIncremental>
-    <IncludePath>include\pcre;$(IncludePath)</IncludePath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);src</IncludePath>
+    <LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(Configuration)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
     <LinkIncremental>true</LinkIncremental>
-    <IncludePath>include/pcre;$(IncludePath)</IncludePath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);src</IncludePath>
+    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;$(Configuration)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
-    <IncludePath>include/pcre;$(IncludePath)</IncludePath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);src</IncludePath>
+    <LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(Configuration)</LibraryPath>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <LinkIncremental>false</LinkIncremental>
-    <IncludePath>include/pcre;$(IncludePath)</IncludePath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);src</IncludePath>
+    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;$(Configuration)</LibraryPath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -87,12 +93,11 @@
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
-      <AdditionalIncludeDirectories>src</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>hl.lib;sdl.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -102,12 +107,11 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>src</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>hl.lib;sdl.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -120,14 +124,13 @@
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
-      <AdditionalIncludeDirectories>src</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>hl.lib;sdl.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -139,56 +142,21 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>src</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>hl.lib;sdl.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="include\pcre\pcre_chartables.c" />
-    <ClCompile Include="include\pcre\pcre_compile.c" />
-    <ClCompile Include="include\pcre\pcre_dfa_exec.c" />
-    <ClCompile Include="include\pcre\pcre_exec.c" />
-    <ClCompile Include="include\pcre\pcre_fullinfo.c" />
-    <ClCompile Include="include\pcre\pcre_globals.c" />
-    <ClCompile Include="include\pcre\pcre_newline.c" />
-    <ClCompile Include="include\pcre\pcre_string_utils.c" />
-    <ClCompile Include="include\pcre\pcre_tables.c" />
-    <ClCompile Include="include\pcre\pcre_xclass.c" />
-    <ClCompile Include="src\alloc.c" />
-    <ClCompile Include="src\std\array.c" />
-    <ClCompile Include="src\std\buffer.c" />
-    <ClCompile Include="src\std\bytes.c" />
-    <ClCompile Include="src\std\cast.c" />
-    <ClCompile Include="src\std\date.c" />
-    <ClCompile Include="src\std\error.c" />
-    <ClCompile Include="src\std\file.c" />
-    <ClCompile Include="src\std\fun.c" />
-    <ClCompile Include="src\std\maps.c" />
-    <ClCompile Include="src\std\math.c" />
-    <ClCompile Include="src\std\obj.c" />
-    <ClCompile Include="src\std\regexp.c" />
-    <ClCompile Include="src\std\socket.c" />
-    <ClCompile Include="src\std\string.c" />
-    <ClCompile Include="src\std\sys.c" />
-    <ClCompile Include="src\std\types.c" />
-    <ClCompile Include="src\std\ucs2.c" />
+    <ClCompile Include="src\main.c" />
     <ClCompile Include="src\_main.c" />
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="include\pcre\config.h" />
-    <ClInclude Include="include\pcre\pcre.h" />
-    <ClInclude Include="include\pcre\pcre_internal.h" />
-    <ClInclude Include="include\pcre\ucp.h" />
-    <ClInclude Include="src\hl.h" />
     <ClInclude Include="src\hlc.h" />
-    <ClInclude Include="src\hlmodule.h" />
-    <ClInclude Include="src\opcodes.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 1 - 105
hl.vcxproj.filters

@@ -1,114 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <ClCompile Include="src\alloc.c" />
     <ClCompile Include="src\_main.c" />
-    <ClCompile Include="include\pcre\pcre_xclass.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_chartables.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_compile.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_dfa_exec.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_exec.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_fullinfo.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_globals.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_newline.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_string_utils.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="include\pcre\pcre_tables.c">
-      <Filter>pcre</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\array.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\fun.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\buffer.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\bytes.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\cast.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\date.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\error.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\file.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\maps.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\obj.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\math.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\regexp.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\types.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\socket.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\string.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\sys.c">
-      <Filter>std</Filter>
-    </ClCompile>
-    <ClCompile Include="src\std\ucs2.c">
-      <Filter>std</Filter>
-    </ClCompile>
+    <ClCompile Include="src\main.c" />
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="src\hl.h" />
     <ClInclude Include="src\hlc.h" />
-    <ClInclude Include="src\hlmodule.h" />
-    <ClInclude Include="src\opcodes.h" />
-    <ClInclude Include="include\pcre\pcre.h">
-      <Filter>pcre</Filter>
-    </ClInclude>
-    <ClInclude Include="include\pcre\pcre_internal.h">
-      <Filter>pcre</Filter>
-    </ClInclude>
-    <ClInclude Include="include\pcre\config.h">
-      <Filter>pcre</Filter>
-    </ClInclude>
-    <ClInclude Include="include\pcre\ucp.h">
-      <Filter>pcre</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <Filter Include="pcre">
-      <UniqueIdentifier>{39677e22-d3ec-4045-b5b1-3ab742946791}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="std">
-      <UniqueIdentifier>{7e253825-89b6-4013-9015-12ff52742fbb}</UniqueIdentifier>
-    </Filter>
   </ItemGroup>
 </Project>

+ 202 - 0
hldll.vcxproj

@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" 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">
+    <ProjectGuid>{C6213FBF-BC2B-4235-A827-84A60E848C52}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>hldll</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </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>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);include/pcre;src</IncludePath>
+    <TargetName>hl</TargetName>
+    <TargetExt>.hdll</TargetExt>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);include/pcre;src</IncludePath>
+    <TargetName>hl</TargetName>
+    <TargetExt>.hdll</TargetExt>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);include/pcre;src</IncludePath>
+    <TargetName>hl</TargetName>
+    <TargetExt>.hdll</TargetExt>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);include/pcre;src</IncludePath>
+    <TargetName>hl</TargetName>
+    <TargetExt>.hdll</TargetExt>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>ws2_32.lib;user32.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>ws2_32.lib;user32.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>ws2_32.lib;user32.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>ws2_32.lib;user32.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="include\pcre\pcre_chartables.c" />
+    <ClCompile Include="include\pcre\pcre_compile.c" />
+    <ClCompile Include="include\pcre\pcre_dfa_exec.c" />
+    <ClCompile Include="include\pcre\pcre_exec.c" />
+    <ClCompile Include="include\pcre\pcre_fullinfo.c" />
+    <ClCompile Include="include\pcre\pcre_globals.c" />
+    <ClCompile Include="include\pcre\pcre_newline.c" />
+    <ClCompile Include="include\pcre\pcre_string_utils.c" />
+    <ClCompile Include="include\pcre\pcre_tables.c" />
+    <ClCompile Include="include\pcre\pcre_xclass.c" />
+    <ClCompile Include="src\alloc.c" />
+    <ClCompile Include="src\std\array.c" />
+    <ClCompile Include="src\std\buffer.c" />
+    <ClCompile Include="src\std\bytes.c" />
+    <ClCompile Include="src\std\cast.c" />
+    <ClCompile Include="src\std\date.c" />
+    <ClCompile Include="src\std\error.c" />
+    <ClCompile Include="src\std\file.c" />
+    <ClCompile Include="src\std\fun.c" />
+    <ClCompile Include="src\std\maps.c" />
+    <ClCompile Include="src\std\math.c" />
+    <ClCompile Include="src\std\obj.c" />
+    <ClCompile Include="src\std\regexp.c" />
+    <ClCompile Include="src\std\socket.c" />
+    <ClCompile Include="src\std\string.c" />
+    <ClCompile Include="src\std\sys.c" />
+    <ClCompile Include="src\std\types.c" />
+    <ClCompile Include="src\std\ucs2.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="include\pcre\config.h" />
+    <ClInclude Include="include\pcre\pcre.h" />
+    <ClInclude Include="include\pcre\pcre_internal.h" />
+    <ClInclude Include="include\pcre\ucp.h" />
+    <ClInclude Include="src\hl.h" />
+    <ClInclude Include="src\hlmodule.h" />
+    <ClInclude Include="src\opcodes.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 112 - 0
hldll.vcxproj.filters

@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="pcre">
+      <UniqueIdentifier>{0e7277a9-ef45-478a-96fb-94c4a8974464}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="std">
+      <UniqueIdentifier>{1a2be115-e928-4943-acee-27878bb374ee}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="include\pcre\pcre_chartables.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_compile.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_dfa_exec.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_exec.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_fullinfo.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_globals.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_newline.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_string_utils.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_tables.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="include\pcre\pcre_xclass.c">
+      <Filter>pcre</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\array.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\buffer.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\bytes.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\cast.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\date.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\error.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\file.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\fun.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\maps.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\math.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\obj.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\regexp.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\socket.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\string.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\sys.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\types.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\std\ucs2.c">
+      <Filter>std</Filter>
+    </ClCompile>
+    <ClCompile Include="src\alloc.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="include\pcre\config.h">
+      <Filter>pcre</Filter>
+    </ClInclude>
+    <ClInclude Include="include\pcre\pcre.h">
+      <Filter>pcre</Filter>
+    </ClInclude>
+    <ClInclude Include="include\pcre\pcre_internal.h">
+      <Filter>pcre</Filter>
+    </ClInclude>
+    <ClInclude Include="include\pcre\ucp.h">
+      <Filter>pcre</Filter>
+    </ClInclude>
+    <ClInclude Include="src\hl.h" />
+    <ClInclude Include="src\hlmodule.h" />
+    <ClInclude Include="src\opcodes.h" />
+  </ItemGroup>
+</Project>

+ 111 - 90
src/hl.h

@@ -22,6 +22,8 @@
 #ifndef HL_H
 #define HL_H
 
+#define HL_VERSION	010
+
 #ifdef _WIN32
 #	define HL_WIN
 #endif
@@ -127,7 +129,11 @@ typedef long long int64;
 #include <stdio.h>
 #include <memory.h>
 
-#define HL_VERSION	010
+#ifdef HLDLL_EXPORTS
+#define HL_API extern EXPORT
+#else
+#define	HL_API IMPORT
+#endif
 
 // -------------- UNICODE -----------------------------------
 
@@ -152,16 +158,16 @@ typedef wchar_t	uchar;
 typedef unsigned short uchar;
 #	undef USTR
 #	define USTR(str)	u##str
-extern int ustrlen( const uchar *str );
-extern uchar *ustrdup( const uchar *str );
-extern double utod( const uchar *str, uchar **end );
-extern int utoi( const uchar *str, uchar **end );
-extern int ucmp( const uchar *a, const uchar *b );
-extern int strtou( uchar *out, int out_size, const char *str ); 
-extern int utostr( char *out, int out_size, const uchar *str ); 
-extern int usprintf( uchar *out, int out_size, const uchar *fmt, ... );
-extern int uvsprintf( uchar *out, const uchar *fmt, va_list arglist );
-extern void uprintf( const uchar *fmt, const uchar *str );
+HL_API int ustrlen( const uchar *str );
+HL_API uchar *ustrdup( const uchar *str );
+HL_API double utod( const uchar *str, uchar **end );
+HL_API int utoi( const uchar *str, uchar **end );
+HL_API int ucmp( const uchar *a, const uchar *b );
+HL_API int strtou( uchar *out, int out_size, const char *str );
+HL_API int utostr( char *out, int out_size, const uchar *str );
+HL_API int usprintf( uchar *out, int out_size, const uchar *fmt, ... );
+HL_API int uvsprintf( uchar *out, const uchar *fmt, va_list arglist );
+HL_API void uprintf( const uchar *fmt, const uchar *str );
 #endif
 
 // ---- TYPES -------------------------------------------
@@ -385,103 +391,104 @@ typedef struct _venum {
 	int index;
 } venum;
 
-extern hl_type hlt_void;
-extern hl_type hlt_i32;
-extern hl_type hlt_f64;
-extern hl_type hlt_f32;
-extern hl_type hlt_dyn;
-extern hl_type hlt_array;
-extern hl_type hlt_bytes;
-extern hl_type hlt_dynobj;
-
-double hl_nan();
-bool hl_is_dynamic( hl_type *t );
+HL_API hl_type hlt_void;
+HL_API hl_type hlt_i32;
+HL_API hl_type hlt_f64;
+HL_API hl_type hlt_f32;
+HL_API hl_type hlt_dyn;
+HL_API hl_type hlt_array;
+HL_API hl_type hlt_bytes;
+HL_API hl_type hlt_dynobj;
+
+HL_API double hl_nan();
+HL_API bool hl_is_dynamic( hl_type *t );
 #define hl_is_ptr(t)	((t)->kind >= HBYTES)
-bool hl_same_type( hl_type *a, hl_type *b );
-bool hl_safe_cast( hl_type *t, hl_type *to );
+HL_API bool hl_same_type( hl_type *a, hl_type *b );
+HL_API bool hl_safe_cast( hl_type *t, hl_type *to );
 
 #define hl_aptr(a,t)	((t*)(((varray*)(a))+1))
 
-varray *hl_alloc_array( hl_type *t, int size );
-vdynamic *hl_alloc_dynamic( hl_type *t );
-vdynamic *hl_alloc_obj( hl_type *t );
-vvirtual *hl_alloc_virtual( hl_type *t );
-vdynobj *hl_alloc_dynobj();
-vbyte *hl_alloc_bytes( int size );
-vbyte *hl_copy_bytes( vbyte *byte, int size );
-vdynamic *hl_virtual_make_value( vvirtual *v );
+HL_API varray *hl_alloc_array( hl_type *t, int size );
+HL_API vdynamic *hl_alloc_dynamic( hl_type *t );
+HL_API vdynamic *hl_alloc_obj( hl_type *t );
+HL_API vvirtual *hl_alloc_virtual( hl_type *t );
+HL_API vdynobj *hl_alloc_dynobj();
+HL_API vbyte *hl_alloc_bytes( int size );
+HL_API vbyte *hl_copy_bytes( vbyte *byte, int size );
+HL_API char *hl_to_utf8( uchar *bytes );
+HL_API vdynamic *hl_virtual_make_value( vvirtual *v );
 
-int hl_hash( vbyte *name );
-int hl_hash_gen( const uchar *name, bool cache_name );
-const uchar *hl_field_name( int hash );
+HL_API int hl_hash( vbyte *name );
+HL_API int hl_hash_gen( const uchar *name, bool cache_name );
+HL_API const uchar *hl_field_name( int hash );
 
 #define hl_error(msg)	hl_error_msg(USTR(msg))
-void hl_error_msg( const uchar *msg, ... );
-void hl_throw( vdynamic *v );
-void hl_rethrow( vdynamic *v );
+HL_API void hl_error_msg( const uchar *msg, ... );
+HL_API void hl_throw( vdynamic *v );
+HL_API void hl_rethrow( vdynamic *v );
 
-vvirtual *hl_to_virtual( hl_type *vt, vdynamic *obj );
-void hl_init_virtual( hl_type *vt, hl_module_context *ctx );
-hl_field_lookup *hl_lookup_find( hl_field_lookup *l, int size, int hash );
+HL_API vvirtual *hl_to_virtual( hl_type *vt, vdynamic *obj );
+HL_API void hl_init_virtual( hl_type *vt, hl_module_context *ctx );
+HL_API hl_field_lookup *hl_lookup_find( hl_field_lookup *l, int size, int hash );
 
-int hl_dyn_geti( vdynamic *d, int hfield, hl_type *t );
-void *hl_dyn_getp( vdynamic *d, int hfield, hl_type *t );
-float hl_dyn_getf( vdynamic *d, int hfield );
-double hl_dyn_getd( vdynamic *d, int hfield );
+HL_API int hl_dyn_geti( vdynamic *d, int hfield, hl_type *t );
+HL_API void *hl_dyn_getp( vdynamic *d, int hfield, hl_type *t );
+HL_API float hl_dyn_getf( vdynamic *d, int hfield );
+HL_API double hl_dyn_getd( vdynamic *d, int hfield );
 
-int hl_dyn_casti( void *data, hl_type *t, hl_type *to );
-void *hl_dyn_castp( void *data, hl_type *t, hl_type *to );
-float hl_dyn_castf( void *data, hl_type *t );
-double hl_dyn_castd( void *data, hl_type *t );
+HL_API int hl_dyn_casti( void *data, hl_type *t, hl_type *to );
+HL_API void *hl_dyn_castp( void *data, hl_type *t, hl_type *to );
+HL_API float hl_dyn_castf( void *data, hl_type *t );
+HL_API double hl_dyn_castd( void *data, hl_type *t );
 
 #define hl_invalid_comparison 0xAABBCCDD
-int hl_dyn_compare( vdynamic *a, vdynamic *b );
-vdynamic *hl_make_dyn( void *data, hl_type *t );
-void hl_write_dyn( void *data, hl_type *t, vdynamic *v );
+HL_API int hl_dyn_compare( vdynamic *a, vdynamic *b );
+HL_API vdynamic *hl_make_dyn( void *data, hl_type *t );
+HL_API void hl_write_dyn( void *data, hl_type *t, vdynamic *v );
 
-void hl_dyn_seti( vdynamic *d, int hfield, hl_type *t, int value );
-void hl_dyn_setp( vdynamic *d, int hfield, hl_type *t, void *ptr );
-void hl_dyn_setf( vdynamic *d, int hfield, float f );
-void hl_dyn_setd( vdynamic *d, int hfield, double v );
+HL_API void hl_dyn_seti( vdynamic *d, int hfield, hl_type *t, int value );
+HL_API void hl_dyn_setp( vdynamic *d, int hfield, hl_type *t, void *ptr );
+HL_API void hl_dyn_setf( vdynamic *d, int hfield, float f );
+HL_API void hl_dyn_setd( vdynamic *d, int hfield, double v );
 
-vclosure *hl_alloc_closure_void( hl_type *t, void *fvalue );
-vclosure *hl_alloc_closure_ptr( hl_type *fullt, void *fvalue, void *ptr );
-vclosure *hl_make_fun_wrapper( vclosure *c, hl_type *to );
-void *hl_wrapper_call( void *value, void **args, vdynamic *ret );
+HL_API vclosure *hl_alloc_closure_void( hl_type *t, void *fvalue );
+HL_API vclosure *hl_alloc_closure_ptr( hl_type *fullt, void *fvalue, void *ptr );
+HL_API vclosure *hl_make_fun_wrapper( vclosure *c, hl_type *to );
+HL_API void *hl_wrapper_call( void *value, void **args, vdynamic *ret );
 
 // ----------------------- ALLOC --------------------------------------------------
 
-void *hl_gc_alloc( int size );
-void *hl_gc_alloc_noptr( int size );
-void *hl_gc_alloc_finalizer( int size );
+HL_API void *hl_gc_alloc( int size );
+HL_API void *hl_gc_alloc_noptr( int size );
+HL_API void *hl_gc_alloc_finalizer( int size );
 
-void hl_alloc_init( hl_alloc *a );
-void *hl_malloc( hl_alloc *a, int size );
-void *hl_zalloc( hl_alloc *a, int size );
-void hl_free( hl_alloc *a );
+HL_API void hl_alloc_init( hl_alloc *a );
+HL_API void *hl_malloc( hl_alloc *a, int size );
+HL_API void *hl_zalloc( hl_alloc *a, int size );
+HL_API void hl_free( hl_alloc *a );
 
-void hl_global_init();
-void hl_global_free();
+HL_API void hl_global_init();
+HL_API void hl_global_free();
 
 // ----------------------- BUFFER --------------------------------------------------
 
 typedef struct hl_buffer hl_buffer;
 
-hl_buffer *hl_alloc_buffer();
-void hl_buffer_val( hl_buffer *b, vdynamic *v );
-void hl_buffer_char( hl_buffer *b, uchar c );
-void hl_buffer_str( hl_buffer *b, const uchar *str );
-void hl_buffer_cstr( hl_buffer *b, const char *str );
-void hl_buffer_str_sub( hl_buffer *b, const uchar *str, int len );
-int hl_buffer_length( hl_buffer *b );
-uchar *hl_buffer_content( hl_buffer *b, int *len );
-uchar *hl_to_string( vdynamic *v );
-const uchar *hl_type_str( hl_type *t );
+HL_API hl_buffer *hl_alloc_buffer();
+HL_API void hl_buffer_val( hl_buffer *b, vdynamic *v );
+HL_API void hl_buffer_char( hl_buffer *b, uchar c );
+HL_API void hl_buffer_str( hl_buffer *b, const uchar *str );
+HL_API void hl_buffer_cstr( hl_buffer *b, const char *str );
+HL_API void hl_buffer_str_sub( hl_buffer *b, const uchar *str, int len );
+HL_API int hl_buffer_length( hl_buffer *b );
+HL_API uchar *hl_buffer_content( hl_buffer *b, int *len );
+HL_API uchar *hl_to_string( vdynamic *v );
+HL_API const uchar *hl_type_str( hl_type *t );
 
 // ----------------------- FFI ------------------------------------------------------
 
 // match GNU C++ mangling
-#define TYPE_STR	"vcsifdbBXPOATR"
+#define TYPE_STR	"vcsifdbBDPOATR"
 
 #undef  _VOID
 #define _NO_ARG
@@ -492,30 +499,44 @@ const uchar *hl_type_str( hl_type *t );
 #define _F32						"f"
 #define _F64						"d"
 #define _BOOL						"b"
-#define _DYN						"X"
+#define _DYN						"D"
 #define _FUN(t, args)				"P" args "_" t
-#define _OBJ						"O"
+#define _OBJ(fields)				"O" fields "_"
 #define _BYTES						"B"
 #define _ARR						"A"
 #define _TYPE						"T"
 #define _REF(t)						"R" t
 #undef _NULL
 #define _NULL(t)					"N" t
+#define _ABSTRACT(name)				"X" #name "_"
 
-#if HL_JIT
-#define	HL_PRIM						static
-#define DEFINE_PRIM(t,name,args)	DEFINE_PRIM_WITH_NAME(t,name,args,name)
-#define DEFINE_PRIM_WITH_NAME(t,name,args,realName)	C_FUNCTION_BEGIN EXPORT void *hlp_##realName( const char **sign ) { *sign = _FUN(t,args); return (void*)(&name); } C_FUNCTION_END
-#else
-#define	HL_PRIM
+#define _STRING						_OBJ(_BYTES _I32)
+
+typedef struct {
+	uchar *bytes;
+	int length;
+} vstring;
+
+#ifndef HL_NAME
+#	ifdef HLDLL_EXPORTS
+#		define HL_PRIM				EXPORT
+#	else
+#		define HL_PRIM
+#	endif
+#define HL_NAME(p)					p
 #define DEFINE_PRIM(t,name,args)
 #define DEFINE_PRIM_WITH_NAME(t,name,args,realName)
+#else
+#define	HL_PRIM						EXPORT
+#define DEFINE_PRIM(t,name,args)	DEFINE_PRIM_WITH_NAME(t,name,args,name)
+#define DEFINE_PRIM_WITH_NAME(t,name,args,realName)	C_FUNCTION_BEGIN EXPORT void *hlp_##realName( const char **sign ) { *sign = _FUN(t,args); return (void*)(&HL_NAME(name)); } C_FUNCTION_END
 #endif
 
 // -------------- EXTRA ------------------------------------
 
 #define hl_fatal(msg)	hl_fatal_error(msg,__FILE__,__LINE__)
-void *hl_fatal_error( const char *msg, const char *file, int line );
-void hl_fatal_fmt( const char *fmst, ... );
+HL_API void *hl_fatal_error( const char *msg, const char *file, int line );
+HL_API void hl_fatal_fmt( const char *fmst, ... );
+HL_API void hl_sys_init(void **args, int nargs);
 
 #endif

+ 7 - 3
src/hlc.h

@@ -58,7 +58,7 @@ static void hl_null_access() {
 	hl_error_msg(USTR("Null access"));
 }
 
-extern vdynamic *hl_call_method( vdynamic *c, varray *args );
+HL_API vdynamic *hl_call_method( vdynamic *c, varray *args );
 
 #define HLC_DYN_MAX_ARGS 9
 static vdynamic *hlc_dyn_call_args( vclosure *c, vdynamic **args, int nargs ) {
@@ -126,10 +126,14 @@ struct _hl_trap_ctx {
 	hl_trap_ctx *prev;
 };
 
-extern hl_trap_ctx *hl_current_trap;
-extern vdynamic *hl_current_exc;
+HL_API hl_trap_ctx *hl_current_trap;
+HL_API vdynamic *hl_current_exc;
 
 #define hlc_trap(ctx,r,label) { ctx.prev = hl_current_trap; hl_current_trap = &ctx; if( setjmp(ctx.buf) ) { r = hl_current_exc; goto label; } }
 #define hlc_endtrap(ctx) hl_current_trap = ctx.prev
 
+extern void *hlc_static_call(void *fun, hl_type *t, void **args, vdynamic *out);
+extern void *hlc_get_wrapper(hl_type *t);
+HL_API void hlc_setup(void *sc, void *gw);
+
 #endif

+ 25 - 7
src/main.c

@@ -19,7 +19,7 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-#include "hlmodule.h"
+#include <hlc.h>
 
 #ifdef HL_VCC
 #	include <crtdbg.h>
@@ -27,13 +27,33 @@
 #	define _CrtSetDbgFlag(x)
 #endif
 
-int main( int argc, char *argv[] ) {
-	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );
+
+#ifdef HL_WIN
+int wmain(int argc, uchar *argv[]) {
+#else
+int main(int argc, char *argv[]) {
+#endif
+	hl_trap_ctx ctx;
+	vdynamic *exc;
+	hl_global_init();
+	hlc_setup(hlc_static_call, hlc_get_wrapper);
+	hl_sys_init(argv + 1,argc - 1);
+	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF /*| _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF*/);
+	hlc_trap(ctx, exc, on_exception);
+	hl_entry_point();
+	hl_global_free();
+	return 0;
+on_exception:
+	uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(exc));
+	hl_global_free();
+	return 1;
+}
+
+/*
 	if( argc == 1 ) {
 		printf("HLVM %d.%d.%d (c)2015 Haxe Foundation\n  Usage : hl <file>\n",HL_VERSION/100,(HL_VERSION/10)%10,HL_VERSION%10);
 		return 1;
 	}
-	hl_global_init();
 	{
 		hl_code *code;
 		hl_module *m;
@@ -72,6 +92,4 @@ int main( int argc, char *argv[] ) {
 		hl_module_free(m);
 		hl_free(&code->alloc);
 	}
-	hl_global_free();
-	return 0;
-}
+*/

+ 2 - 2
src/std/error.c

@@ -23,8 +23,8 @@
 #include <stdarg.h>
 #include <string.h>
 
-hl_trap_ctx *hl_current_trap = NULL;
-vdynamic *hl_current_exc = NULL;
+HL_PRIM hl_trap_ctx *hl_current_trap = NULL;
+HL_PRIM vdynamic *hl_current_exc = NULL;
 
 void *hl_fatal_error( const char *msg, const char *file, int line ) {
 	printf("%s(%d) : FATAL ERROR : %s\n",file,line,msg);

+ 10 - 2
src/std/fun.c

@@ -87,8 +87,16 @@ bool hl_fun_compare( vdynamic *a, vdynamic *b ) {
 
 // ------------ DYNAMIC CALLS
 
-extern void *hlc_static_call( void *fun, hl_type *t, void **args, vdynamic *out );
-extern void *hlc_get_wrapper( hl_type *t );
+typedef void *(*fptr_static_call)(void *fun, hl_type *t, void **args, vdynamic *out);
+typedef void *(*fptr_get_wrapper)(hl_type *t);
+
+static fptr_static_call hlc_static_call = NULL;
+static fptr_get_wrapper hlc_get_wrapper = NULL;
+
+HL_PRIM void hlc_setup( void *c, void *w ) {
+	hlc_static_call = (fptr_static_call)c;
+	hlc_get_wrapper = (fptr_get_wrapper)w;
+}
 
 #define HL_MAX_ARGS 5
 

+ 6 - 0
src/std/string.c

@@ -194,6 +194,12 @@ HL_PRIM vbyte *hl_utf16_to_utf8( vbyte *str, int pos, int *size ) {
 	return out;
 }
 
+HL_PRIM char *hl_to_utf8( uchar *bytes ) {
+	int size;
+	return hl_utf16_to_utf8((vbyte*)bytes, 0, &size);
+}
+
+
 HL_PRIM vbyte *hl_url_encode( vbyte *str, int *len ) {
 	hl_buffer *b = hl_alloc_buffer();
 	uchar *cstr = (uchar*)str;

+ 26 - 52
src/std/sys.c

@@ -142,11 +142,11 @@ HL_PRIM int hl_random( int max ) {
 	return rand() % max;
 }
 
-vbyte *hl_sys_get_env( vbyte *v ) {
+HL_PRIM vbyte *hl_sys_get_env( vbyte *v ) {
 	return (vbyte*)getenv((pchar*)v);
 }
 
-bool hl_sys_put_env( vbyte *e, vbyte *v ) {
+HL_PRIM bool hl_sys_put_env( vbyte *e, vbyte *v ) {
 #ifdef HL_WIN
 	hl_buffer *b = hl_alloc_buffer();
 	hl_buffer_str(b,(uchar*)e);
@@ -170,7 +170,7 @@ bool hl_sys_put_env( vbyte *e, vbyte *v ) {
 extern char **environ;
 #endif
 
-varray *hl_sys_env() {
+HL_PRIM varray *hl_sys_env() {
 	varray *a;
 	pchar **e = environ;
 	pchar **arr;
@@ -200,7 +200,7 @@ varray *hl_sys_env() {
 }
 
 
-void hl_sys_sleep( double f ) {
+HL_PRIM void hl_sys_sleep( double f ) {
 #ifdef HL_WIN
 	Sleep((DWORD)(f * 1000));
 #else
@@ -211,7 +211,7 @@ void hl_sys_sleep( double f ) {
 #endif
 }
 
-bool hl_sys_set_time_locale( vbyte *l ) {
+HL_PRIM bool hl_sys_set_time_locale( vbyte *l ) {
 #ifdef HL_POSIX
 	locale_t lc, old;
 	lc = newlocale(LC_TIME_MASK,(char*)l,NULL);
@@ -230,7 +230,7 @@ bool hl_sys_set_time_locale( vbyte *l ) {
 }
 
 
-vbyte *hl_sys_get_cwd() {
+HL_PRIM vbyte *hl_sys_get_cwd() {
 	pchar buf[256];
 	int l;
 	if( getcwd(buf,256) == NULL )
@@ -243,11 +243,11 @@ vbyte *hl_sys_get_cwd() {
 	return (vbyte*)pstrdup(buf,-1);
 }
 
-bool hl_sys_set_cwd( vbyte *dir ) {
+HL_PRIM bool hl_sys_set_cwd( vbyte *dir ) {
 	return chdir((pchar*)dir) == 0;
 }
 
-bool hl_sys_is64() {
+HL_PRIM bool hl_sys_is64() {
 #ifdef HL_64
 	return true;
 #else
@@ -255,7 +255,7 @@ bool hl_sys_is64() {
 #endif
 }
 
-int hl_sys_command( vbyte *cmd ) {
+HL_PRIM int hl_sys_command( vbyte *cmd ) {
 #ifdef HL_WIN
 	return system((pchar*)cmd);
 #else
@@ -264,20 +264,20 @@ int hl_sys_command( vbyte *cmd ) {
 #endif
 }
 
-bool hl_sys_exists( vbyte *path ) {
+HL_PRIM bool hl_sys_exists( vbyte *path ) {
 	pstat st;
 	return stat((pchar*)path,&st) == 0;
 }
 
-bool hl_sys_delete( vbyte *path ) {
+HL_PRIM bool hl_sys_delete( vbyte *path ) {
 	return unlink((pchar*)path) == 0;
 }
 
-bool hl_sys_rename( vbyte *path, vbyte *newname ) {
+HL_PRIM bool hl_sys_rename( vbyte *path, vbyte *newname ) {
 	return rename((pchar*)path,(pchar*)newname) == 0;
 }
 
-varray *hl_sys_stat( vbyte *path ) {
+HL_PRIM varray *hl_sys_stat( vbyte *path ) {
 	pstat s;
 	varray *a;
 	int *i;
@@ -299,22 +299,22 @@ varray *hl_sys_stat( vbyte *path ) {
 	return a;
 }
 
-bool hl_sys_is_dir( vbyte *path ) {
+HL_PRIM bool hl_sys_is_dir( vbyte *path ) {
 	pstat s;
 	if( stat((pchar*)path,&s) != 0 )
 		return false;
 	return (s.st_mode & S_IFDIR) != 0;
 }
 
-bool hl_sys_create_dir( vbyte *path, int mode ) {
+HL_PRIM bool hl_sys_create_dir( vbyte *path, int mode ) {
 	return mkdir((pchar*)path,mode) == 0;
 }
 
-bool hl_sys_remove_dir( vbyte *path ) {
+HL_PRIM bool hl_sys_remove_dir( vbyte *path ) {
 	return rmdir((pchar*)path) == 0;
 }
 
-double hl_sys_cpu_time() {
+HL_PRIM double hl_sys_cpu_time() {
 #ifdef HL_WIN
 	FILETIME unused;
 	FILETIME stime;
@@ -329,7 +329,7 @@ double hl_sys_cpu_time() {
 #endif
 }
 
-double hl_sys_thread_cpu_time() {
+HL_PRIM double hl_sys_thread_cpu_time() {
 #if defined(HL_WIN)
 	FILETIME unused;
 	FILETIME utime;
@@ -347,7 +347,7 @@ double hl_sys_thread_cpu_time() {
 #endif
 }
 
-varray *hl_sys_read_dir( vbyte *_path ) {
+HL_PRIM varray *hl_sys_read_dir( vbyte *_path ) {
 	pchar *path = (pchar*)_path;
 	int count = 0;
 	int pos = 0;
@@ -417,7 +417,7 @@ varray *hl_sys_read_dir( vbyte *_path ) {
 	return a;
 }
 
-vbyte *hl_sys_full_path( vbyte *path ) {
+HL_PRIM vbyte *hl_sys_full_path( vbyte *path ) {
 #ifdef HL_WIN
 	pchar buf[MAX_PATH+1];
 	if( GetFullPathNameW((pchar*)path,MAX_PATH+1,buf,NULL) == 0 )
@@ -431,7 +431,7 @@ vbyte *hl_sys_full_path( vbyte *path ) {
 #endif
 }
 
-vbyte *hl_sys_exe_path() {
+HL_PRIM vbyte *hl_sys_exe_path() {
 #if defined(HL_WIN)
 	pchar path[MAX_PATH];
 	if( GetModuleFileNameW(NULL,path,MAX_PATH) == 0 )
@@ -458,7 +458,7 @@ vbyte *hl_sys_exe_path() {
 #endif
 }
 
-int hl_sys_get_char( bool b ) {
+HL_PRIM int hl_sys_get_char( bool b ) {
 #	ifdef HL_WIN
 	return b?getche():getch();
 #	else
@@ -478,21 +478,10 @@ int hl_sys_get_char( bool b ) {
 #	endif
 }
 
-#ifndef HL_JIT
-
-#include <hlc.h>
-#if defined(HL_VCC) && defined(_DEBUG)
-#	include <crtdbg.h>
-#else
-#	define _CrtSetDbgFlag(x)
-#endif
-
-extern void hl_entry_point();
-
 static pchar **sys_args;
 static int sys_nargs;
 
-varray *hl_sys_args() {
+HL_PRIM varray *hl_sys_args() {
 	varray *a = hl_alloc_array(&hlt_bytes,sys_nargs);
 	int i;
 	for(i=0;i<sys_nargs;i++)
@@ -500,22 +489,7 @@ varray *hl_sys_args() {
 	return a;
 }
 
-#ifdef HL_WIN
-int wmain( int argc, uchar *argv[] ) {
-#else
-int main( int argc, char *argv[] ) {
-#endif
-	hl_trap_ctx ctx;
-	vdynamic *exc;
-	sys_args = argv + 1;
-	sys_nargs = argc - 1;
-	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF /*| _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF*/ );
-	hlc_trap(ctx,exc,on_exception);
-	hl_entry_point();
-	return 0;
-on_exception:
-	uprintf(USTR("Uncaught exception: %s\n"),hl_to_string(exc));
-	return 1;
+HL_PRIM void hl_sys_init(void **args, int nargs) {
+	sys_args = (pchar**)args;
+	sys_nargs = nargs;
 }
-
-#endif

+ 13 - 13
src/std/types.c

@@ -21,14 +21,14 @@
  */
 #include <hl.h>
 
-hl_type hlt_array = { HARRAY };
-hl_type hlt_bytes = { HBYTES };
-hl_type hlt_dynobj = { HDYNOBJ };
-hl_type hlt_dyn = { HDYN };
-hl_type hlt_i32 = { HI32 };
-hl_type hlt_f32 = { HF32 };
-hl_type hlt_f64 = { HF64 };
-hl_type hlt_void = { HVOID };
+HL_PRIM hl_type hlt_array = { HARRAY };
+HL_PRIM hl_type hlt_bytes = { HBYTES };
+HL_PRIM hl_type hlt_dynobj = { HDYNOBJ };
+HL_PRIM hl_type hlt_dyn = { HDYN };
+HL_PRIM hl_type hlt_i32 = { HI32 };
+HL_PRIM hl_type hlt_f32 = { HF32 };
+HL_PRIM hl_type hlt_f64 = { HF64 };
+HL_PRIM hl_type hlt_void = { HVOID };
 
 static const uchar *TSTR[] = {
 	USTR("void"), USTR("i8"), USTR("i16"), USTR("i32"), USTR("f32"), USTR("f64"),
@@ -72,7 +72,7 @@ int hl_pad_size( int pos, hl_type *t ) {
 	return 0;
 }
 
-bool hl_same_type( hl_type *a, hl_type *b ) {
+HL_PRIM bool hl_same_type( hl_type *a, hl_type *b ) {
 	if( a == b )
 		return true;
 	if( a->kind != b->kind )
@@ -118,7 +118,7 @@ bool hl_same_type( hl_type *a, hl_type *b ) {
 	return false;
 }
 
-bool hl_is_dynamic( hl_type *t ) {
+HL_PRIM bool hl_is_dynamic( hl_type *t ) {
 	static bool T_IS_DYNAMIC[] = {
 		false, // HVOID,
 		false, // HI8
@@ -143,7 +143,7 @@ bool hl_is_dynamic( hl_type *t ) {
 	return T_IS_DYNAMIC[t->kind];
 }
 
-bool hl_safe_cast( hl_type *t, hl_type *to ) {
+HL_PRIM bool hl_safe_cast( hl_type *t, hl_type *to ) {
 	if( t == to )
 		return true;
 	if( to->kind == HDYN )
@@ -256,7 +256,7 @@ static void hl_type_str_rec( hl_buffer *b, hl_type *t ) {
 	}
 }
 
-const uchar *hl_type_str( hl_type *t ) {
+HL_PRIM const uchar *hl_type_str( hl_type *t ) {
 	const uchar *c = TSTR[t->kind];
 	hl_buffer *b;
 	if( c != NULL )
@@ -354,7 +354,7 @@ HL_PRIM vdynamic *hl_type_get_global( hl_type *t ) {
 	return NULL;
 }
 
-bool hl_type_enum_eq( vdynamic *a, vdynamic *b ) {
+HL_PRIM bool hl_type_enum_eq( vdynamic *a, vdynamic *b ) {
 	int i;
 	venum *ea, *eb;
 	hl_enum_construct *c;