Forráskód Böngészése

complete and fix defined prims

Nicolas Cannasse 9 éve
szülő
commit
75c39f8141
27 módosított fájl, 371 hozzáadás és 155 törlés
  1. 7 4
      hl.vcxproj
  2. 3 0
      hl.vcxproj.filters
  3. 65 0
      libs/sdl/gl.c
  4. 1 1
      libs/sdl/sdl/GL.hx
  5. 2 2
      libs/sdl/sdl/Sdl.hx
  6. 2 2
      src/alloc.c
  7. 1 1
      src/callback.c
  8. 22 14
      src/hl.h
  9. 1 0
      src/hlmodule.h
  10. 32 79
      src/jit.c
  11. 8 10
      src/main.c
  12. 34 10
      src/module.c
  13. 3 3
      src/std/array.c
  14. 9 7
      src/std/bytes.c
  15. 4 0
      src/std/cast.c
  16. 9 1
      src/std/date.c
  17. 2 2
      src/std/error.c
  18. 16 0
      src/std/file.c
  19. 6 0
      src/std/fun.c
  20. 26 0
      src/std/maps.c
  21. 21 0
      src/std/math.c
  22. 13 3
      src/std/obj.c
  23. 8 3
      src/std/regexp.c
  24. 23 0
      src/std/socket.c
  25. 11 9
      src/std/string.c
  26. 30 0
      src/std/sys.c
  27. 12 4
      src/std/types.c

+ 7 - 4
hl.vcxproj

@@ -97,7 +97,7 @@
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>std.lib;sdl.lib;fmt.lib</AdditionalDependencies>
+      <AdditionalDependencies>std.lib</AdditionalDependencies>
       <StackReserveSize>0x200000</StackReserveSize>
     </Link>
   </ItemDefinitionGroup>
@@ -112,7 +112,7 @@
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>std.lib;sdl.lib;fmt.lib</AdditionalDependencies>
+      <AdditionalDependencies>std.lib</AdditionalDependencies>
       <StackReserveSize>0x200000</StackReserveSize>
     </Link>
   </ItemDefinitionGroup>
@@ -133,7 +133,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>std.lib;sdl.lib;fmt.lib</AdditionalDependencies>
+      <AdditionalDependencies>std.lib</AdditionalDependencies>
       <StackReserveSize>0x200000</StackReserveSize>
     </Link>
   </ItemDefinitionGroup>
@@ -153,13 +153,16 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>std.lib;sdl.lib;fmt.lib</AdditionalDependencies>
+      <AdditionalDependencies>std.lib</AdditionalDependencies>
       <StackReserveSize>0x200000</StackReserveSize>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="src\callback.c" />
     <ClCompile Include="src\code.c" />
+    <ClCompile Include="src\jit.c" />
     <ClCompile Include="src\main.c" />
+    <ClCompile Include="src\module.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\hlmodule.h" />

+ 3 - 0
hl.vcxproj.filters

@@ -3,6 +3,9 @@
   <ItemGroup>
     <ClCompile Include="src\main.c" />
     <ClCompile Include="src\code.c" />
+    <ClCompile Include="src\module.c" />
+    <ClCompile Include="src\jit.c" />
+    <ClCompile Include="src\callback.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\hlmodule.h" />

+ 65 - 0
libs/sdl/gl.c

@@ -364,3 +364,68 @@ HL_PRIM void HL_NAME(gl_uniform4fv)( vdynamic *u, vbyte *buffer, int bufPos, int
 HL_PRIM void HL_NAME(gl_draw_elements)( int mode, int count, int type, int start ) {
 	glDrawElements(mode, count, type, (void*)(int_val)start);
 }
+
+
+DEFINE_PRIM(_BOOL,gl_init,_NO_ARG);
+DEFINE_PRIM(_BOOL,gl_is_context_lost,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_clear,_I32);
+DEFINE_PRIM(_I32,gl_get_error,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_scissor,_I32 _I32 _I32 _I32);
+DEFINE_PRIM(_VOID,gl_clear_color,_F64 _F64 _F64 _F64);
+DEFINE_PRIM(_VOID,gl_clear_depth,_F64);
+DEFINE_PRIM(_VOID,gl_clear_stencil,_I32);
+DEFINE_PRIM(_VOID,gl_viewport,_I32 _I32 _I32 _I32);
+DEFINE_PRIM(_VOID,gl_finish,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_pixel_storei,_I32 _I32);
+DEFINE_PRIM(_VOID,gl_enable,_I32);
+DEFINE_PRIM(_VOID,gl_disable,_I32);
+DEFINE_PRIM(_VOID,gl_cull_face,_I32);
+DEFINE_PRIM(_VOID,gl_blend_func,_I32 _I32);
+DEFINE_PRIM(_VOID,gl_blend_func_separate,_I32 _I32 _I32 _I32);
+DEFINE_PRIM(_VOID,gl_blend_equation,_I32);
+DEFINE_PRIM(_VOID,gl_blend_equation_separate,_I32 _I32);
+DEFINE_PRIM(_VOID,gl_depth_mask,_BOOL);
+DEFINE_PRIM(_VOID,gl_depth_func,_I32);
+DEFINE_PRIM(_VOID,gl_color_mask,_BOOL _BOOL _BOOL _BOOL);
+DEFINE_PRIM(_NULL(_I32),gl_create_program,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_attach_shader,_NULL(_I32) _NULL(_I32));
+DEFINE_PRIM(_VOID,gl_link_program,_NULL(_I32));
+DEFINE_PRIM(_DYN,gl_get_program_parameter,_NULL(_I32) _I32);
+DEFINE_PRIM(_BYTES,gl_get_program_info_bytes,_NULL(_I32));
+DEFINE_PRIM(_NULL(_I32),gl_get_uniform_location,_NULL(_I32) _STRING);
+DEFINE_PRIM(_I32,gl_get_attrib_location,_NULL(_I32) _STRING);
+DEFINE_PRIM(_VOID,gl_use_program,_NULL(_I32));
+DEFINE_PRIM(_NULL(_I32),gl_create_shader,_I32);
+DEFINE_PRIM(_VOID,gl_shader_source,_NULL(_I32) _STRING);
+DEFINE_PRIM(_VOID,gl_compile_shader,_NULL(_I32));
+DEFINE_PRIM(_BYTES,gl_get_shader_info_bytes,_NULL(_I32));
+DEFINE_PRIM(_DYN,gl_get_shader_parameter,_NULL(_I32) _I32);
+DEFINE_PRIM(_VOID,gl_delete_shader,_NULL(_I32));
+DEFINE_PRIM(_NULL(_I32),gl_create_texture,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_active_texture,_I32);
+DEFINE_PRIM(_VOID,gl_bind_texture,_I32 _NULL(_I32));
+DEFINE_PRIM(_VOID,gl_tex_parameteri,_I32 _I32 _I32);
+DEFINE_PRIM(_VOID,gl_tex_image2d,_I32 _I32 _I32 _I32 _I32 _I32 _I32 _I32 _BYTES);
+DEFINE_PRIM(_VOID,gl_generate_mipmap,_I32);
+DEFINE_PRIM(_VOID,gl_delete_texture,_NULL(_I32));
+DEFINE_PRIM(_NULL(_I32),gl_create_framebuffer,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_bind_framebuffer,_I32 _NULL(_I32));
+DEFINE_PRIM(_VOID,gl_framebuffer_texture2d,_I32 _I32 _I32 _NULL(_I32) _I32);
+DEFINE_PRIM(_VOID,gl_delete_framebuffer,_NULL(_I32));
+DEFINE_PRIM(_NULL(_I32),gl_create_renderbuffer,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_bind_renderbuffer,_I32 _NULL(_I32));
+DEFINE_PRIM(_VOID,gl_renderbuffer_storage,_I32 _I32 _I32 _I32);
+DEFINE_PRIM(_VOID,gl_framebuffer_renderbuffer,_I32 _I32 _I32 _NULL(_I32));
+DEFINE_PRIM(_VOID,gl_delete_renderbuffer,_NULL(_I32));
+DEFINE_PRIM(_NULL(_I32),gl_create_buffer,_NO_ARG);
+DEFINE_PRIM(_VOID,gl_bind_buffer,_I32 _NULL(_I32));
+DEFINE_PRIM(_VOID,gl_buffer_data_size,_I32 _I32 _I32);
+DEFINE_PRIM(_VOID,gl_buffer_data,_I32 _I32 _BYTES _I32);
+DEFINE_PRIM(_VOID,gl_buffer_sub_data,_I32 _I32 _BYTES _I32 _I32);
+DEFINE_PRIM(_VOID,gl_enable_vertex_attrib_array,_I32);
+DEFINE_PRIM(_VOID,gl_disable_vertex_attrib_array,_I32);
+DEFINE_PRIM(_VOID,gl_vertex_attrib_pointer,_I32 _I32 _I32 _BOOL _I32 _I32);
+DEFINE_PRIM(_VOID,gl_delete_buffer,_NULL(_I32));
+DEFINE_PRIM(_VOID,gl_uniform1i,_NULL(_I32) _I32);
+DEFINE_PRIM(_VOID,gl_uniform4fv,_NULL(_I32) _BYTES _I32 _I32);
+DEFINE_PRIM(_VOID,gl_draw_elements,_I32 _I32 _I32 _I32);

+ 1 - 1
libs/sdl/sdl/GL.hx

@@ -226,7 +226,7 @@ class GL {
 	public static function bufferDataSize( target : Int, size : Int, param : Int ) {
 	}
 
-	public static function bufferData( target : Int, data : hl.types.Bytes, param : Int ) {
+	public static function bufferData( target : Int, size : Int, data : hl.types.Bytes, param : Int ) {
 	}
 
 	public static function bufferSubData( target : Int, offset : Int, data : hl.types.Bytes, srcOffset : Int, srcLength : Int ) {

+ 2 - 2
libs/sdl/sdl/Sdl.hx

@@ -8,11 +8,11 @@ class Sdl {
 	public static function init() {
 		if( initDone ) return;
 		initDone = true;
-		initOnce();
+		if( !initOnce() ) throw "Failed to init SDL";
 		isWin32 = detectWin32();
 	}
 
-	static function initOnce() {}
+	static function initOnce() return false;
 	static function eventLoop( e : Event ) return false;
 
 	public static function loop( callb : Void -> Void, ?onEvent : Event -> Void ) {

+ 2 - 2
src/alloc.c

@@ -821,7 +821,7 @@ void hl_free( hl_alloc *a ) {
 		a->cur = NULL;
 }
 
-void *hl_alloc_executable_memory( int size ) {
+HL_PRIM void *hl_alloc_executable_memory( int size ) {
 #ifdef HL_WIN
 	return VirtualAlloc(NULL,size,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
 #else
@@ -831,7 +831,7 @@ void *hl_alloc_executable_memory( int size ) {
 #endif
 }
 
-void hl_free_executable_memory( void *c, int size ) {
+HL_PRIM void hl_free_executable_memory( void *c, int size ) {
 #ifdef HL_WIN
 	VirtualFree(c,0,MEM_RELEASE);
 #else

+ 1 - 1
src/callback.c

@@ -19,7 +19,7 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-#include "hl.h"
+#include <hl.h>
 
 #define MAX_ARGS	16
 

+ 22 - 14
src/hl.h

@@ -299,11 +299,11 @@ struct hl_type {
 	void **vobj_proto;
 };
 
-int hl_type_size( hl_type *t );
-int hl_pad_size( int size, hl_type *t );
+HL_API int hl_type_size( hl_type *t );
+HL_API int hl_pad_size( int size, hl_type *t );
 
-hl_runtime_obj *hl_get_obj_rt( hl_type *ot );
-hl_runtime_obj *hl_get_obj_proto( hl_type *ot );
+HL_API hl_runtime_obj *hl_get_obj_rt( hl_type *ot );
+HL_API hl_runtime_obj *hl_get_obj_proto( hl_type *ot );
 
 /* -------------------- VALUES ------------------------------ */
 
@@ -520,7 +520,7 @@ HL_API const uchar *hl_type_str( hl_type *t );
 // ----------------------- FFI ------------------------------------------------------
 
 // match GNU C++ mangling
-#define TYPE_STR	"vcsifdbBDPOATR"
+#define TYPE_STR	"vcsifdbBDPOATR??X?N"
 
 #undef  _VOID
 #define _NO_ARG
@@ -531,16 +531,16 @@ HL_API const uchar *hl_type_str( hl_type *t );
 #define _F32						"f"
 #define _F64						"d"
 #define _BOOL						"b"
+#define _BYTES						"B"
 #define _DYN						"D"
 #define _FUN(t, args)				"P" args "_" t
 #define _OBJ(fields)				"O" fields "_"
-#define _BYTES						"B"
 #define _ARR						"A"
 #define _TYPE						"T"
 #define _REF(t)						"R" t
+#define _ABSTRACT(name)				"X" #name "_"
 #undef _NULL
 #define _NULL(t)					"N" t
-#define _ABSTRACT(name)				"X" #name "_"
 
 #define _STRING						_OBJ(_BYTES _I32)
 
@@ -550,26 +550,34 @@ typedef struct {
 	int length;
 } vstring;
 
+#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
+
 #ifndef HL_NAME
+#	define HL_NAME(p)					p
 #	ifdef HLDLL_EXPORTS
 #		define HL_PRIM				EXPORT
+#		undef DEFINE_PRIM
+#		define DEFINE_PRIM(t,name,args)						_DEFINE_PRIM_WITH_NAME(t,hl_##name,args,name)
+#		define DEFINE_PRIM_WITH_NAME						_DEFINE_PRIM_WITH_NAME
 #	else
 #		define HL_PRIM
+#		define DEFINE_PRIM_WITH_NAME(t,name,args,realName)
 #	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
+#define DEFINE_PRIM_WITH_NAME		_DEFINE_PRIM_WITH_NAME
 #endif
 
 // -------------- EXTRA ------------------------------------
 
-#define hl_fatal(msg)	hl_fatal_error(msg,__FILE__,__LINE__)
+#define hl_fatal(msg)			hl_fatal_error(msg,__FILE__,__LINE__)
+#define hl_fatal1(msg,p0)		hl_fatal_fmt(__FILE__,__LINE__,msg,p0)
+#define hl_fatal2(msg,p0,p1)	hl_fatal_fmt(__FILE__,__LINE__,msg,p0,p1)
+#define hl_fatal3(msg,p0,p1,p2)	hl_fatal_fmt(__FILE__,__LINE__,msg,p0,p1,p2)
+#define hl_fatal4(msg,p0,p1,p2,p3)	hl_fatal_fmt(__FILE__,__LINE__,msg,p0,p1,p2,p3)
 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_fatal_fmt( const char *file, int line, const char *fmt, ...);
 HL_API void hl_sys_init(void **args, int nargs);
 
 #endif

+ 1 - 0
src/hlmodule.h

@@ -77,6 +77,7 @@ typedef struct {
 	void **functions_ptrs;
 	int *functions_indexes;
 	void *jit_code;
+	hl_module_context ctx;
 } hl_module;
 
 typedef struct jit_ctx jit_ctx;

+ 32 - 79
src/jit.c

@@ -19,9 +19,9 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-#include "hl.h"
+#include <hlmodule.h>
 
-#ifdef _DEBUG
+#ifdef HL_DEBUG
 //#define OP_LOG
 //#define JIT_DEBUG
 #endif
@@ -1271,12 +1271,12 @@ static preg *op_binop( jit_ctx *ctx, vreg *dst, vreg *a, vreg *b, hl_opcode *op
 		case OSub: o = SUBSD; break;
 		case OMul: o = MULSD; break;
 		case OSDiv: o = DIVSD; break;
-		case OSGte:
-		case OSLt:
 		case OJSLt:
 		case OJSGte:
+		case OJSLte:
+		case OJSGt:
 		case OJEq:
-		case OJNeq:
+		case OJNotEq:
 			o = COMISD;
 			break;
 		default:
@@ -1332,18 +1332,14 @@ static preg *op_binop( jit_ctx *ctx, vreg *dst, vreg *a, vreg *b, hl_opcode *op
 			}
 			if( dst ) store(ctx, dst, PEAX, true);
 			return PEAX;
-		case OSGte:
-		case OSLt:
 		case OJSLt:
 		case OJSGte:
-		case OUGte:
-		case OULt:
+		case OJSLte:
+		case OJSGt:
 		case OJULt:
 		case OJUGte:
 		case OJEq:
-		case OJNeq:
-		case OEq:
-		case ONotEq:
+		case OJNotEq:
 			o = CMP;
 			break;
 		default:
@@ -1446,28 +1442,28 @@ static int do_jump( jit_ctx *ctx, hl_op op, bool isFloat ) {
 	case OJAlways:
 		XJump(JAlways,j);
 		break;
-	case OSGte:
 	case OJSGte:
 		XJump(isFloat ? JUGte : JSGte,j);
 		break;
-	case OUGte:
+	case OJSGt:
+		XJump(isFloat ? JUGt : JSGt,j);
+		break;
 	case OJUGte:
 		XJump(JUGte,j);
 		break;
-	case OSLt:
 	case OJSLt:
 		XJump(isFloat ? JULt : JSLt,j);
 		break;
-	case OULt:
+	case OJSLte:
+		XJump(isFloat ? JULte : JSLte,j);
+		break;
 	case OJULt:
 		XJump(JULt,j);
 		break;
-	case OEq:
 	case OJEq:
 		XJump(JEq,j);
 		break;
-	case ONotEq:
-	case OJNeq:
+	case OJNotEq:
 		XJump(JNeq,j);
 		break;
 	default:
@@ -1478,17 +1474,6 @@ static int do_jump( jit_ctx *ctx, hl_op op, bool isFloat ) {
 	return j;
 }
 
-static void op_cmp( jit_ctx *ctx, hl_opcode *op ) {
-	int p, e;
-	op_binop(ctx,NULL,R(op->p2),R(op->p3),op);
-	p = do_jump(ctx,op->op,IS_FLOAT(R(op->p2)));
-	store_const(ctx, R(op->p1), 0);
-	e = do_jump(ctx,OJAlways,false);
-	patch_jump(ctx,p);
-	store_const(ctx, R(op->p1), 1);
-	patch_jump(ctx,e);
-}
-
 static void register_jump( jit_ctx *ctx, int pos, int target ) {
 	jlist *j = (jlist*)hl_malloc(&ctx->falloc, sizeof(jlist));
 	j->pos = pos;
@@ -1771,14 +1756,6 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				store(ctx,dst,v,true);
 			}
 			break;
-		case OEq:
-		case ONotEq:
-		case OSGte:
-		case OSLt:
-		case OUGte:
-		case OULt:
-			op_cmp(ctx, o);
-			break;
 		case OJFalse:
 		case OJTrue:
 		case OJNotNull:
@@ -1791,9 +1768,11 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 			}
 			break;
 		case OJEq:
-		case OJNeq:
+		case OJNotEq:
 		case OJSLt:
 		case OJSGte:
+		case OJSLte:
+		case OJSGt:
 		case OJULt:
 		case OJUGte:
 			op_binop(ctx, NULL, dst, ra, o);
@@ -1825,7 +1804,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				store(ctx, dst, PEAX, true);
 			}
 			break;
-		case OToFloat:
+		case OToSFloat:
 			{
 				preg *r = alloc_cpu(ctx,ra,true);
 				preg *w = alloc_fpu(ctx,dst,false);
@@ -1914,7 +1893,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				ASSERT(dst->t->kind);
 			}
 			break;
-		case OGetFunction:
+/*		case OGetFunction:
 			{
 				int_val args[2] = { (int_val)m, (int_val)o->p2 };
 				call_native_consts(ctx, hl_alloc_closure_void, args, 2);
@@ -1950,7 +1929,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				store(ctx, dst, PEAX, true);
 			}
 			break;
-		case OCallClosure:
+*/		case OCallClosure:
 			op_call_closure(ctx,dst,ra,o->p3,o->extra);
 			break;
 		case OField:
@@ -1958,7 +1937,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				switch( ra->t->kind ) {
 				case HOBJ:
 					{
-						hl_runtime_obj *rt = hl_get_obj_rt(m, ra->t);
+						hl_runtime_obj *rt = hl_get_obj_rt(ra->t);
 						preg *rr = alloc_cpu(ctx,ra, true);
 						copy_to(ctx,dst,pmem(&p, (CpuReg)rr->id, rt->fields_indexes[o->p3]));
 					}
@@ -1996,7 +1975,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				switch( dst->t->kind ) {
 				case HOBJ:
 					{
-						hl_runtime_obj *rt = hl_get_obj_rt(m, dst->t);
+						hl_runtime_obj *rt = hl_get_obj_rt(dst->t);
 						preg *rr = alloc_cpu(ctx, dst, true);
 						copy_from(ctx, pmem(&p, (CpuReg)rr->id, rt->fields_indexes[o->p2]), rb);
 					}
@@ -2032,7 +2011,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 		case OGetThis:
 			{
 				vreg *r = R(0);
-				hl_runtime_obj *rt = hl_get_obj_rt(m, r->t);
+				hl_runtime_obj *rt = hl_get_obj_rt(r->t);
 				preg *rr = alloc_cpu(ctx,r, true);
 				copy_to(ctx,dst,pmem(&p, (CpuReg)rr->id, rt->fields_indexes[o->p2]));
 			}
@@ -2040,7 +2019,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 		case OSetThis:
 			{
 				vreg *r = R(0);
-				hl_runtime_obj *rt = hl_get_obj_rt(m, r->t);
+				hl_runtime_obj *rt = hl_get_obj_rt(r->t);
 				preg *rr = alloc_cpu(ctx, r, true);
 				copy_from(ctx, pmem(&p, (CpuReg)rr->id, rt->fields_indexes[o->p1]), ra);
 			}
@@ -2078,7 +2057,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				store(ctx, dst, IS_FLOAT(dst) ? PXMM(0) : PEAX, true);
 			}
 			break;
-		case OMethod:
+/*		case OMethod:
 			switch( ra->t->kind ) {
 			case HVIRTUAL:
 				{
@@ -2099,24 +2078,12 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				ASSERT(ra->t->kind);
 			}
 			break;
-		case OThrow:
+*/		case OThrow:
 			{
 				int size = prepare_call_args(ctx,1,&o->p1,ctx->vregs,true);
 				call_native(ctx,hl_throw,size);
 			}
 			break;
-		case OError:
-			{
-#				ifdef HL_64
-				int size = pad_stack(ctx, 0);
-				op64(ctx,MOV,REG_AT(CALL_REGS[0]),pconst64(&p,(int_val)m->code->strings[o->p1]));
-#				else
-				int size = pad_stack(ctx, HL_WSIZE);
-				op32(ctx,PUSH,pconst(&p,(int)(int_val)m->code->strings[o->p1]), UNUSED);
-#				endif
-				call_native(ctx,hl_error_msg,size);
-			}
-			break;
 		case OLabel:
 			// NOP for now
 			discard_regs(ctx,false);
@@ -2189,28 +2156,14 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				op32(ctx,PUSH,fetch(ra),UNUSED);
 				op32(ctx,PUSH,pconst(&p,(int)(int_val)dst->t),UNUSED);
 #				endif
-				if( ra->t->kind == HOBJ ) hl_get_obj_rt(ctx->m, ra->t); // ensure it's initialized
+				if( ra->t->kind == HOBJ ) hl_get_obj_rt(ra->t); // ensure it's initialized
 				call_native(ctx,hl_to_virtual,size);
 				store(ctx,dst,PEAX,true);
 			}
 			break;
-		case OUnVirtual:
-			{
-				preg *v = alloc_cpu(ctx,ra,true);
-				int jnz, jend;
-				op64(ctx,TEST,v,v);
-				XJump_small(JNotZero,jnz);
-				op64(ctx,XOR,alloc_cpu(ctx, dst, false),alloc_cpu(ctx, dst, false));
-				XJump_small(JAlways,jend);
-				patch_jump(ctx,jnz);
-				op64(ctx,MOV,alloc_cpu(ctx, dst, false),pmem(&p,v->id,HL_WSIZE));
-				patch_jump(ctx,jend);
-				store(ctx,dst,dst->current,false);
-			}
-			break;
-		case ODynGet:
+/*		case ODynGet:
 			{
-				int hfield = hl_hash(m->code->strings[o->p3],false);
+				int hfield = hl_hash_gen(m->code->ustrings[o->p3],false);
 #				ifdef HL_64
 				int size = pad_stack(ctx, 0);
 				op64(ctx,MOV,REG_AT(CALL_REGS[0]),fetch(ra));
@@ -2223,7 +2176,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				op32(ctx,PUSH,fetch(ra),UNUSED);
 #				endif
 				if( dst->size == 8 ) {
-					call_native(ctx,hl_dyn_get64,size);
+					call_native(ctx,hl_dyn_getd,size);
 #					ifdef HL_64
 					store(ctx,dst,PEAX,true);
 #					else
@@ -2268,7 +2221,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 					call_native(ctx,hl_dyn_set32,size);
 			}
 			break;
-		default:
+*/		default:
 			printf("Don't know how to jit %s\n",hl_op_name(o->op));
 			break;
 		}

+ 8 - 10
src/main.c

@@ -74,7 +74,7 @@ int main(int argc, char *argv[]) {
 #endif
 	struct {
 		hl_code *code;
-//		hl_module *m;
+		hl_module *m;
 		vdynamic *exc;
 	} ctx;
 	if( argc == 1 ) {
@@ -90,15 +90,13 @@ int main(int argc, char *argv[]) {
 	ctx.code = load_code(argv[1]);
 	if( ctx.code == NULL )
 		return 1;
-/*
-	m = hl_module_alloc(code);
-	if( m == NULL )
-		return 4;
-	if( !hl_module_init(m) )
-		return 5;
-	hl_callback(m->functions_ptrs[m->code->entrypoint],0,NULL);
-	hl_module_free(m);
-*/
+	ctx.m = hl_module_alloc(ctx.code);
+	if( ctx.m == NULL )
+		return 2;
+	if( !hl_module_init(ctx.m) )
+		return 3;
+	hl_callback(ctx.m->functions_ptrs[ctx.m->code->entrypoint],0,NULL);
+	hl_module_free(ctx.m);
 	hl_free(&ctx.code->alloc);
 	hl_global_free();
 	return 0;

+ 34 - 10
src/module.c

@@ -19,7 +19,7 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-#include "hl.h"
+#include <hlmodule.h>
 
 #ifdef HL_WIN
 #	include <windows.h>
@@ -55,12 +55,16 @@ hl_module *hl_module_alloc( hl_code *c ) {
 	memset(m->globals_data,0,gsize);
 	m->functions_ptrs = (void**)malloc(sizeof(void*)*(c->nfunctions + c->nnatives));
 	m->functions_indexes = (int*)malloc(sizeof(int)*(c->nfunctions + c->nnatives));
-	if( m->functions_ptrs == NULL || m->functions_indexes == NULL ) {
+	m->ctx.functions_types = (hl_type**)malloc(sizeof(void*)*(c->nfunctions + c->nnatives));
+	if( m->functions_ptrs == NULL || m->functions_indexes == NULL || m->ctx.functions_types == NULL ) {
 		hl_module_free(m);
 		return NULL;
 	}
 	memset(m->functions_ptrs,0,sizeof(void*)*(c->nfunctions + c->nnatives));
 	memset(m->functions_indexes,0xFF,sizeof(int)*(c->nfunctions + c->nnatives));
+	memset(m->ctx.functions_types,0,sizeof(void*)*(c->nfunctions + c->nnatives));
+	hl_alloc_init(&m->ctx.alloc);
+	m->ctx.functions_ptrs = m->functions_ptrs;
 	return m;
 }
 
@@ -75,14 +79,26 @@ static void append_type( char **p, hl_type *t ) {
 		{
 			int i;
 			for(i=0;i<t->fun->nargs;i++)
-				append_type(p,(&t->fun->args)[i]);
+				append_type(p,t->fun->args[i]);
 			*(*p)++ = '_';
 			append_type(p,t->fun->ret);
 			break;
 		}
-	case HARRAY:
 	case HREF:
-		append_type(p,t->t);
+	case HNULL:
+		append_type(p,t->tparam);
+		break;
+	case HOBJ:
+		{
+			int i;
+			for(i=0;i<t->obj->nfields;i++)
+				append_type(p,t->obj->fields[i].t);
+			*(*p)++ = '_';
+		}
+		break;
+	case HABSTRACT:
+		*p += utostr(*p,100,t->abs_name);
+		*(*p)++ = '_';
 		break;
 	default:
 		break;
@@ -95,7 +111,7 @@ int hl_module_init( hl_module *m ) {
 	// RESET globals
 	for(i=0;i<m->code->nglobals;i++) {
 		hl_type *t = m->code->globals[i];
-		if( t->kind == HFUN ) *(fptr*)(m->globals_data + m->globals_indexes[i]) = null_function;
+		if( t->kind == HFUN ) *(void**)(m->globals_data + m->globals_indexes[i]) = null_function;
 	}
 	// INIT natives
 	{
@@ -114,9 +130,9 @@ int hl_module_init( hl_module *m ) {
 #				else
 				strcpy(tmp+strlen(tmp),".hdll");
 #				endif
-				libHandler = dlopen(memcmp(n->lib,"std",4) == 0 ? NULL : tmp,RTLD_LAZY);
+				libHandler = dlopen(tmp,RTLD_LAZY);
 				if( libHandler == NULL )
-					hl_error("Failed to load library %s",tmp);
+					hl_fatal1("Failed to load library %s",tmp);
 			}
 			strcpy(p,"hlp_");
 			p += 4;
@@ -125,23 +141,29 @@ int hl_module_init( hl_module *m ) {
 			*p++ = 0;
 			f = dlsym(libHandler,tmp);
 			if( f == NULL )
-				hl_error("Failed to load function %s@%s",n->lib,n->name);
+				hl_fatal2("Failed to load function %s@%s",n->lib,n->name);
 			m->functions_ptrs[n->findex] = ((void *(*)( const char **p ))f)(&sign);
 			p = tmp;
 			append_type(&p,n->t);
 			*p++ = 0;
 			if( memcmp(sign,tmp,strlen(sign)+1) != 0 )
-				hl_error("Invalid signature for function %s@%s : %s should be %s",n->lib,n->name,tmp,sign);
+				hl_fatal4("Invalid signature for function %s@%s : %s required but %s found",n->lib,n->name,tmp,sign);
 		}
 	}
 	// INIT indexes
 	for(i=0;i<m->code->nfunctions;i++) {
 		hl_function *f = m->code->functions + i;
 		m->functions_indexes[f->findex] = i;
+		m->ctx.functions_types[f->findex] = f->type;
 	}
 	for(i=0;i<m->code->nnatives;i++) {
 		hl_native *n = m->code->natives + i;
 		m->functions_indexes[n->findex] = i + m->code->nfunctions;
+		m->ctx.functions_types[n->findex] = n->t;
+	}
+	for(i=0;i<m->code->ntypes;i++) {
+		hl_type *t = m->code->types + i;
+		if( t->kind == HOBJ ) t->obj->m = &m->ctx;
 	}
 	// JIT
 	ctx = hl_jit_alloc();
@@ -169,9 +191,11 @@ int hl_module_init( hl_module *m ) {
 }
 
 void hl_module_free( hl_module *m ) {
+	hl_free(&m->ctx.alloc);
 	hl_free_executable_memory(m->code, m->codesize);
 	free(m->functions_indexes);
 	free(m->functions_ptrs);
+	free(m->ctx.functions_types);
 	free(m->globals_indexes);
 	free(m->globals_data);
 	free(m);

+ 3 - 3
src/std/array.c

@@ -39,6 +39,6 @@ HL_PRIM hl_type *hl_array_type( varray *a ) {
 	return a->at;
 }
 
-DEFINE_PRIM(_ARR(_DYN),hl_aalloc,_TYPE _I32);
-DEFINE_PRIM(_VOID,hl_ablit,_ARR(_DYN) _I32 _ARR(_DYN) _I32 _I32);
-DEFINE_PRIM(_TYPE,hl_atype,_ARR);
+DEFINE_PRIM(_ARR,alloc_array,_TYPE _I32);
+DEFINE_PRIM(_VOID,array_blit,_ARR _I32 _ARR _I32 _I32);
+DEFINE_PRIM(_TYPE,array_type,_ARR);

+ 9 - 7
src/std/bytes.c

@@ -186,10 +186,12 @@ HL_PRIM vdynamic *hl_parse_int( vbyte *bytes, int pos, int len ) {
 	return c == end ? NULL : hl_make_dyn(&h,&hlt_i32);
 }
 
-DEFINE_PRIM(_BYTES,hl_balloc,_I32);
-DEFINE_PRIM(_VOID,hl_bblit,_BYTES _I32 _BYTES _I32 _I32);
-DEFINE_PRIM(_I32,hl_bytes_compare,_BYTES _I32 _BYTES _I32 _I32);
-DEFINE_PRIM(_I32,hl_bytes_find,_BYTES _I32 _I32 _BYTES _I32 _I32);
-DEFINE_PRIM(_VOID,hl_bytes_fill,_BYTES _I32 _I32 _I32);
-DEFINE_PRIM(_VOID,hl_bsort_i32,_BYTES _I32 _I32 _FUN(_I32,_I32 _I32));
-DEFINE_PRIM(_VOID,hl_bsort_f64,_BYTES _I32 _I32 _FUN(_I32,_F64 _F64));
+DEFINE_PRIM(_BYTES,alloc_bytes,_I32);
+DEFINE_PRIM(_VOID,bytes_blit,_BYTES _I32 _BYTES _I32 _I32);
+DEFINE_PRIM(_I32,bytes_compare,_BYTES _I32 _BYTES _I32 _I32);
+DEFINE_PRIM(_I32,bytes_find,_BYTES _I32 _I32 _BYTES _I32 _I32);
+DEFINE_PRIM(_VOID,bytes_fill,_BYTES _I32 _I32 _I32);
+DEFINE_PRIM(_F64, parse_float,_BYTES _I32 _I32);
+DEFINE_PRIM(_NULL(_I32), parse_int, _BYTES _I32 _I32);
+DEFINE_PRIM(_VOID,bsort_i32,_BYTES _I32 _I32 _FUN(_I32,_I32 _I32));
+DEFINE_PRIM(_VOID,bsort_f64,_BYTES _I32 _I32 _FUN(_I32,_F64 _F64));

+ 4 - 0
src/std/cast.c

@@ -350,3 +350,7 @@ HL_PRIM vdynamic* hl_value_cast( vdynamic *v, hl_type *t ) {
 HL_PRIM bool hl_type_safe_cast( hl_type *a, hl_type *b ) {
 	return hl_safe_cast(a,b);
 }
+
+DEFINE_PRIM(_I32, dyn_compare, _DYN _DYN);
+DEFINE_PRIM(_DYN, value_cast, _DYN _TYPE);
+DEFINE_PRIM(_BOOL, type_safe_cast, _TYPE _TYPE);

+ 9 - 1
src/std/date.c

@@ -68,7 +68,7 @@ HL_PRIM int hl_date_from_time( double time ) {
 	return (int)(time / 1000.);
 }
 
-HL_PRIM int hl_date_from_string( vbyte *b ) {
+HL_PRIM int hl_date_from_string( vbyte *b, int len ) {
 	uchar *str = (uchar*)b;
 	hl_fatal("TODO");
 	return *str;
@@ -100,3 +100,11 @@ HL_PRIM void hl_date_get_inf( int date, int *y, int *mo, int *day, int *h, int *
 	if( s ) *s = t.tm_sec;
 	if( wday ) *wday = t.tm_wday;
 }
+
+DEFINE_PRIM(_I32, date_now, _NO_ARG);
+DEFINE_PRIM(_BYTES, date_to_string, _I32 _REF(_I32));
+DEFINE_PRIM(_F64, date_get_time, _I32);
+DEFINE_PRIM(_I32, date_from_time, _F64);
+DEFINE_PRIM(_I32, date_from_string, _BYTES _I32);
+DEFINE_PRIM(_I32, date_new, _I32 _I32 _I32 _I32 _I32 _I32);
+DEFINE_PRIM(_VOID, date_get_inf, _I32 _REF(_I32) _REF(_I32) _REF(_I32) _REF(_I32) _REF(_I32) _REF(_I32) _REF(_I32));

+ 2 - 2
src/std/error.c

@@ -164,11 +164,11 @@ HL_PRIM void hl_error_msg( const uchar *fmt, ... ) {
 	hl_throw(d);
 }
 
-HL_PRIM void hl_fatal_fmt(const char *fmt, ...) {
+HL_PRIM void hl_fatal_fmt( const char *file, int line, const char *fmt, ...) {
 	char buf[256];
 	va_list args;
 	va_start(args, fmt);
 	vsprintf(buf,fmt, args);
 	va_end(args);
-	hl_fatal(buf);
+	hl_fatal_error(buf,file,line);
 }

+ 16 - 0
src/std/file.c

@@ -136,3 +136,19 @@ HL_PRIM vbyte *hl_file_contents( vbyte *name, int *size ) {
 	fclose(f);
 	return content;
 }
+
+#define _FILE _ABSTRACT(hl_fdesc)
+DEFINE_PRIM(_FILE, file_open, _BYTES _I32 _BOOL);
+DEFINE_PRIM(_VOID, file_close, _FILE);
+DEFINE_PRIM(_I32, file_write, _FILE _BYTES _I32 _I32);
+DEFINE_PRIM(_I32, file_read, _FILE _BYTES _I32 _I32);
+DEFINE_PRIM(_BOOL, file_write_char, _FILE _I32);
+DEFINE_PRIM(_I32, file_read_char, _FILE);
+DEFINE_PRIM(_BOOL, file_seek, _FILE _I32 _I32);
+DEFINE_PRIM(_I32, file_tell, _FILE);
+DEFINE_PRIM(_BOOL, file_eof, _FILE);
+DEFINE_PRIM(_BOOL, file_flush, _FILE);
+DEFINE_PRIM(_FILE, file_stdin, _NO_ARG);
+DEFINE_PRIM(_FILE, file_stdout, _NO_ARG);
+DEFINE_PRIM(_FILE, file_stderr, _NO_ARG);
+DEFINE_PRIM(_BYTES, file_contents, _BYTES _REF(_I32));

+ 6 - 0
src/std/fun.c

@@ -274,3 +274,9 @@ HL_PRIM vdynamic *hl_make_var_args( vclosure *c ) {
 	hlt_var_fun.closure_type.p = &hlt_var_fun;
 	return (vdynamic*)hl_alloc_closure_ptr(&hlt_var_args,fun_var_args,c);
 }
+
+DEFINE_PRIM(_DYN, no_closure, _DYN);
+DEFINE_PRIM(_DYN, get_closure_value, _DYN);
+DEFINE_PRIM(_BOOL, fun_compare, _DYN _DYN);
+DEFINE_PRIM(_DYN, make_var_args, _FUN(_DYN,_ARR));
+DEFINE_PRIM(_DYN, call_method, _DYN _ARR);

+ 26 - 0
src/std/maps.c

@@ -642,3 +642,29 @@ HL_PRIM varray* hl_hovalues( hl_obj_map *m ) {
 	return a;
 }
 
+#define _BMAP _ABSTRACT(hl_bytes_map)
+DEFINE_PRIM( _BMAP, hballoc, _NO_ARG );
+DEFINE_PRIM( _VOID, hbset, _BMAP _BYTES _DYN );
+DEFINE_PRIM( _BOOL, hbexists, _BMAP _BYTES );
+DEFINE_PRIM( _DYN, hbget, _BMAP _BYTES );
+DEFINE_PRIM( _BOOL, hbremove, _BMAP _BYTES );
+DEFINE_PRIM( _ARR, hbkeys, _BMAP );
+DEFINE_PRIM( _ARR, hbvalues, _BMAP );
+
+#define _IMAP _ABSTRACT(hl_int_map)
+DEFINE_PRIM( _IMAP, hialloc, _NO_ARG );
+DEFINE_PRIM( _VOID, hiset, _IMAP _I32 _DYN );
+DEFINE_PRIM( _BOOL, hiexists, _IMAP _I32 );
+DEFINE_PRIM( _DYN, higet, _IMAP _I32 );
+DEFINE_PRIM( _BOOL, hiremove, _IMAP _I32 );
+DEFINE_PRIM( _ARR, hikeys, _IMAP );
+DEFINE_PRIM( _ARR, hivalues, _IMAP );
+
+#define _OMAP _ABSTRACT(hl_obj_map)
+DEFINE_PRIM( _OMAP, hoalloc, _NO_ARG );
+DEFINE_PRIM( _VOID, hoset, _OMAP _DYN _DYN );
+DEFINE_PRIM( _BOOL, hoexists, _OMAP _DYN );
+DEFINE_PRIM( _DYN, hoget, _OMAP _DYN );
+DEFINE_PRIM( _BOOL, horemove, _OMAP _DYN );
+DEFINE_PRIM( _ARR, hokeys, _OMAP );
+DEFINE_PRIM( _ARR, hovalues, _OMAP );

+ 21 - 0
src/std/math.c

@@ -128,3 +128,24 @@ HL_PRIM double hl_math_sqrt( double a ) {
 	return sqrt(a);
 }
 
+DEFINE_PRIM(_F64, nan, _NO_ARG);
+DEFINE_PRIM(_F64, math_abs, _F64);
+DEFINE_PRIM(_BOOL, math_isnan, _F64);
+DEFINE_PRIM(_BOOL, math_isfinite, _F64);
+DEFINE_PRIM(_F64, math_fceil, _F64);
+DEFINE_PRIM(_F64, math_fround, _F64);
+DEFINE_PRIM(_F64, math_ffloor, _F64);
+DEFINE_PRIM(_I32, math_round, _F64);
+DEFINE_PRIM(_I32, math_ceil, _F64);
+DEFINE_PRIM(_I32, math_floor, _F64);
+DEFINE_PRIM(_F64, math_cos, _F64);
+DEFINE_PRIM(_F64, math_sin, _F64);
+DEFINE_PRIM(_F64, math_tan, _F64);
+DEFINE_PRIM(_F64, math_acos, _F64);
+DEFINE_PRIM(_F64, math_asin, _F64);
+DEFINE_PRIM(_F64, math_atan, _F64);
+DEFINE_PRIM(_F64, math_atan2, _F64 _F64);
+DEFINE_PRIM(_F64, math_pow, _F64 _F64);
+DEFINE_PRIM(_F64, math_log, _F64);
+DEFINE_PRIM(_F64, math_exp, _F64);
+DEFINE_PRIM(_F64, math_sqrt, _F64);

+ 13 - 3
src/std/obj.c

@@ -123,7 +123,7 @@ HL_PRIM void hl_cache_free() {
 	Builds class metadata (fields indexes, etc.)
 	Does not require the method table to be finalized.
 **/
-hl_runtime_obj *hl_get_obj_rt( hl_type *ot ) {
+HL_PRIM hl_runtime_obj *hl_get_obj_rt( hl_type *ot ) {
 	hl_type_obj *o = ot->obj;
 	hl_module_context *m = o->m;
 	hl_alloc *alloc = &m->alloc;
@@ -197,7 +197,7 @@ hl_runtime_obj *hl_get_obj_rt( hl_type *ot ) {
 	Fill class prototype with method pointers.
 	Requires method table to be finalized
 **/
-hl_runtime_obj *hl_get_obj_proto( hl_type *ot ) {
+HL_API hl_runtime_obj *hl_get_obj_proto( hl_type *ot ) {
 	hl_type_obj *o = ot->obj;
 	hl_module_context *m = o->m;
 	hl_alloc *alloc = &m->alloc;
@@ -350,7 +350,7 @@ vvirtual *hl_to_virtual( hl_type *vt, vdynamic *obj ) {
 		if( hl_safe_cast(obj->t, vt) ) return (vvirtual*)obj;
 		return hl_to_virtual(vt,hl_virtual_make_value((vvirtual*)obj));
 	default:
-		hl_fatal_fmt("Don't know how to virtual %d",obj->t->kind);
+		hl_fatal1("Don't know how to virtual %d",obj->t->kind);
 	}
 	return v;
 }
@@ -863,3 +863,13 @@ HL_PRIM vdynamic *hl_obj_copy( vdynamic *obj ) {
 HL_PRIM vdynamic *hl_get_virtual_value( vdynamic *v ) {
 	return ((vvirtual*)v)->value;
 }
+
+DEFINE_PRIM(_DYN, alloc_obj, _TYPE);
+DEFINE_PRIM(_DYN, obj_get_field, _DYN _I32);
+DEFINE_PRIM(_VOID, obj_set_field, _DYN _I32 _DYN);
+DEFINE_PRIM(_BOOL, obj_has_field, _DYN _I32);
+DEFINE_PRIM(_BOOL, obj_delete_field, _DYN _I32);
+DEFINE_PRIM(_ARR, obj_fields, _DYN);
+DEFINE_PRIM(_DYN, obj_copy, _DYN);
+DEFINE_PRIM(_DYN, get_virtual_value, _DYN);
+DEFINE_PRIM(_I32, hash, _BYTES);

+ 8 - 3
src/std/regexp.c

@@ -40,7 +40,7 @@ static void regexp_finalize( ereg *e ) {
 	free(e->matches);
 }
 
-HL_PRIM ereg *regexp_regexp_new_options( vbyte *str, vbyte *opts ) {
+HL_PRIM ereg *hl_regexp_new_options( vbyte *str, vbyte *opts ) {
 	ereg *r;
 	const char *error;
 	int err_offset;
@@ -91,7 +91,7 @@ HL_PRIM ereg *regexp_regexp_new_options( vbyte *str, vbyte *opts ) {
 	return r;
 }
 
-HL_PRIM int regexp_regexp_matched_pos( ereg *e, int m, int *len ) {
+HL_PRIM int hl_regexp_matched_pos( ereg *e, int m, int *len ) {
 	int start;
 	if( !e->matched )
 		hl_error("Calling matchedPos() on an unmatched regexp"); 
@@ -102,7 +102,7 @@ HL_PRIM int regexp_regexp_matched_pos( ereg *e, int m, int *len ) {
 	return start;
 }
 
-HL_PRIM bool regexp_regexp_match( ereg *e, vbyte *s, int pos, int len ) {
+HL_PRIM bool hl_regexp_match( ereg *e, vbyte *s, int pos, int len ) {
 	int res = pcre16_exec(e->p,&limit,(PCRE_SPTR16)s,pos+len,pos,0,e->matches,e->nmatches * 3);
 	e->matched = res >= 0;
 	if( res >= 0 )
@@ -112,3 +112,8 @@ HL_PRIM bool regexp_regexp_match( ereg *e, vbyte *s, int pos, int len ) {
 	return false;
 }
 
+#define _EREG _ABSTRACT(ereg)
+DEFINE_PRIM( _EREG, regexp_new_options, _BYTES _BYTES);
+DEFINE_PRIM( _I32, regexp_matched_pos, _EREG _I32 _REF(_I32));
+DEFINE_PRIM( _BOOL, regexp_match, _EREG _BYTES _I32 _I32);
+

+ 23 - 0
src/std/socket.c

@@ -301,3 +301,26 @@ HL_PRIM bool hl_socket_set_fast_send( hl_socket *s, bool b ) {
 	int fast = b;
 	return setsockopt(s->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&fast,sizeof(fast)) == 0;
 }
+
+#define _SOCK	_ABSTRACT(hl_socket)
+DEFINE_PRIM(_VOID,socket_init,_NO_ARG);
+DEFINE_PRIM(_SOCK,socket_new,_BOOL);
+DEFINE_PRIM(_VOID,socket_close,_SOCK);
+DEFINE_PRIM(_I32,socket_send_char,_SOCK _I32);
+DEFINE_PRIM(_I32,socket_send,_SOCK _BYTES _I32 _I32 );
+DEFINE_PRIM(_I32,socket_recv,_SOCK _BYTES _I32 _I32 );
+DEFINE_PRIM(_I32,socket_recv_char, _SOCK);
+DEFINE_PRIM(_I32,host_resolve,_BYTES);
+DEFINE_PRIM(_BYTES,host_to_string,_I32);
+DEFINE_PRIM(_BYTES,host_reverse,_I32);
+DEFINE_PRIM(_BYTES,host_local,_NO_ARG);
+DEFINE_PRIM(_BOOL,socket_connect,_SOCK _I32 _I32);
+DEFINE_PRIM(_BOOL,socket_listen,_SOCK _I32);
+DEFINE_PRIM(_BOOL,socket_bind,_SOCK _I32 _I32);
+DEFINE_PRIM(_SOCK,socket_accept,_SOCK);
+DEFINE_PRIM(_BOOL,socket_peer,_SOCK _REF(_I32) _REF(_I32));
+DEFINE_PRIM(_BOOL,socket_host,_SOCK _REF(_I32) _REF(_I32));
+DEFINE_PRIM(_BOOL,socket_set_timeout,_SOCK _F64);
+DEFINE_PRIM(_BOOL,socket_shutdown,_SOCK _BOOL _BOOL);
+DEFINE_PRIM(_BOOL,socket_set_blocking,_SOCK _BOOL);
+DEFINE_PRIM(_BOOL,socket_set_fast_send,_SOCK _BOOL);

+ 11 - 9
src/std/string.c

@@ -201,7 +201,6 @@ HL_PRIM char *hl_to_utf8( uchar *bytes ) {
 	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;
@@ -305,12 +304,15 @@ HL_PRIM vbyte *hl_url_decode( vbyte *str, int *len ) {
 	hl_error("Malformed URL encoded");
 	return NULL;
 }
-	
 
-DEFINE_PRIM(_BYTES,hl_itos,_I32 _REF(_I32));
-DEFINE_PRIM(_BYTES,hl_ftos,_F64 _REF(_I32));
-DEFINE_PRIM(_BYTES,hl_value_to_string,_DYN _REF(_I32));
-DEFINE_PRIM(_I32,hl_ucs2length,_BYTES _I32);
-DEFINE_PRIM(_BYTES,hl_utf8_to_utf16,_BYTES _I32 _REF(_I32));
-DEFINE_PRIM(_BYTES,hl_ucs2_upper,_BYTES _I32 _I32);
-DEFINE_PRIM(_BYTES,hl_ucs2_lower,_BYTES _I32 _I32);
+DEFINE_PRIM(_BYTES,itos,_I32 _REF(_I32));
+DEFINE_PRIM(_BYTES,ftos,_F64 _REF(_I32));
+DEFINE_PRIM(_BYTES,value_to_string,_DYN _REF(_I32));
+DEFINE_PRIM(_I32,ucs2length,_BYTES _I32);
+DEFINE_PRIM(_BYTES,utf8_to_utf16,_BYTES _I32 _REF(_I32));
+DEFINE_PRIM(_BYTES,utf16_to_utf8,_BYTES _I32 _REF(_I32));
+DEFINE_PRIM(_BYTES,ucs2_upper,_BYTES _I32 _I32);
+DEFINE_PRIM(_BYTES,ucs2_lower,_BYTES _I32 _I32);
+DEFINE_PRIM(_BYTES,url_encode,_BYTES _REF(_I32));
+DEFINE_PRIM(_BYTES,url_decode,_BYTES _REF(_I32));
+

+ 30 - 0
src/std/sys.c

@@ -493,3 +493,33 @@ HL_PRIM void hl_sys_init(void **args, int nargs) {
 	sys_args = (pchar**)args;
 	sys_nargs = nargs;
 }
+
+DEFINE_PRIM(_BOOL, sys_utf8_path, _NO_ARG);
+DEFINE_PRIM(_BYTES, sys_string, _NO_ARG);
+DEFINE_PRIM(_VOID, sys_print, _BYTES);
+DEFINE_PRIM(_VOID, sys_exit, _I32);
+DEFINE_PRIM(_F64, sys_time, _NO_ARG);
+DEFINE_PRIM(_I32, random, _I32);
+DEFINE_PRIM(_BYTES, sys_get_env, _BYTES);
+DEFINE_PRIM(_BOOL, sys_put_env, _BYTES _BYTES);
+DEFINE_PRIM(_ARR, sys_env, _NO_ARG);
+DEFINE_PRIM(_VOID, sys_sleep, _F64);
+DEFINE_PRIM(_BOOL, sys_set_time_locale, _BYTES);
+DEFINE_PRIM(_BYTES, sys_get_cwd, _NO_ARG);
+DEFINE_PRIM(_BOOL, sys_set_cwd, _BYTES);
+DEFINE_PRIM(_BOOL, sys_is64, _NO_ARG);
+DEFINE_PRIM(_I32, sys_command, _BYTES);
+DEFINE_PRIM(_BOOL, sys_exists, _BYTES);
+DEFINE_PRIM(_BOOL, sys_delete, _BYTES);
+DEFINE_PRIM(_BOOL, sys_rename, _BYTES _BYTES);
+DEFINE_PRIM(_ARR, sys_stat, _BYTES);
+DEFINE_PRIM(_BOOL, sys_is_dir, _BYTES);
+DEFINE_PRIM(_BOOL, sys_create_dir, _BYTES _I32);
+DEFINE_PRIM(_BOOL, sys_remove_dir, _BYTES);
+DEFINE_PRIM(_F64, sys_cpu_time, _NO_ARG);
+DEFINE_PRIM(_F64, sys_thread_cpu_time, _NO_ARG);
+DEFINE_PRIM(_ARR, sys_read_dir, _BYTES);
+DEFINE_PRIM(_BYTES, sys_full_path, _BYTES);
+DEFINE_PRIM(_BYTES, sys_exe_path, _NO_ARG);
+DEFINE_PRIM(_I32, sys_get_char, _BOOL);
+DEFINE_PRIM(_ARR, sys_args, _NO_ARG);

+ 12 - 4
src/std/types.c

@@ -38,7 +38,7 @@ static const uchar *TSTR[] = {
 };
 
 
-int hl_type_size( hl_type *t ) {
+HL_PRIM int hl_type_size( hl_type *t ) {
 	static int SIZES[] = {
 		0, // VOID
 		1, // I8
@@ -63,7 +63,7 @@ int hl_type_size( hl_type *t ) {
 	return SIZES[t->kind];
 }
 
-int hl_pad_size( int pos, hl_type *t ) {
+HL_PRIM int hl_pad_size( int pos, hl_type *t ) {
 	int sz = hl_type_size(t);
 	int align;
 	align = pos & (sz - 1);
@@ -422,5 +422,13 @@ HL_PRIM varray *hl_enum_parameters( vdynamic *v ) {
 	return a;
 }
 
-DEFINE_PRIM(_BYTES, hl_type_name, _TYPE);
-DEFINE_PRIM(_ARR, hl_type_enum_fields, _TYPE);
+DEFINE_PRIM(_BYTES, type_str, _TYPE);
+DEFINE_PRIM(_BYTES, type_name, _TYPE);
+DEFINE_PRIM(_I32, type_args_count, _TYPE);
+DEFINE_PRIM(_ARR, type_instance_fields, _TYPE);
+DEFINE_PRIM(_TYPE, type_super, _TYPE);
+DEFINE_PRIM(_DYN, type_get_global, _TYPE);
+DEFINE_PRIM(_ARR, type_enum_fields, _TYPE);
+DEFINE_PRIM(_BOOL, type_enum_eq, _DYN _DYN);
+DEFINE_PRIM(_DYN, alloc_enum, _TYPE _I32 _ARR);
+DEFINE_PRIM(_ARR, enum_parameters, _DYN);