refactored compiler code abit
This commit is contained in:
		| @ -408,30 +408,39 @@ class UndefinedObject(Apex) | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class Error(Apex) | class Error(Apex) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| pooldic Error.Code | pooldic Error.Code | ||||||
| { | { | ||||||
| 	GENERIC   := error(0). | 	EGENERIC   := error(0). | ||||||
| 	NOIMPL    := error(1). | 	ENOIMPL    := error(1). | ||||||
| 	SYSERR    := error(2). | 	ESYSERR    := error(2). | ||||||
| 	INTERN    := error(3). | 	EINTERN    := error(3). | ||||||
| 	SYSMEM    := error(4). | 	ESYSMEM    := error(4). | ||||||
| 	OOMEM     := error(5). | 	EOOMEM     := error(5). | ||||||
| 	INVAL     := error(6). | 	EINVAL     := error(6). | ||||||
| 	NOENT     := error(7). | 	ENOENT     := error(7). | ||||||
| (* add more items... *) | (* add more items... *) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | (*pooldic Error.Code2  | ||||||
|  | { | ||||||
|  | 	>> CAN I SUPPORT this kind of redefnition? as of now, it's not accepted because  | ||||||
|  | 	>> Error.Code2.EGENERIC is not a literal. Should i treate pooldic members as a constant | ||||||
|  | 	>> and treat it as if it's a literal like? then even if the defined value changes, | ||||||
|  | 	>> the definition here won't see the change... what is the best way to tackle this issue? | ||||||
|  |  | ||||||
|  | 	EGENERIC := Error.Code2.EGENERIC. | ||||||
|  | }*) | ||||||
|  |  | ||||||
| extend Error | extend Error | ||||||
| { | { | ||||||
| 	(* ---------------------------- | 	(* ---------------------------- | ||||||
| 	TODO: support constant declaration... | 	TODO: support nested pooldic/constant declaration... | ||||||
|  |  | ||||||
| 	#const | 	pooldic/const | ||||||
| 	{ | 	{ | ||||||
| 		NONE := error(0). | 		NONE := error(0). | ||||||
| 		GENERIC := error(1). | 		GENERIC := error(1). | ||||||
|  | |||||||
| @ -29,7 +29,7 @@ class Collection(Object) | |||||||
| 	method detect: block | 	method detect: block | ||||||
| 	{ | 	{ | ||||||
| 		self do: [ :el | if (block value: el) { ^el } ]. | 		self do: [ :el | if (block value: el) { ^el } ]. | ||||||
| 		^Error.Code.NOENT | 		^Error.Code.ENOENT | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	method detect: block ifNone: exception_block | 	method detect: block ifNone: exception_block | ||||||
| @ -229,7 +229,7 @@ class Set(Collection) | |||||||
| 		}. | 		}. | ||||||
|  |  | ||||||
| 		##upsert ifFalse: [^ErrorCode.NOENT]. | 		##upsert ifFalse: [^ErrorCode.NOENT]. | ||||||
| 		if (upsert) {} else { ^Error.Code.NOENT }. | 		if (upsert) {} else { ^Error.Code.ENOENT }. | ||||||
|  |  | ||||||
| 		ntally := self.tally + 1. | 		ntally := self.tally + 1. | ||||||
| 		if (ntally >= bs) | 		if (ntally >= bs) | ||||||
| @ -316,7 +316,7 @@ class Set(Collection) | |||||||
| 			index := (index + 1) rem: bs. | 			index := (index + 1) rem: bs. | ||||||
| 		}. | 		}. | ||||||
|  |  | ||||||
| 		^Error.Code.NOENT. | 		^Error.Code.ENOENT. | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	method __remove_at: index | 	method __remove_at: index | ||||||
|  | |||||||
| @ -2795,7 +2795,10 @@ oops: | |||||||
| 	return MOO_NULL; | 	return MOO_NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int preprocess_dotted_name (moo_t* moo, int dont_add_ns, int accept_pooldic_as_ns, const moo_oocs_t* fqn, const moo_ioloc_t* fqn_loc, moo_oocs_t* name, moo_oop_set_t* ns_oop) | #define PDN_DONT_ADD_NS (1 << 0) | ||||||
|  | #define PDN_ACCEPT_POOLDIC_AS_NS (1 << 1) | ||||||
|  |  | ||||||
|  | static int preprocess_dotted_name (moo_t* moo, int flags, moo_oop_set_t topdic, const moo_oocs_t* fqn, const moo_ioloc_t* fqn_loc, moo_oocs_t* name, moo_oop_set_t* ns_oop) | ||||||
| { | { | ||||||
| 	const moo_ooch_t* ptr, * dot; | 	const moo_ooch_t* ptr, * dot; | ||||||
| 	moo_oow_t len; | 	moo_oow_t len; | ||||||
| @ -2804,7 +2807,7 @@ static int preprocess_dotted_name (moo_t* moo, int dont_add_ns, int accept_poold | |||||||
| 	moo_oop_association_t ass; | 	moo_oop_association_t ass; | ||||||
| 	int pooldic_gotten = 0; | 	int pooldic_gotten = 0; | ||||||
|  |  | ||||||
| 	dic = moo->sysdic; | 	dic = topdic? topdic: moo->sysdic; | ||||||
| 	ptr = fqn->ptr; | 	ptr = fqn->ptr; | ||||||
| 	len = fqn->len; | 	len = fqn->len; | ||||||
|  |  | ||||||
| @ -2844,7 +2847,7 @@ static int preprocess_dotted_name (moo_t* moo, int dont_add_ns, int accept_poold | |||||||
| 						 * has been attached to the class */ | 						 * has been attached to the class */ | ||||||
| 						moo_oop_set_t t; | 						moo_oop_set_t t; | ||||||
|  |  | ||||||
| 						if (dont_add_ns) goto wrong_name; | 						if (flags & PDN_DONT_ADD_NS) goto wrong_name; | ||||||
|  |  | ||||||
| 						/* attach a new namespace dictionary to the nsdic field | 						/* attach a new namespace dictionary to the nsdic field | ||||||
| 						 * of the class */ | 						 * of the class */ | ||||||
| @ -2856,7 +2859,7 @@ static int preprocess_dotted_name (moo_t* moo, int dont_add_ns, int accept_poold | |||||||
| 				} | 				} | ||||||
| 				else | 				else | ||||||
| 				{ | 				{ | ||||||
| 					if (accept_pooldic_as_ns && MOO_CLASSOF(moo, ass->value) == moo->_pool_dictionary) | 					if ((flags & PDN_ACCEPT_POOLDIC_AS_NS) && MOO_CLASSOF(moo, ass->value) == moo->_pool_dictionary) | ||||||
| 					{ | 					{ | ||||||
| 						/* A pool dictionary is treated as if it's a name space. | 						/* A pool dictionary is treated as if it's a name space. | ||||||
| 						 * However, the pool dictionary can only act as a name space | 						 * However, the pool dictionary can only act as a name space | ||||||
| @ -2875,7 +2878,7 @@ static int preprocess_dotted_name (moo_t* moo, int dont_add_ns, int accept_poold | |||||||
| 				moo_oop_set_t t; | 				moo_oop_set_t t; | ||||||
|  |  | ||||||
| 				/* the segment does not exist. add it */ | 				/* the segment does not exist. add it */ | ||||||
| 				if (dont_add_ns) | 				if (flags & PDN_DONT_ADD_NS) | ||||||
| 				{ | 				{ | ||||||
| 					/* in '#extend Planet.Earth', it's an error | 					/* in '#extend Planet.Earth', it's an error | ||||||
| 					 * if Planet doesn't exist */ | 					 * if Planet doesn't exist */ | ||||||
| @ -2924,7 +2927,7 @@ static int resolve_pooldic (moo_t* moo, int dotted, const moo_oocs_t* name) | |||||||
|  |  | ||||||
| 	if (dotted) | 	if (dotted) | ||||||
| 	{ | 	{ | ||||||
| 		if (preprocess_dotted_name(moo, 0, 0, name, TOKEN_LOC(moo), &last, &ns_oop) <= -1) return -1; | 		if (preprocess_dotted_name(moo, 0, MOO_NULL, name, TOKEN_LOC(moo), &last, &ns_oop) <= -1) return -1; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @ -3011,7 +3014,7 @@ static int compile_class_level_variables (moo_t* moo) | |||||||
| 		else if (is_token_symbol(moo, VOCA_POOLDIC_S)) | 		else if (is_token_symbol(moo, VOCA_POOLDIC_S)) | ||||||
| 		{ | 		{ | ||||||
| 			/* dcl(#pooldic) - import a pool dictionary */ | 			/* dcl(#pooldic) - import a pool dictionary */ | ||||||
| 			dcl_type = VAR_GLOBAL; /* this is not a real type. use for branching below */ | 			dcl_type = VAR_GLOBAL; /* this is not a real type. used for branching below */ | ||||||
| 			GET_TOKEN (moo); | 			GET_TOKEN (moo); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @ -3027,7 +3030,7 @@ static int compile_class_level_variables (moo_t* moo) | |||||||
| 	if (dcl_type == VAR_GLOBAL)  | 	if (dcl_type == VAR_GLOBAL)  | ||||||
| 	{ | 	{ | ||||||
| 		/* pool dictionary import declaration | 		/* pool dictionary import declaration | ||||||
| 		 * #dcl(#pooldic) ... */ | 		 * dcl(#pooldic) ... */ | ||||||
| 		moo_oocs_t last; | 		moo_oocs_t last; | ||||||
| 		moo_oop_set_t ns_oop; | 		moo_oop_set_t ns_oop; | ||||||
|  |  | ||||||
| @ -3035,7 +3038,7 @@ static int compile_class_level_variables (moo_t* moo) | |||||||
| 		{ | 		{ | ||||||
| 			if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | 			if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | ||||||
| 			{ | 			{ | ||||||
| 				if (preprocess_dotted_name(moo, 0, 0, TOKEN_NAME(moo), TOKEN_LOC(moo), &last, &ns_oop) <= -1) return -1; | 				if (preprocess_dotted_name(moo, 0, MOO_NULL, TOKEN_NAME(moo), TOKEN_LOC(moo), &last, &ns_oop) <= -1) return -1; | ||||||
| 			} | 			} | ||||||
| 			else if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) | 			else if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) | ||||||
| 			{ | 			{ | ||||||
| @ -3490,7 +3493,7 @@ static int get_variable_info (moo_t* moo, const moo_oocs_t* name, const moo_iolo | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (preprocess_dotted_name (moo, 1, 1, name, name_loc, &last, &ns_oop) <= -1) return -1; | 		if (preprocess_dotted_name (moo, PDN_DONT_ADD_NS | PDN_ACCEPT_POOLDIC_AS_NS, MOO_NULL, name, name_loc, &last, &ns_oop) <= -1) return -1; | ||||||
|  |  | ||||||
| 		ass = moo_lookupdic (moo, ns_oop, &last); | 		ass = moo_lookupdic (moo, ns_oop, &last); | ||||||
| 		if (ass) | 		if (ass) | ||||||
| @ -6181,7 +6184,7 @@ static int __compile_class_definition (moo_t* moo, int extend) | |||||||
| 	moo->c->cls.fqn_loc = moo->c->tok.loc; | 	moo->c->cls.fqn_loc = moo->c->tok.loc; | ||||||
| 	if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | 	if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | ||||||
| 	{ | 	{ | ||||||
| 		if (preprocess_dotted_name(moo, extend, 0, &moo->c->cls.fqn, &moo->c->cls.fqn_loc, &moo->c->cls.name, &moo->c->cls.ns_oop) <= -1) return -1; | 		if (preprocess_dotted_name(moo, (extend? PDN_DONT_ADD_NS: 0), MOO_NULL, &moo->c->cls.fqn, &moo->c->cls.fqn_loc, &moo->c->cls.name, &moo->c->cls.ns_oop) <= -1) return -1; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @ -6253,7 +6256,7 @@ static int __compile_class_definition (moo_t* moo, int extend) | |||||||
|  |  | ||||||
| 			if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | 			if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | ||||||
| 			{ | 			{ | ||||||
| 				if (preprocess_dotted_name(moo, 1, 0, &moo->c->cls.superfqn, &moo->c->cls.superfqn_loc, &moo->c->cls.supername, &moo->c->cls.superns_oop) <= -1) return -1; | 				if (preprocess_dotted_name(moo, PDN_DONT_ADD_NS, MOO_NULL, &moo->c->cls.superfqn, &moo->c->cls.superfqn_loc, &moo->c->cls.supername, &moo->c->cls.superns_oop) <= -1) return -1; | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
| @ -6446,7 +6449,7 @@ static int __compile_class_definition (moo_t* moo, int extend) | |||||||
|  |  | ||||||
| 				if (dotted) | 				if (dotted) | ||||||
| 				{ | 				{ | ||||||
| 					if (preprocess_dotted_name(moo, 0, 0, &tok, &loc, &last, &ns_oop) <= -1) return -1; | 					if (preprocess_dotted_name(moo, 0, MOO_NULL, &tok, &loc, &last, &ns_oop) <= -1) return -1; | ||||||
| 				} | 				} | ||||||
| 				else | 				else | ||||||
| 				{ | 				{ | ||||||
| @ -6605,7 +6608,7 @@ static int __compile_pooldic_definition (moo_t* moo) | |||||||
|  |  | ||||||
| 	if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | 	if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) | ||||||
| 	{ | 	{ | ||||||
| 		if (preprocess_dotted_name(moo, 0, 0, &moo->c->cls.fqn, &moo->c->cls.fqn_loc, &moo->c->cls.name, &moo->c->cls.ns_oop) <= -1) return -1; | 		if (preprocess_dotted_name(moo, 0, MOO_NULL, &moo->c->cls.fqn, &moo->c->cls.fqn_loc, &moo->c->cls.name, &moo->c->cls.ns_oop) <= -1) return -1; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user