Browse Source

mx2cc cleanups.

Mark Sibly 9 years ago
parent
commit
da00036041

+ 1 - 1
src/mx2new/class.monkey2

@@ -676,7 +676,7 @@ Class ClassScope Extends Scope
 	
 		Local node:=ctype.FindNode( ident )
 		If node Return node
-		
+
 		If outer Return outer.FindNode( ident )
 		
 		Return Null

+ 6 - 6
src/mx2new/expr.monkey2

@@ -151,9 +151,9 @@ Class IdentExpr Extends Expr
 	Method OnSemant:Value( scope:Scope ) Override
 	
 		Local value:=scope.FindValue( ident )
-		If Not value Throw New SemantEx( "Identifier '"+ident+"' not found" )
+		If value Return value
 		
-		Return value
+		Throw New SemantEx( "Identifier '"+ident+"' not found" )
 	End
 	
 	Method OnSemantType:Type( scope:Scope ) Override
@@ -183,14 +183,14 @@ Class MemberExpr Extends Expr
 	
 	Method OnSemant:Value( scope:Scope ) Override
 	
-'		Local value:=expr.Semant( scope )
 		Local value:=expr.SemantRValue( scope )
 		
 		Local tvalue:=value.FindValue( ident )
-		If Not tvalue Throw New SemantEx( "Value of type '"+value.type.Name+"' has no member named '"+ident+"'" )
-'		If Not tvalue Throw New IdentEx( ident )
+		If tvalue Return tvalue
 		
-		Return tvalue
+		Local tv:=Cast<TypeValue>( value )
+		If tv Throw New SemantEx( "Type '"+tv.ttype.Name+"' has no member named '"+ident+"'" )
+		Throw New SemantEx( "Value of type '"+value.type.Name+"' has no member named '"+ident+"'" )
 	End
 	
 	Method OnSemantType:Type( scope:Scope ) Override

+ 2 - 1
src/mx2new/func.monkey2

@@ -285,10 +285,11 @@ Class FuncValue Extends Value
 			If Not instance Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed without an instance" )
 			
 			If Not instance.type.ExtendsType( Cast<ClassScope>( scope ).ctype )
-				Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed from instance of a different class" )
+				Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed from an instance of a different class" )
 			Endif
 			
 			value=New MemberFuncValue( instance,Self )
+
 		Endif
 		
 		Used()

+ 3 - 7
src/mx2new/mx2cc.monkey2

@@ -20,13 +20,7 @@ Using libc
 
 Global StartDir:String
 
-Const TestArgs:="mx2cc makedocs std"
-
-'Const TestArgs:="mx2cc makeapp src/ted2/ted2.monkey2"
-
-'Const TestArgs:="mx2cc makeapp src/mx2new/test.monkey2"
-
-'Const TestArgs:="mx2cc makeapp src/mx2new/test.monkey2"
+Const TestArgs:="mx2cc makedocs"
 
 'Const TestArgs:="mx2cc makeapp src/mx2new/test.monkey2"
 
@@ -185,6 +179,8 @@ Function MakeDocs( args:String[] )
 	opts.verbose=0
 	
 	args=ParseOpts( opts,args )
+	opts.clean=False
+	
 	If Not args args=EnumModules()
 	
 	Local docsMaker:=New HtmlDocsMaker

+ 12 - 3
src/mx2new/property.monkey2

@@ -17,6 +17,7 @@ Class PropertyList Extends FuncList
 	
 	Field pdecl:PropertyDecl
 	Field scope:Scope
+	Field cscope:ClassScope
 	
 	Field getFunc:FuncValue
 	Field setFunc:FuncValue
@@ -28,6 +29,7 @@ Class PropertyList Extends FuncList
 		Self.pnode=pdecl
 		Self.pdecl=pdecl
 		Self.scope=scope
+		Self.cscope=Cast<ClassScope>( scope )
 	End
 	
 	Method ToString:String() Override
@@ -51,7 +53,7 @@ Class PropertyList Extends FuncList
 
 		If pdecl.setFunc
 			Try
-				setFunc=New FuncValue( pdecl.setFunc,scope,Null,null )
+				setFunc=New FuncValue( pdecl.setFunc,scope,Null,Null )
 				setFunc.Semant()
 				PushFunc( setFunc )
 			Catch ex:SemantEx
@@ -63,9 +65,16 @@ Class PropertyList Extends FuncList
 	
 	Method ToValue:Value( instance:Value ) Override
 	
-		If instance Return New PropertyValue( Self,instance )
+		If Not instance Throw New SemantEx( "Property '"+pdecl.ident+"' cannot be accessed without an instance" )
 		
-		Return Null
+		If Not instance.type.ExtendsType( cscope.ctype )
+			Throw New SemantEx( "Property '"+pdecl.ident+"' cannot be accessed from an instance of a different class" )
+		Endif
+		
+		Return New PropertyValue( Self,instance )
+	
+		'If instance Return New PropertyValue( Self,instance )
+		'Return Null
 	End
 	
 End

+ 28 - 2
src/mx2new/test.monkey2

@@ -1,15 +1,41 @@
 
+Namespace test
+
 #Import "<std.monkey2>"
 
 Using std..
 
-Struct S
+Enum Mode
+	Opaque
+	Alpha
+End
+
+Struct Line
 
-	Method New( s:S )
+	Field state:Int
+	
+	Property Mode:Mode()
+		Return _mode
 	End
+	
+	Method update( line:Line )
+		Self=line
+	End
+	
+	Field _mode:=test.Mode.Opaque
 
 End
 
 Function Main()
 
+	Local t:=1.5e-2
+	
+	Print t
+
+	Local lines:=New Stack<Line>
+	
+	lines.Push( New Line )
+	
+'	lines[0].state=10
+
 End

+ 24 - 13
src/mx2new/toker.monkey2

@@ -188,28 +188,39 @@ Class Toker
 			
 			Return _toke
 			
-		Else If IsDigit( ch ) 
-		
+		Else If IsDigit( ch ) Or (ch=CHAR_DOT And _pos<_len And IsDigit( _text[_pos] ))
+
+			_tokeType=TOKE_INTLIT
+			If ch=CHAR_DOT
+				_tokeType=TOKE_FLOATLIT
+				_pos+=1
+			Endif
+			
 			While _pos<_len And IsDigit( _text[_pos] )
 				_pos+=1
 			Wend
-			_tokeType=TOKE_INTLIT
 			
-			If _pos<_len And _text[_pos]=CHAR_DOT
-				_pos+=1
+			'.#
+			If _pos+1<_len And _text[_pos]=CHAR_DOT And IsDigit( _text[_pos+1] ) And _tokeType=TOKE_INTLIT
+				_tokeType=TOKE_FLOATLIT
+				_pos+=2
 				While _pos<_len And IsDigit( _text[_pos] )
 					_pos+=1
 				Wend
-				_tokeType=TOKE_FLOATLIT
 			Endif
 			
-		Else If ch=CHAR_DOT And _pos<_len And IsDigit( _text[_pos] )
-		
-			_pos+=1
-			While _pos<_len And IsDigit( _text[_pos] )
-				_pos+=1
-			Wend
-			_tokeType=TOKE_FLOATLIT
+			'e, E...
+			If _pos+1<_len And (_text[_pos]=69 Or _text[_pos]=101)
+				Local tpos:=_pos+1
+				If _text[tpos]=43 Or _text[tpos]=45 tpos+=1
+				If tpos<_len And IsDigit( _text[tpos] )
+					_tokeType=TOKE_FLOATLIT
+					_pos=tpos+1
+					While _pos<_len And IsDigit( _text[_pos] )
+						_pos+=1
+					Wend
+				Endif
+			Endif
 			
 		Else If ch=CHAR_QUOTE
 		

+ 2 - 0
src/mx2new/value.monkey2

@@ -222,6 +222,8 @@ Class SelfValue Extends Value
 	Method New( ctype:ClassType )
 		Self.type=ctype
 		Self.ctype=ctype
+		
+		If ctype.IsStruct flags|=VALUE_LVALUE|VALUE_ASSIGNABLE
 	End
 	
 	Method ToString:String() Override

+ 28 - 11
src/mx2new/var.monkey2

@@ -38,6 +38,7 @@ Class VarValue Extends Value
 	Field vdecl:VarDecl
 	Field scope:Scope
 	Field transFile:FileDecl
+	Field cscope:ClassScope
 	
 	Field init:Value
 	
@@ -47,6 +48,7 @@ Class VarValue Extends Value
 		Self.vdecl=vdecl
 		Self.scope=scope
 		Self.transFile=scope.FindFile().fdecl
+		Self.cscope=Cast<ClassScope>( scope )
 		
 		If vdecl.kind="global" Or vdecl.kind="local" Or vdecl.kind="param" flags|=VALUE_LVALUE|VALUE_ASSIGNABLE
 	End
@@ -60,6 +62,7 @@ Class VarValue Extends Value
 		Self.pnode=vdecl
 		Self.type=init.type
 		Self.scope=scope
+		Self.cscope=Cast<ClassScope>( scope )
 		Self.init=init
 		
 		If vdecl.kind="global" Or vdecl.kind="local" Or vdecl.kind="param" flags|=VALUE_LVALUE|VALUE_ASSIGNABLE
@@ -67,6 +70,10 @@ Class VarValue Extends Value
 		semanted=Self
 	End
 	
+	Property IsField:Bool()
+		Return vdecl.kind="field"
+	End
+	
 	Method OnSemant:SNode() Override
 	
 		If vdecl.type
@@ -77,12 +84,6 @@ Class VarValue Extends Value
 			type=init.type
 		Endif
 		
-		'struct field?
-'		Local cscope:=Cast<ClassScope>( scope )
-'		If vdecl.kind="field" And cscope And cscope.ctype.cdecl.kind="struct"
-'			If init And init.HasSideEffects Throw New SemantEx( "Struct field initializers cannot have side effects" )
-'		Endif
-		
 		If Not type.IsGeneric And Not vdecl.IsExtern And Not Cast<Block>( scope )
 			If vdecl.kind="global" Or vdecl.kind="const"
 				transFile.globals.Push( Self )
@@ -105,11 +106,20 @@ Class VarValue Extends Value
 	Method ToValue:Value( instance:Value ) Override
 	
 		If vdecl.kind="field"
-			Local ctype:=Cast<ClassScope>( scope ).ctype 
-			If instance And instance.type.DistanceToType( ctype )>=0
-				Return New MemberVarValue( instance,Self )
+		
+			If Not instance Throw New SemantEx( "Field '"+vdecl.ident+"' cannot be accessed without an instance" )
+		
+			If Not instance.type.ExtendsType( cscope.ctype )
+				Throw New SemantEx( "Field '"+vdecl.ident+"' cannot be accessed from an instance of a different class" )
 			Endif
-			Throw New SemantEx( "Field '"+ToString()+"' cannot be accessed from here" )
+
+			Return New MemberVarValue( instance,Self )
+			
+'			If instance And instance.type.DistanceToType( cscope.ctype )>=0
+'				Return New MemberVarValue( instance,Self )
+'			Endif
+'			Throw New SemantEx( "Field '"+ToString()+"' cannot be accessed without an instance" )
+
 		Endif
 		
 		Return Self
@@ -131,7 +141,14 @@ Class MemberVarValue Extends Value
 		Self.instance=instance
 		Self.member=member
 		
-		If member.vdecl.kind="field" flags|=VALUE_LVALUE|VALUE_ASSIGNABLE
+		If member.vdecl.kind="field"
+			If member.cscope.ctype.IsStruct
+				If instance.IsLValue flags|=VALUE_LVALUE
+				If instance.IsAssignable flags|=VALUE_ASSIGNABLE
+			Else
+				flags|=VALUE_LVALUE|VALUE_ASSIGNABLE
+			Endif
+		Endif
 	End
 	
 	Method ToString:String() Override