Exemplo n.º 1
0
void NewtInitEnv(int argc, const char * argv[], int n)
{
	// シンボルテーブルの作成
    SYM_TABLE = NewtMakeArray(kNewtRefUnbind, 0);
    NewtInitSYM();

	// ルートフレームの作成
    ROOT = NcMakeFrame();
	// グローバル変数テーブルの作成
    GLOBALS = NcMakeFrame();
	// グローバル関数テーブルの作成
    GLOBAL_FNS = NcMakeFrame();
	// マジックポインタテーブルの作成
    MAGIC_POINTERS = NewtMakeArray(kNewtRefUnbind, 0);

	// ルートフレームに各テーブルを格納
    NcSetSlot(ROOT, NSSYM0(globals), GLOBALS);
    NcSetSlot(ROOT, NSSYM0(global_fns), GLOBAL_FNS);
    NcSetSlot(ROOT, NSSYM0(magic_pointers), MAGIC_POINTERS);
    NcSetSlot(ROOT, NSSYM0(sym_table), SYM_TABLE);

#ifdef __NAMED_MAGIC_POINTER__
	// 名前付マジックポインタテーブルの作成
    NAMED_MPS = NcMakeFrame();
	// ルートフレームに名前付マジックポインタテーブルの格納
    NcSetSlot(ROOT, NSSYM0(named_mps), NAMED_MPS);
#endif /* __NAMED_MAGIC_POINTER__ */

	// 環境変数の初期化
	NewtInitSysEnv();
	// ARGV の初期化
	NewtInitARGV(argc, argv, n);
	// バージョン情報の初期化
	NewtInitVersInfo();
}
Exemplo n.º 2
0
/** Call a function with an array of parameters
 * 
 * @param rcvr		[in] レシーバ
 * @param func		[in] Function
 * @param params	[in] Parameters
 * 
 * @return			Return value
 */
newtRef 	NsApply(newtRefArg rcvr, newtRefArg func, newtRefArg params)
{
	if (! NewtRefIsFunction(func))
	{
		return NewtThrow(kNErrNotAFunction, func);
	}
	
	newtRef ary = NewtRefIsNIL(params) ? NewtMakeArray(kNewtRefUnbind, 0) : params;
	return NcCallWithArgArray(func, ary);
}
Exemplo n.º 3
0
newtRef NsMakeArray(newtRefArg rcvr, newtRefArg size, newtRefArg initialValue) {
  if (!NewtRefIsInteger(size)) {
    return NewtThrow(kNErrNotAnInteger, size);
  }
  int length = NewtRefToInteger(size);
  newtRef result = NewtMakeArray(kNewtRefUnbind, length);
  int i;
  for (i = 0; i<length; i++) {
    NewtSlotsSetSlot(result, i, initialValue);
  }
  return result;
}
Exemplo n.º 4
0
newtRef NsSplit(newtRefArg rcvr, newtRefArg r, newtRefArg sep)
{
	newtRefVar  result;

    if (! NewtRefIsString(r))
        return NewtThrow(kNErrNotAString, r);

	switch (NewtGetRefType(sep, true))
	{
		case kNewtCharacter:
			{
				newtRefVar  v;
				char *		next;
				char *		s;
				int			c;

				s = NewtRefToString(r);
				c = NewtRefToCharacter(sep);

				result = NewtMakeArray(kNewtRefUnbind, 0);

				while (*s)
				{
					next = strchr(s, c);
					if (next == NULL) break;

					v = NewtMakeString2(s, next - s, false);
					NcAddArraySlot(result, v);
					s = next + 1;
				}

				if (s == NewtRefToString(r))
					v = r;
				else
					v = NSSTR(s);

				NcAddArraySlot(result, v);
			}
			break;

		default:
			{
				newtRefVar	initObj[] = {r};

				result = NewtMakeArray2(kNewtRefNIL, sizeof(initObj) / sizeof(newtRefVar), initObj);
			}
			break;
	}

    return result;
}
Exemplo n.º 5
0
void NewtInitARGV(int argc, const char * argv[], int n)
{
	newtRefVar  exepath = kNewtRefUnbind;
	newtRefVar  r;
	uint16_t	j;
	uint16_t	i;

	r = NewtMakeArray(kNewtRefUnbind, argc - n);
    NcSetSlot(GLOBALS, NSSYM0(_ARGV_), r);

	for (i = n, j = 0; i < argc; i++, j++)
	{
		NewtSetArraySlot(r, j, NewtMakeString(argv[i], true));
	}

#ifdef __WIN32__
	{
		char	sep;

		sep = NewtGetFileSeparator();

		if (sep != '\\')
		{
			char *	path;

			path = strdup(argv[0]);

			if (path)
			{
				replacechr(path, '\\', sep);
				exepath = NewtExpandPath(path);
				free(path);
			}
			else
			{
				exit(errno);
			}
		}
	}
#endif

	if (NewtRefIsNIL(exepath))
		exepath = NewtExpandPath(argv[0]);

    NcSetSlot(GLOBALS, NSSYM0(_EXEDIR_), NcDirName(exepath));
}
Exemplo n.º 6
0
newtRef protoREGEX_regexec(newtRefArg preg, newtRefArg str)
{
	newtRefVar	substr;
	newtRefVar	r;
	regmatch_t	pmatch[10];
	size_t	nmatch;
	char *	src;
	int		eflags = 0;
	int		err;
	int		i;

    if (NewtRefIsNIL(str))
        return kNewtRefNIL;

    if (! protoREGEX_refIsPreg(preg))
        return kNewtRefUnbind;

    if (! NewtRefIsString(str))
        return NewtThrow(kNErrNotAString, str);

	nmatch = sizeof(pmatch) / sizeof(regmatch_t);

	src = NewtRefToString(str);
    err = regexec((regex_t*)NewtRefToBinary(preg), src, nmatch, pmatch, eflags);

	if (err != 0)
		return kNewtRefNIL;

	r = NewtMakeArray(kNewtRefUnbind, nmatch);

	for (i = 0; i < nmatch; i++)
	{
		if (pmatch[i].rm_so != -1)
		{
			substr = NewtMakeString2(src + pmatch[i].rm_so, pmatch[i].rm_eo - pmatch[i].rm_so, false);
			NewtSetArraySlot(r, i, substr);
		}
	}

	return r;
}
Exemplo n.º 7
0
/** Send a message to a method in a frame by name with an array of parameters, if it is defined (proto inheritance only)
 * 
 * @param rcvr		[in] レシーバ
 * @param frame		[in] Frame
 * @param message	[in] Message
 * @param params	[in] Parameters
 * 
 * @return			Return value
 */
newtRef 	NsProtoPerformIfDefined(newtRefArg rcvr, newtRefArg frame, newtRefArg message, newtRefArg params)
{
	newtRef ary = NewtRefIsNIL(params) ? NewtMakeArray(kNewtRefUnbind, 0) : params;
	return NcSendProtoWithArgArray(frame, message, true, ary);
}
Exemplo n.º 8
0
/** Send a message to a method in a frame by name with an array of parameters
 * 
 * @param rcvr		[in] レシーバ
 * @param frame		[in] Frame
 * @param message	[in] Message
 * @param params	[in] Parameters
 * 
 * @return			Return value
 */
newtRef 	NsPerform(newtRefArg rcvr, newtRefArg frame, newtRefArg message, newtRefArg params)
{
	newtRef ary = NewtRefIsNIL(params) ? NewtMakeArray(kNewtRefUnbind, 0) : params;
	return NcSendWithArgArray(frame, message, false, ary);
}