Browse Source

Fixed mx2cc allowing Null of Void type.

Mark Sibly 7 years ago
parent
commit
634e822b2b
5 changed files with 9 additions and 36 deletions
  1. 1 0
      src/mx2cc/expr.monkey2
  2. 2 2
      src/mx2cc/mx2cc.monkey2
  3. 1 24
      src/mx2cc/test.monkey2
  4. 3 4
      src/mx2cc/type.monkey2
  5. 2 6
      src/mx2cc/value.monkey2

+ 1 - 0
src/mx2cc/expr.monkey2

@@ -770,6 +770,7 @@ Class BinaryopExpr Extends Expr
 		Local lhs:=Self.lhs.Semant( scope )
 		Local rhs:=Self.rhs.Semant( scope )
 		
+		
 		If lhs.type=Type.NullType
 			rhs=rhs.ToRValue()
 			lhs=lhs.UpCast( rhs.type )

+ 2 - 2
src/mx2cc/mx2cc.monkey2

@@ -34,13 +34,13 @@ Global opts_time:Bool
 
 Global StartDir:String
 
-'Const TestArgs:="mx2cc makemods"
+Const TestArgs:="mx2cc makemods"
 
 'Const TestArgs:="mx2cc makedocs mojo"
 'Const TestArgs:="pyro-framework pyro-gui pyro-scenegraph pyro-tiled"
 'Const TestArgs:="mx2cc makedocs"
 
-Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
+'Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
 
 'To build with old mx2cc...
 '

+ 1 - 24
src/mx2cc/test.monkey2

@@ -1,30 +1,7 @@
 
-Namespace std.test
-
-#Import "<std>"
-
-#Reflect std.graphics
-
-Using std..
-
-Function F()
-
-End
-
-Class C 'Extends Resource
-	
-End
-
 Function Main()
-
-	Print "Hello World"
-	
-'	Local socket:Socket
-	
-	Local ti:=Typeof<Pixmap>
-	'Local ti:=Typeof<C>
 	
-	Print ti
+	If String<>Null Print "oops"
 	
 End
 	

+ 3 - 4
src/mx2cc/type.monkey2

@@ -43,12 +43,12 @@ Class Type Extends SNode
 	
 	'Not nice - should fix comparison ops
 	Operator=:Bool( type:Type )
-		If Not Self Or Not type Throw New SemantEx( "Type.Operator=()" )
+		If Not type Throw New SemantEx( "Type.Operator=()" )
 		Return Object(Dealias)=type.Dealias
 	End
 	
 	Operator<>:Bool( type:Type )
-		If Not Self Or Not type Throw New SemantEx( "Type.Operator<>()" )
+		If Not type Throw New SemantEx( "Type.Operator<>()" )
 		Return Object(Dealias)<>type.Dealias
 	End
 	
@@ -790,7 +790,7 @@ Class GenArgType Extends Type
 End
 
 Class VoidType Extends Type
-
+	
 	Method ToString:String() Override
 		Return "Void"
 	End
@@ -850,4 +850,3 @@ Class NullType Extends Type
 	End
 	
 End
-

+ 2 - 6
src/mx2cc/value.monkey2

@@ -152,11 +152,6 @@ Class TypeValue Extends Value
 		Return "<"+ttype.ToString()+">"
 	End
 	
-'	Method ToRValue:Value() Override
-'		Throw New SemantEx( "Type '"+ttype.ToString()+"' cannot be converted to a value" )
-'		Return Null
-'	End
-	
 	Method FindValue:Value( ident:String ) Override
 		Local node:=ttype.FindNode( ident )
 		If node Return node.ToValue( Null )
@@ -354,6 +349,7 @@ Class LiteralValue Extends Value
 	End
 	
 	Function NullValue:LiteralValue( type:Type )
+		If type.Equals( Type.VoidType ) Throw New SemantEx( "Null value cannot have void type" )
 		Return New LiteralValue( type,"" )
 	end
 End
@@ -374,7 +370,7 @@ Class NullValue Extends Value
 	End
 		
 	Method UpCast:Value( type:Type ) Override
-		Return New LiteralValue( type,"" )
+		Return LiteralValue.NullValue( type )
 	End
 	
 End