starting to write support 'const' defintion in a class

This commit is contained in:
hyunghwan.chung 2019-09-04 15:06:24 +00:00
parent 1bd41fc6c0
commit 00969032ff
3 changed files with 42 additions and 7 deletions

View File

@ -16,6 +16,20 @@ class FFI(Object)
{
var name, ffi, funcs.
/*
pooldic Type
{
UINT8 := 1.
UINT16 := 2.
UINT32 := 3.
UINT64 := 4.
}
*/
/*
const UINT8 := 1.
const UINT16 := 2.
*/
method(#class) new: aString
{
^self new open: aString.
@ -55,6 +69,9 @@ class FFI(Object)
{
| f rc |
//self.Type.UINT8 dump.
//#[ self.Type.UINT8, FFI.Type.UINT16 ] dump.
/* f := self.funcs at: name ifAbsent: [
f := self.ffi getsym(name).
if (f isError) { FFIException signal: ('Unable to find %O' strfmt(name)) }.
@ -71,7 +88,7 @@ class FFI(Object)
}.
rc := self.ffi call(f, sig, args).
if (rc isError) { FFIException signal: ('Unable to call %O' strfmt(name)) }.
if (rc isError) { FFIException signal: ('Unable to call %O - %O' strfmt(name, rc)) }.
^rc.
}

View File

@ -118,6 +118,7 @@ static struct voca_t
{ 5, { 'c','l','a','s','s' } },
{ 6, { '#','c','l','a','s','s' } },
{ 10, { '#','c','l','a','s','s','i','n','s','t' } },
{ 5, { 'c','o','n','s','t' } },
{ 8, { 'c','o','n','t','i','n','u','e' } },
{ 2, { 'd','o' } },
{ 5, { '#','d','u','a','l' } },
@ -187,6 +188,7 @@ enum voca_id_t
VOCA_CLASS,
VOCA_CLASS_S,
VOCA_CLASSINST_S,
VOCA_CONST,
VOCA_CONTINUE,
VOCA_DO,
VOCA_DUAL_S,
@ -430,6 +432,7 @@ static int is_restricted_word (const moo_oocs_t* ucs)
static int rw[] =
{
VOCA_CLASS,
VOCA_CONST,
VOCA_EXTEND,
VOCA_FROM,
VOCA_IMPORT,
@ -4014,6 +4017,12 @@ static int compile_class_level_imports (moo_t* moo)
return 0;
}
static int compile_class_level_consts (moo_t* moo)
{
/* TODO: */
return 0;
}
static int compile_unary_method_name (moo_t* moo, moo_method_data_t* mth)
{
MOO_ASSERT (moo, mth->name.len == 0);
@ -9068,6 +9077,9 @@ static int __compile_class_definition (moo_t* moo, int class_type)
}
while (1);
}
/* TODO: load constants here? */
}
else
{
@ -9104,6 +9116,12 @@ static int __compile_class_definition (moo_t* moo, int class_type)
GET_TOKEN (moo);
if (compile_class_level_imports(moo) <= -1) return -1;
}
else if (is_token_word(moo, VOCA_CONST))
{
/* constant declaration */
GET_TOKEN (moo);
if (compile_class_level_consts(moo) <= -1) return -1;
}
else break;
}
while (1);

View File

@ -30,15 +30,13 @@
#include <errno.h>
#include <string.h>
#if defined(HAVE_DYNCALL_LIB) && defined(HAVE_DYNCALL_H)
# define USE_DYNCALL
#elif defined(HAVE_FFI_LIB) && defined(HAVE_FFI_H)
#if defined(HAVE_FFI_LIB) && defined(HAVE_FFI_H)
# define USE_LIBFFI
#elif defined(HAVE_DYNCALL_LIB) && defined(HAVE_DYNCALL_H)
# define USE_DYNCALL
#endif
#if defined(USE_DYNCALL)
# include <dyncall.h>
#elif defined(USE_LIBFFI)
#if defined(USE_LIBFFI)
# include <ffi.h>
# if (MOO_SIZEOF_LONG_LONG > 0) && !defined(ffi_type_ulonglong)
# if MOO_SIZEOF_LONG_LONG == MOO_SIZEOF_INT32_T
@ -49,6 +47,8 @@
# define ffi_type_slonglong ffi_type_sint64
# endif
# endif
#elif defined(USE_DYNCALL)
# include <dyncall.h>
#endif
#define FMTC_NULL '\0' /* internal use only */