summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-01-16 16:02:04 -0500
committerAdrian Thurston <thurston@complang.org>2015-01-16 16:02:04 -0500
commit59180fc43e2a9c983df2609a956f6dfa707f786a (patch)
treefb81a6ecbec1e050a3d5b40da53d0b7167aa122e /src
parent469cb252fc376e0efed20aa583c1df87c196e634 (diff)
downloadcolm-59180fc43e2a9c983df2609a956f6dfa707f786a.tar.gz
brought back the pointer deref for reverse load
Resurrected the pointer deref instruction for loading during reverse execution. Fixed the lastPtrInQual computation for structs and generics. Removed the deref syntax.
Diffstat (limited to 'src')
-rw-r--r--src/bytecode.c58
-rw-r--r--src/bytecode.h6
-rw-r--r--src/colm.lm2
-rw-r--r--src/loadcolm.cc5
-rw-r--r--src/lookup.cc4
-rw-r--r--src/parsetree.h3
-rw-r--r--src/synthesis.cc45
7 files changed, 32 insertions, 91 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index c10cf33b..5ad610c1 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2566,7 +2566,7 @@ again:
case IN_INPUT_PUSH_WV: {
debug( prg, REALM_BYTECODE, "IN_INPUT_PUSH_WV\n" );
- Stream *input = (Stream*)vm_pop();
+ Stream *input = vm_pop_type( Stream * );
Tree *tree = vm_pop();
long len = stream_push( prg, sp, streamToImpl( input ), tree, false );
vm_push( 0 );
@@ -2767,58 +2767,26 @@ again:
vm_push( res );
break;
}
- case IN_PTR_DEREF_R: {
- debug( prg, REALM_BYTECODE, "IN_PTR_DEREF_R\n" );
-
- Pointer *ptr = (Pointer*)vm_pop();
- treeDownref( prg, sp, (Tree*)ptr );
+ case IN_PTR_ACCESS_WV: {
+ debug( prg, REALM_BYTECODE, "IN_PTR_ACCESS_WV\n" );
- Tree *dval = getPtrVal( ptr );
- treeUpref( dval );
- vm_push( dval );
- break;
- }
- case IN_PTR_DEREF_WC: {
- debug( prg, REALM_BYTECODE, "IN_PTR_DEREF_WC\n" );
-
- Pointer *ptr = (Pointer*)vm_pop();
- treeDownref( prg, sp, (Tree*)ptr );
-
- Tree *dval = getPtrValSplit( prg, ptr );
- treeUpref( dval );
- vm_push( dval );
- break;
- }
- case IN_PTR_DEREF_WV: {
- debug( prg, REALM_BYTECODE, "IN_PTR_DEREF_WV\n" );
-
- Pointer *ptr = (Pointer*)vm_pop();
- /* Don't downref the pointer since it is going into the reverse
- * instruction. */
-
- Tree *dval = getPtrValSplit( prg, ptr );
- treeUpref( dval );
- vm_push( dval );
+ Struct *ptr = vm_pop_type( Struct * );
+ vm_push_type( Struct *, ptr );
/* This is an initial global load. Need to reverse execute it. */
rcodeUnitStart( exec );
- rcodeCode( exec, IN_PTR_DEREF_BKT );
+ rcodeCode( exec, IN_PTR_ACCESS_BKT );
rcodeWord( exec, (Word) ptr );
break;
}
- case IN_PTR_DEREF_BKT: {
+ case IN_PTR_ACCESS_BKT: {
Word p;
read_word( p );
- debug( prg, REALM_BYTECODE, "IN_PTR_DEREF_BKT\n" );
+ debug( prg, REALM_BYTECODE, "IN_PTR_ACCESS_BKT\n" );
- Pointer *ptr = (Pointer*)p;
-
- Tree *dval = getPtrValSplit( prg, ptr );
- treeUpref( dval );
- vm_push( dval );
-
- treeDownref( prg, sp, (Tree*)ptr );
+ Struct *ptr = (Struct*)p;
+ vm_push_type( Struct *, ptr );
break;
}
case IN_REF_FROM_LOCAL: {
@@ -4141,13 +4109,11 @@ again:
treeDownref( prg, sp, val );
break;
}
- case IN_PTR_DEREF_BKT: {
+ case IN_PTR_ACCESS_BKT: {
Tree *ptr;
read_tree( ptr );
- debug( prg, REALM_BYTECODE, "IN_PTR_DEREF_BKT\n" );
-
- treeDownref( prg, sp, ptr );
+ debug( prg, REALM_BYTECODE, "IN_PTR_ACCESS_BKT\n" );
break;
}
case IN_SET_TOKEN_DATA_BKT: {
diff --git a/src/bytecode.h b/src/bytecode.h
index ba68dfc2..2359485b 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -134,10 +134,8 @@ typedef unsigned char uchar;
#define IN_LOAD_GLOBAL_WC 0x57
#define IN_LOAD_GLOBAL_BKT 0x58
-#define IN_PTR_DEREF_R 0x59
-#define IN_PTR_DEREF_WV 0x5a
-#define IN_PTR_DEREF_WC 0x60
-#define IN_PTR_DEREF_BKT 0x61
+#define IN_PTR_ACCESS_WV 0x5a
+#define IN_PTR_ACCESS_BKT 0x61
#define IN_REF_FROM_LOCAL 0x62
#define IN_REF_FROM_REF 0x63
diff --git a/src/colm.lm b/src/colm.lm
index c5e6bf35..d1323245 100644
--- a/src/colm.lm
+++ b/src/colm.lm
@@ -49,7 +49,6 @@ lex
token SWITCH / 'switch' /
token CASE / 'case' /
token DEFAULT / 'default' /
- token DEREF / 'deref' /
token MAKE_TOKEN / 'make_token' /
token MAKE_TREE / 'make_tree' /
@@ -558,7 +557,6 @@ def code_factor
| [TYPEID LT type_ref GT] :TypeId
| [NEW type_ref] :New
| [CAST LT type_ref GT code_factor] :Cast
-| [DEREF code_factor] :Deref
def type_ref
[region_qual id opt_repeat] :Id
diff --git a/src/loadcolm.cc b/src/loadcolm.cc
index c831d57b..fbb0947c 100644
--- a/src/loadcolm.cc
+++ b/src/loadcolm.cc
@@ -1855,11 +1855,6 @@ struct LoadColm
expr = LangExpr::cons( LangTerm::cons( codeFactor.loc(),
LangTerm::CastType, typeRef, castExpr ) );
break;
- }
- case code_factor::Deref: {
- LangExpr *cfExpr = walkCodeFactor( codeFactor._code_factor() );
- expr = LangExpr::cons( codeFactor.loc(), OP_Deref, cfExpr );
- break;
}}
return expr;
}
diff --git a/src/lookup.cc b/src/lookup.cc
index 8d08ba2a..5514c00a 100644
--- a/src/lookup.cc
+++ b/src/lookup.cc
@@ -79,13 +79,13 @@ VarRefLookup LangVarRef::lookupQualification( Compiler *pd, NameScope *rootScope
/* Check for references. When loop is done we will have the last one
* present, if any. */
- if ( qualUT->typeId == TYPE_PTR )
+ if ( qualUT->ptr() )
lastPtrInQual = qi.pos();
if ( qi->form == QualItem::Dot ) {
/* Cannot dot a reference. Iterator yes (access of the iterator
* not the current) */
- if ( qualUT->typeId == TYPE_PTR )
+ if ( qualUT->ptr() )
error(loc) << "dot cannot be used to access a pointer" << endp;
}
else if ( qi->form == QualItem::Arrow ) {
diff --git a/src/parsetree.h b/src/parsetree.h
index fc6a7ee4..f63e453a 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -1851,6 +1851,9 @@ struct UniqueType : public AvlTreeEl<UniqueType>
bool parser()
{ return typeId == TYPE_GENERIC && generic->typeId == GEN_PARSER; }
+
+ bool ptr()
+ { return typeId == TYPE_STRUCT || typeId == TYPE_GENERIC; }
};
struct CmpUniqueType
diff --git a/src/synthesis.cc b/src/synthesis.cc
index 907fc9ad..18e7159d 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -465,26 +465,13 @@ void LangVarRef::loadQualification( Compiler *pd, CodeVect &code,
error(loc) << "dot cannot be used to access a pointer" << endp;
}
else if ( qi->form == QualItem::Arrow ) {
- if ( qualUT->typeId == TYPE_PTR ) {
-// /* Always dereference references when used for qualification. If
-// * this is the last one then we must start with the reverse
-// * execution business. */
-// if ( pd->revertOn && qi.pos() == lastPtrInQual && forWriting ) {
-// /* This is like a global load. */
-// code.append( IN_PTR_DEREF_WV );
-// }
-// else {
-// /* If reading or not yet the last in ref then we only need a
-// * reading deref. */
-// code.append( IN_PTR_DEREF_R );
-// }
-
- qualUT = pd->findUniqueType( TYPE_TREE, qualUT->langEl );
- }
- else if ( qualUT->typeId == TYPE_STRUCT ||
- qualUT->typeId == TYPE_GENERIC )
- {
- /* No deref. */
+ if ( qualUT->ptr() ) {
+ /* This deref instruction exists to capture the pointer reverse
+ * execution purposes. */
+ if ( pd->revertOn && qi.pos() == lastPtrInQual && forWriting ) {
+ /* This is like a global load. */
+ code.append( IN_PTR_ACCESS_WV );
+ }
}
else {
error(loc) << "arrow operator cannot be used to "
@@ -670,9 +657,12 @@ bool LangVarRef::canTakeRef( Compiler *pd, VarRefLookup &lookup ) const
* via a local and attributes. */
if ( lookup.inObject->type == ObjectDef::FrameType )
canTake = true;
- else if ( isLocalRef() && lookup.lastPtrInQual < 0 &&
- lookup.uniqueType->typeId != TYPE_PTR )
- canTake = true;
+ else if ( isLocalRef() )
+ {
+ cerr << "lastPtrInQual: " << lookup.lastPtrInQual << endl;
+ if ( lookup.lastPtrInQual < 0 && ! lookup.uniqueType->ptr() )
+ canTake = true;
+ }
return canTake;
}
@@ -1956,15 +1946,6 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const
code.append( IN_TREE_TRIM );
return rt;
}
- case OP_Deref: {
- UniqueType *ut = right->evaluate( pd, code );
- if ( ut->typeId != TYPE_PTR )
- error(loc) << "can only dereference pointers" << endl;
-
- code.append( IN_PTR_DEREF_R );
- ut = pd->findUniqueType( TYPE_TREE, ut->langEl );
- return ut;
- }
default:
assert(false);
}